OpenTelemetry Instrumentation GraphQL
This module provides automated instrumentation and tracing for GraphQL in Node.js applications.
Installation
npm install @opentelemetry/instrumentation-graphql
Usage
'use strict';
const { GraphQLInstrumentation } = require('@opentelemetry/instrumentation-graphql');
const { ConsoleSpanExporter, SimpleSpanProcessor } = require('@opentelemetry/tracing');
const { NodeTracerProvider } = require('@opentelemetry/node');
const { CollectorTraceExporter } = require('@opentelemetry/exporter-collector');
const exporter = new CollectorTraceExporter({
serviceName: 'basic-service',
});
const provider = new NodeTracerProvider({
plugins: {
http: { enabled: false, path: '@opentelemetry/plugin-http' },
https: { enabled: false, path: '@opentelemetry/plugin-https' },
express: { enabled: false, path: '@opentelemetry/plugin-express' },
},
});
const graphQLInstrumentation = new GraphQLInstrumentation({
// optional params
// allowAttributes: true,
// depth: 2,
// mergeItems: true,
});
graphQLInstrumentation.setTracerProvider(provider);
graphQLInstrumentation.enable();
provider.addSpanProcessor(new SimpleSpanProcessor(exporter));
provider.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter()));
provider.register();
Useful links
- For more information on OpenTelemetry, visit: https://opentelemetry.io/
- For more about OpenTelemetry JavaScript: https://github.com/open-telemetry/opentelemetry-js
- For help or feedback on this project, join us on gitter
License
Apache 2.0 - See LICENSE for more information.