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

@ministryofjustice/hmpps-azure-telemetry

v1.0.2

Published

Azure Application Insights telemetry using OpenTelemetry

Readme

@ministryofjustice/hmpps-azure-telemetry

A shared telemetry package that wraps OpenTelemetry and Azure Application Insights. Offers a few useful processors and helpers by default.

Status

This library is currently: ready to adopt.

Teams are encouraged to use this library. Please provide feedback via slack to the #typescript channel.

Setup

Important: This must be imported at the very top of your entry point, before any other imports. OpenTelemetry needs to instrument modules (express, http, etc.) before they're loaded.

// server/utils/azureAppInsights.ts
import { initialiseTelemetry, flushTelemetry, telemetry } from '@ministryofjustice/hmpps-azure-telemetry'

initialiseTelemetry({
  serviceName: 'my-service',
  serviceVersion: process.env.BUILD_NUMBER,
  connectionString: process.env.APPLICATIONINSIGHTS_CONNECTION_STRING,
  debug: process.env.DEBUG_TELEMETRY // Log telemetry to the console for debugging/developing
})
  .addFilter(telemetry.processors.filterSpanWherePath(['/health', '/ping', '/assets/*']))
  .addModifier(telemetry.processors.modifySpanNameWithHttpRoute())
  .startRecording()

// Then other imports...
import express from 'express'

// Graceful shutdown
process.on('SIGTERM', async () => {
  await flushTelemetry()
  process.exit(0)
})
// server.ts
// Import before any of the other modules are loaded.
import './server/utils/azureAppInsights'
import app from './server/index'
import logger from './logger'

Usage

Custom events and spans

import { telemetry } from '@ministryofjustice/hmpps-azure-telemetry'

// Set attributes on the current span
telemetry.setSpanAttributes({ 'custom.key': 'value' })

// Add events
telemetry.trackEvent('UserLoggedIn', { userId: '123' })

// Wrap operations in spans
await telemetry.withSpan('processPayment', async (span) => {
  span.setAttribute('orderId', '123')
  return await processPayment()
})

Custom processors

You can write your own filters and modifiers:

import type { SpanFilterFn, SpanModifierFn } from '@ministryofjustice/hmpps-azure-telemetry'

// Filters decide keep (true) or drop (false)
function filterSlowSpans(minMs: number): SpanFilterFn {
  return span => span.durationMs >= minMs
}

// Modifiers read and write span data directly
function addEnvironmentTag(): SpanModifierFn {
  return span => {
    span.setAttribute('deployment.environment', process.env.ENVIRONMENT)
  }
}

Custom instrumentations

Using the defaultInstrumentations export and setInstrumentations, you can set custom instrumentations, expand on the defaults, or outright replace them with your instrumentation config.

// Use defaults (no change needed)
initialiseTelemetry({ ... }).startRecording()

// Replace all instrumentations
initialiseTelemetry({ ... })
  .setInstrumentations([new HttpInstrumentation()])
  .startRecording()

// Extend defaults
initialiseTelemetry({ ... })
  .setInstrumentations([...defaultInstrumentations, new RedisInstrumentation()])
  .startRecording()

// Remove specific defaults
initialiseTelemetry({ ... })
  .setInstrumentations(defaultInstrumentations.filter(i => i.instrumentationName !== 'bunyan'))
  .startRecording()

Built-in processors

| Processor | Type | Description | |-------------------------------------|----------|---------------------------------------------------------------------------------------------------------------------------| | filterSpanWhereClient() | Filter | Drops outgoing HTTP calls (CLIENT spans / AppDependencies). Trace context is still propagated. | | filterSpanWherePath(paths) | Filter | Drops requests to specified paths. Supports exact matches and prefix matches ending with *. | | modifySpanNameWithHttpRoute() | Modifier | Renames HTTP spans to use the route pattern, e.g. GET becomes GET /users/:id. | | modifySpanWithObfuscation(config) | Modifier | Obfuscates sensitive data in span attributes using HMAC-SHA256. Same input always produces the same hash for correlation. |

Developing this package

This module uses rollup, to build:

npm run lint-fix && npm run build && npm run test

Testing changes to this library

  • cd to this directory and then link this library: npm link
  • Utilise the in-development library within a project by using: npm link @ministryofjustice/hmpps-azure-telemetry