{"id":17629,"library":"express-opentracing","title":"OpenTracing Middleware for Express.js","description":"express-opentracing provides middleware for Express.js applications to instrument incoming HTTP requests using the OpenTracing API. This allows developers to integrate distributed tracing into their Express routes, creating spans for requests and associating them with a configured OpenTracing-compatible tracer. The package is currently at version 0.1.1 and appears to be unmaintained, with its last commit occurring several years ago. Crucially, the underlying OpenTracing project itself has been officially deprecated and archived since 2019, having merged with OpenCensus to form OpenTelemetry. OpenTelemetry is now the recommended, actively developed standard for comprehensive observability, encompassing traces, metrics, and logs. Users are strongly advised to migrate from OpenTracing-based solutions to OpenTelemetry for ongoing support, features, and security.","status":"abandoned","version":"0.1.1","language":"javascript","source_language":"en","source_url":"https://github.com/opentracing-contrib/javascript-express","tags":["javascript","tracing","opentracing","middleware"],"install":[{"cmd":"npm install express-opentracing","lang":"bash","label":"npm"},{"cmd":"yarn add express-opentracing","lang":"bash","label":"yarn"},{"cmd":"pnpm add express-opentracing","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Core API for distributed tracing, required for any OpenTracing implementation.","package":"opentracing","optional":false}],"imports":[{"note":"The package likely pre-dates widespread ESM in Node.js, but modern usage would prefer ESM. The library internally uses `module.exports`, making `require` technically correct for Node.js CJS, but `import` is shown in the README.","wrong":"const middleware = require('express-opentracing');","symbol":"middleware","correct":"import middleware from 'express-opentracing';"},{"note":"The `opentracing` peer dependency provides the core API classes like `Tracer` for interacting with the tracing system. Named import is standard for ESM.","wrong":"const Tracer = require('opentracing').Tracer;","symbol":"Tracer","correct":"import { Tracer } from 'opentracing';"},{"note":"OpenTracing `Tags` are used to add standardized attributes to spans, such as `http.status_code` or `span.kind`.","wrong":"const Tags = require('opentracing').Tags;","symbol":"Tags","correct":"import { Tags } from 'opentracing';"}],"quickstart":{"code":"import * as express from \"express\";\nimport middleware from \"express-opentracing\";\nimport * as opentracing from 'opentracing';\n\n// NOTE: In a real application, you'd replace the NoopTracer\n// with a vendor-specific implementation like Jaeger, LightStep, or Zipkin.\n// For demonstration, we use a basic console logger (MockTracer).\nclass MockTracer extends opentracing.Tracer {\n  _startSpan(name, options) {\n    console.log(`[MockTracer] Starting span: ${name}`);\n    return new MockSpan(this, name, options.references);\n  }\n}\n\nclass MockSpan extends opentracing.Span {\n  _finish() {\n    console.log(`[MockTracer] Finishing span: ${this.operationName()}`);\n  }\n  _context() { return { traceId: 'mock-trace', spanId: 'mock-span' }; }\n  _setOperationName(name) { return this; }\n  _log(fields, timestamp) { console.log(`[MockTracer] Log for ${this.operationName()}:`, fields); return this; }\n  _setTag(key, value) { console.log(`[MockTracer] Tag for ${this.operationName()}: ${key}=${value}`); return this; }\n}\n\nconst myTracer = new MockTracer();\nopentracing.initGlobalTracer(myTracer);\n\nconst app = express();\n\n// Apply the express-opentracing middleware\napp.use(middleware({ tracer: myTracer }));\n\napp.get('/', (req, res) => {\n  // The span is available on req.span if the middleware created one\n  if (req.span) {\n    req.span.log({ event: 'homepage_access', userId: 'test-user-123' });\n    // Simulate some async work\n    setTimeout(() => {\n      res.send('Hello from Express with OpenTracing!');\n      req.span.setTag(opentracing.Tags.HTTP_STATUS_CODE, 200);\n    }, 100);\n  } else {\n    res.send('Hello from Express (no tracing)');\n  }\n});\n\napp.get('/error', (req, res) => {\n  if (req.span) {\n    req.span.setTag(opentracing.Tags.ERROR, true);\n    req.span.setTag(opentracing.Tags.HTTP_STATUS_CODE, 500);\n    req.span.log({ event: 'error_occurred', message: 'Something went wrong' });\n  }\n  res.status(500).send('An error occurred!');\n});\n\nconst PORT = process.env.PORT || 3000;\napp.listen(PORT, () => {\n  console.log(`Server running on http://localhost:${PORT}`);\n  console.log('Try visiting / and /error');\n});","lang":"typescript","description":"This quickstart demonstrates how to integrate `express-opentracing` into an Express.js application using a basic `MockTracer` for logging. It shows how to initialize the middleware and access the request span within a route handler."},"warnings":[{"fix":"Migrate your observability instrumentation to OpenTelemetry. This will require replacing `express-opentracing` with an OpenTelemetry Express instrumentation package (e.g., `@opentelemetry/instrumentation-express`) and adopting the OpenTelemetry SDK.","message":"The OpenTracing project, which this library depends on, has been officially deprecated and archived. It was superseded by OpenTelemetry, a unified and actively developed standard for distributed tracing, metrics, and logs. Continuing to use OpenTracing-based libraries is strongly discouraged.","severity":"breaking","affected_versions":">=0.1.1"},{"fix":"As with the OpenTracing deprecation, the primary fix is to migrate to OpenTelemetry-based solutions that are actively maintained and compatible with modern JavaScript ecosystems.","message":"This package is unmaintained. The last release was in 2017 (version 0.1.1), and there has been no active development since. This means it will not receive bug fixes, new features, or security updates. Its compatibility with newer Node.js, Express.js, or `opentracing` versions is not guaranteed.","severity":"gotcha","affected_versions":">=0.1.1"},{"fix":"Ensure `opentracing` is installed at a compatible version. However, given the project's status, the recommended long-term solution is migration to OpenTelemetry.","message":"The peer dependency `opentracing` has a version requirement of `^0.14.0`. While this aligns with the last known stable version of `opentracing` before its deprecation, installing newer or incompatible versions of `opentracing` (or other tracing libraries) could lead to runtime errors or unexpected behavior if strict peer dependency checks are not in place.","severity":"gotcha","affected_versions":">=0.1.1"},{"fix":"Always explicitly pass an initialized tracer instance (e.g., from Jaeger, LightStep, or a MockTracer for testing) to the middleware options: `app.use(middleware({ tracer: myTracer }));`.","message":"This middleware implicitly expects a global tracer to be initialized via `opentracing.initGlobalTracer()`, or it defaults to the OpenTracing NoopTracer if no tracer is explicitly passed in the options object. Failing to initialize a real tracer will result in no actual tracing data being collected without any explicit errors from the middleware itself.","severity":"gotcha","affected_versions":">=0.1.1"}],"env_vars":null,"last_verified":"2026-04-23T00:00:00.000Z","next_check":"2026-07-22T00:00:00.000Z","problems":[{"fix":"Install the `opentracing` package: `npm install opentracing` or `yarn add opentracing`.","cause":"The `opentracing` peer dependency is required by `express-opentracing` but was not installed in the project.","error":"Error: Cannot find module 'opentracing'"},{"fix":"Ensure a valid `Tracer` instance is passed in the middleware options: `app.use(middleware({ tracer: myTracer }));`. If using `opentracing.initGlobalTracer()`, ensure it's called before `express-opentracing` is initialized.","cause":"This error often occurs when the `tracer` option passed to the middleware is `undefined` or not a valid OpenTracing `Tracer` instance, leading to calls on an uninitialized object.","error":"TypeError: Cannot read properties of undefined (reading 'startSpan')"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}