{"library":"opentelemetry-instrumentation-express","title":"OpenTelemetry Express Instrumentation (Enhanced)","description":"opentelemetry-instrumentation-express is an enhanced instrumentation library for the `express` web framework, designed to integrate seamlessly with OpenTelemetry for Node.js applications. Currently at version 0.41.0, it is actively maintained and part of the `aspecto-io/opentelemetry-ext-js` project, which sees frequent updates. This package differentiates itself from the standard `@opentelemetry/instrumentation-express` by providing more granular and accurate route information through custom span attributes like `express.route.full`, `express.route.configured`, and `express.route.params`, which capture the full path and parsed parameters. It also tracks `express.unhandled` requests, offering better insights into unhandled routes and 404s. The instrumentation supports Express versions `^4.9.0` and is suitable for detailed tracing of Express applications where precise route context is crucial for observability.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install opentelemetry-instrumentation-express"],"cli":null},"imports":["import { ExpressInstrumentation } from 'opentelemetry-instrumentation-express';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"const express = require('express');\nconst { NodeTracerProvider } = require('@opentelemetry/sdk-trace-node');\nconst { registerInstrumentations } = require('@opentelemetry/instrumentation');\nconst { ExpressInstrumentation } = require('opentelemetry-instrumentation-express');\n\nconst tracerProvider = new NodeTracerProvider();\ntracerProvider.register();\n\nregisterInstrumentations({\n  tracerProvider,\n  instrumentations: [\n    new ExpressInstrumentation({ \n      // Optional: include HTTP attributes on spans\n      includeHttpAttributes: true,\n      // Optional: custom hook for adding attributes before request handling\n      requestHook: (span, { moduleVersion, req, res }) => {\n        span.setAttribute('my.custom.attribute', 'value');\n      }\n    })\n  ]\n});\n\nconst app = express();\n\napp.get('/', (req, res) => {\n  res.send('Hello OpenTelemetry Express!');\n});\n\napp.get('/users/:id', (req, res) => {\n  res.send(`User ID: ${req.params.id}`);\n});\n\napp.listen(3000, () => {\n  console.log('Server running on port 3000');\n});","lang":"javascript","description":"Demonstrates how to set up and register the ExpressInstrumentation with a NodeTracerProvider to automatically trace Express routes, including custom options.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}