apollo-opentracing is a plugin designed to integrate OpenTracing-compatible distributed tracing with Apollo Server. It enables automatic tracing of GraphQL requests and individual field resolvers, providing insights into query performance, and allows for selective tracing of requests and fields. The library helps in debugging by logging queries and results and supports span context propagation via HTTP headers, crucial for connecting traces across services. As of version 3.0.45, released in March 2023, the project primarily receives maintenance updates, focusing on dependency compatibility. A key differentiator is its adherence to the OpenTracing standard, allowing integration with various tracing backends like Jaeger and Zipkin. However, it's important to note that OpenTracing itself has been superseded by OpenTelemetry, making this library focused on a legacy tracing standard.
npm install apollo-opentracingVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates setting up Apollo Server v3+ with `apollo-opentracing` using mock tracers. It initializes the Apollo Server with a basic schema and resolvers, then integrates the `OpentracingPlugin` to automatically trace requests and field resolutions. It also shows how to optionally control tracing and access the span within a resolver.
Migrate your Apollo Server setup to use the `ApolloServer` class and pass `OpentracingPlugin` within the `plugins` array in the constructor. Refer to Apollo Server v3+ documentation for correct initialization.
For new projects, consider using OpenTelemetry directly with an instrumentation library like `@opentelemetry/instrumentation-graphql` instead of `apollo-opentracing`. For existing projects, evaluate migration paths from OpenTracing to OpenTelemetry.
Ensure you provide properly initialized instances of an `opentracing.Tracer` implementation (e.g., Jaeger, Zipkin, or a `MockTracer` for testing) for both the `server` and `local` options in the `OpentracingPlugin` constructor.
Ensure `OpentracingPlugin` is called with a configuration object containing `server` and `local` properties, each assigned a valid `opentracing.Tracer` instance: `plugins: [OpentracingPlugin({ server: myServerTracer, local: myLocalTracer })]`.Ensure you are using `import OpentracingPlugin from 'apollo-opentracing';` (ESM) or `const OpentracingPlugin = require('apollo-opentracing').default;` (CJS) and then correctly invoking it as a function within the `plugins` array: `plugins: [OpentracingPlugin({ server: ..., local: ... })]`.