Socket
Book a DemoInstallSign in
Socket

@opentelemetry/instrumentation-express

Package Overview
Dependencies
Maintainers
2
Versions
56
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@opentelemetry/instrumentation-express

OpenTelemetry instrumentation for `express` http web application framework

latest
Source
npmnpm
Version
0.54.0
Version published
Weekly downloads
5.8M
-20.2%
Maintainers
2
Weekly downloads
 
Created

What is @opentelemetry/instrumentation-express?

@opentelemetry/instrumentation-express is a package that provides automatic instrumentation for Express.js applications. It allows developers to collect and export telemetry data such as traces and metrics, which can be used for monitoring and performance analysis.

What are @opentelemetry/instrumentation-express's main functionalities?

Automatic Tracing

This code sets up automatic tracing for an Express.js application. It initializes a tracer provider, adds a span processor to export spans to the console, and registers the Express instrumentation.

const { NodeTracerProvider } = require('@opentelemetry/node');
const { SimpleSpanProcessor } = require('@opentelemetry/tracing');
const { ConsoleSpanExporter } = require('@opentelemetry/tracing');
const { ExpressInstrumentation } = require('@opentelemetry/instrumentation-express');

const provider = new NodeTracerProvider();
provider.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter()));
provider.register();

const expressInstrumentation = new ExpressInstrumentation();
expressInstrumentation.setTracerProvider(provider);

Custom Span Attributes

This code demonstrates how to add custom attributes to spans in an Express.js application. It retrieves the current active span and sets a custom attribute.

const express = require('express');
const { context, trace } = require('@opentelemetry/api');

const app = express();

app.use((req, res, next) => {
  const span = trace.getSpan(context.active());
  if (span) {
    span.setAttribute('custom-attribute', 'custom-value');
  }
  next();
});

Error Handling

This code shows how to record exceptions in spans for error handling in an Express.js application. It captures the current active span and records the exception.

const express = require('express');
const { context, trace } = require('@opentelemetry/api');

const app = express();

app.use((err, req, res, next) => {
  const span = trace.getSpan(context.active());
  if (span) {
    span.recordException(err);
  }
  res.status(500).send('Internal Server Error');
});

Other packages similar to @opentelemetry/instrumentation-express

Keywords

express

FAQs

Package last updated on 10 Sep 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts