@envelop/opentelemetry
TypeScript icon, indicating that this package has built-in type declarations

5.0.0 • Public • Published

@envelop/opentelemetry

This plugins integrates Open Telemetry 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, 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:

import { execute, parse, specifiedRules, subscribe, validate } from 'graphql'
import { envelop, useEngine } from '@envelop/core'
import { useOpenTelemetry } from '@envelop/opentelemetry'

const getEnveloped = envelop({
  plugins: [
    useEngine({ parse, validate, specifiedRules, execute, subscribe }),
    // ... 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:

import { execute, parse, specifiedRules, subscribe, validate } from 'graphql'
import { envelop, useEngine } from '@envelop/core'
import { useOpenTelemetry } from '@envelop/opentelemetry'
import { JaegerExporter } from '@opentelemetry/exporter-jaeger'
import { BasicTracerProvider, SimpleSpanProcessor } from '@opentelemetry/sdk-trace-base'

const exporter = new JaegerExporter({
  serviceName: 'my-service-name'
})

const provider = new BasicTracerProvider()
provider.addSpanProcessor(new SimpleSpanProcessor(exporter))
provider.register()

const getEnveloped = envelop({
  plugins: [
    useEngine({ parse, validate, specifiedRules, execute, subscribe }),
    // ... 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
    )
  ]
})

Keywords

none

Install

npm i @envelop/opentelemetry

DownloadsWeekly Downloads

9,506

Version

5.0.0

License

MIT

Unpacked Size

18.3 kB

Total Files

8

Last publish

Collaborators

  • dotansimha