npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@map-colonies/tracing-utils

v1.0.0

Published

Utilities for tracing integration in MapColonies services

Readme

Tracing Utils

Utilities for OpenTelemetry tracing integration in MapColonies services.

Installation

npm install @map-colonies/tracing-utils

Features

  • Utility functions for span creation and management
  • TypeScript decorators for automatic span instrumentation (v4 and v5)
  • Express middleware for trace context headers
  • Pino logger mixin for trace context injection

API Documentation

Full API documentation is available here.

Usage

Utility Functions

Creating spans for async operations

import { asyncCallWithSpan } from '@map-colonies/tracing-utils';
import { trace } from '@opentelemetry/api';

const tracer = trace.getTracer('my-service');

const result = await asyncCallWithSpan(
  async (span) => {
    span?.setAttribute('custom.attribute', 'value');
    return await someAsyncOperation();
  },
  tracer,
  'operation-name'
);

Creating spans for synchronous operations

import { callWithSpan } from '@map-colonies/tracing-utils';
import { trace } from '@opentelemetry/api';

const tracer = trace.getTracer('my-service');

const result = callWithSpan(
  (span) => {
    span?.setAttribute('custom.attribute', 'value');
    return someSyncOperation();
  },
  tracer,
  'operation-name'
);

Manually handling spans

import { handleSpanOnSuccess, handleSpanOnError } from '@map-colonies/tracing-utils';
import { trace } from '@opentelemetry/api';

const tracer = trace.getTracer('my-service');
const span = tracer.startSpan('my-operation');

try {
  // Do work
  handleSpanOnSuccess(span);
} catch (error) {
  handleSpanOnError(span, error);
  throw error;
}

Decorators

TypeScript 5+ Decorators (Stage 3)

import { withSpan, withSpanAsync } from '@map-colonies/tracing-utils';
import { Tracer, trace } from '@opentelemetry/api';

class MyService {
  tracer: Tracer = trace.getTracer('my-service');

  @withSpan
  syncMethod(value: string): string {
    return value.toUpperCase();
  }

  @withSpanAsync
  async asyncMethod(id: number): Promise<Data> {
    return await fetchData(id);
  }
}

Legacy Decorators (TypeScript experimentalDecorators)

For projects using experimentalDecorators: true in tsconfig:

import 'reflect-metadata';
import { withSpanV4, withSpanAsyncV4 } from '@map-colonies/tracing-utils';
import { Tracer, trace } from '@opentelemetry/api';

class MyService {
  tracer: Tracer = trace.getTracer('my-service');

  @withSpanV4
  syncMethod(value: string): string {
    return value.toUpperCase();
  }

  @withSpanAsyncV4
  async asyncMethod(id: number): Promise<Data> {
    return await fetchData(id);
  }
}

[!NOTE] V4 decorators require reflect-metadata to be installed and imported.

Express Middleware

Add trace context headers to HTTP responses:

import express from 'express';
import { getTraceContextHeaderMiddleware } from '@map-colonies/tracing-utils';

const app = express();

app.use(getTraceContextHeaderMiddleware());

app.get('/', (req, res) => {
  res.json({ message: 'Hello World' });
});

The middleware adds a traceparent header to responses in W3C Trace Context format.

Pino Logger Mixin

Inject trace context into Pino logs:

import pino from 'pino';
import { getOtelMixin } from '@map-colonies/tracing-utils';

const logger = pino({
  mixin: getOtelMixin(),
});

logger.info('This log will include trace_id, span_id, and trace_flags');

HTTP Instrumentation Helpers

Filter requests from instrumentation:

import { HttpInstrumentation } from '@opentelemetry/instrumentation-http';
import { ignoreIncomingRequestUrl, ignoreOutgoingRequestPath } from '@map-colonies/tracing-utils';

const httpInstrumentation = new HttpInstrumentation({
  ignoreIncomingRequestHook: ignoreIncomingRequestUrl([
    /\/health/,
    /\/metrics/,
  ]),
  ignoreOutgoingRequestHook: ignoreOutgoingRequestPath([
    /\/internal/,
  ]),
});

Context Binding

Bind functions to span context:

import { contextBindingHelper } from '@map-colonies/tracing-utils';
import { trace } from '@opentelemetry/api';

const tracer = trace.getTracer('my-service');
const span = tracer.startSpan('parent-span');

const boundCallback = contextBindingHelper(span, (data) => {
  // This callback will execute within the span's context
  console.log(data);
});

setTimeout(boundCallback, 1000);
span.end();

Requirements

  • Node.js >= 22
  • @opentelemetry/api ^1.9.0 (peer dependency)
  • reflect-metadata (only for v4 decorators)