UNPKG

@cran/gql.koa

Version:

Cran/GraphQL Koa Server

34 lines (33 loc) 1.29 kB
import { BatchSpanProcessor } from "@opentelemetry/sdk-trace-base"; import { GraphQLInstrumentation } from "@opentelemetry/instrumentation-graphql"; import { HttpInstrumentation } from "@opentelemetry/instrumentation-http"; import { KoaInstrumentation } from "@opentelemetry/instrumentation-koa"; import { MetricSpanExporter } from "./MetricSpanExporter"; import { NodeSDK } from "@opentelemetry/sdk-node"; export class MetricTracer { sdk; constructor(config = {}) { const instrumentations = config.instrumentations || MetricTracer.defaultInstrumentations; if (config.instrumentations && !config.overrideInstrumentations) { instrumentations.push(...MetricTracer.defaultInstrumentations); } this.sdk = new NodeSDK({ spanProcessor: new BatchSpanProcessor(new MetricSpanExporter(config)), instrumentations, }); } async start() { process.on("SIGTERM", () => { void this.sdk.shutdown(); }); return this.sdk.start(); } } (function (MetricTracer) { MetricTracer.defaultInstrumentations = [ new HttpInstrumentation(), new KoaInstrumentation(), new GraphQLInstrumentation(), ]; })(MetricTracer || (MetricTracer = {}));