UNPKG

@envelop/opentelemetry

Version:

This plugins integrates [Open Telemetry](https://opentelemetry.io/) tracing with your GraphQL execution. It also collects GraphQL execution errors and reports it as Exceptions.

73 lines (59 loc) 2.3 kB
## `@envelop/opentelemetry` This plugins integrates [Open Telemetry](https://opentelemetry.io/) tracing with your GraphQL execution. It also collects GraphQL execution errors and reports it as Exceptions. You can use this plugin with any kind of Open Telemetry [tracer](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/api.md#tracer), and integrate it to any tracing/metric platform that supports this standard. ## Getting Started ``` yarn add @envelop/opentelemetry ``` ## Usage Example By default, this plugin prints the collected telemetry to the console: ```ts import { parse, validate, execute, subscribe } from 'graphql' import { envelop } from '@envelop/core' import { useOpenTelemetry } from '@envelop/opentelemetry' const getEnveloped = envelop({ parse, validate, execute, subscribe, plugins: [ // ... other plugins ... useOpenTelemetry({ resolvers: true, // Tracks resolvers calls, and tracks resolvers thrown errors variables: true, // Includes the operation variables values as part of the metadata collected result: true // Includes execution result object as part of the metadata collected }) ] }) ``` If you wish to use custom tracer/exporter, create it and pass it. This example integrates Jaeger tracer: ```ts import { parse, validate, execute, subscribe } from 'graphql' import { envelop } from '@envelop/core' import { useOpenTelemetry } from '@envelop/opentelemetry' import { JaegerExporter } from '@opentelemetry/exporter-jaeger' import { SimpleSpanProcessor, BasicTracerProvider } from '@opentelemetry/tracing' const exporter = new JaegerExporter({ serviceName: 'my-service-name' }) const provider = new BasicTracerProvider() provider.addSpanProcessor(new SimpleSpanProcessor(exporter)) provider.register() const getEnveloped = envelop({ parse, validate, execute, subscribe, plugins: [ // ... other plugins ... useOpenTelemetry( { resolvers: true, // Tracks resolvers calls, and tracks resolvers thrown errors variables: true, // Includes the operation variables values as part of the metadata collected result: true // Includes execution result object as part of the metadata collected }, provider ) ] }) ```