diff --git a/.changeset/loud-swans-serve.md b/.changeset/loud-swans-serve.md new file mode 100644 index 000000000..b22bbbb3b --- /dev/null +++ b/.changeset/loud-swans-serve.md @@ -0,0 +1,5 @@ +--- +'@envelop/opentelemetry': minor +--- + +chore: upgrade opentelemetry diff --git a/packages/plugins/opentelemetry/README.md b/packages/plugins/opentelemetry/README.md index d585e80ed..e9045cfcd 100644 --- a/packages/plugins/opentelemetry/README.md +++ b/packages/plugins/opentelemetry/README.md @@ -39,7 +39,7 @@ import { parse, validate, specifiedRules, execute, subscribe } from 'graphql' import { envelop, useEngine } from '@envelop/core' import { useOpenTelemetry } from '@envelop/opentelemetry' import { JaegerExporter } from '@opentelemetry/exporter-jaeger' -import { SimpleSpanProcessor, BasicTracerProvider } from '@opentelemetry/tracing' +import { SimpleSpanProcessor, BasicTracerProvider } from '@opentelemetry/sdk-trace-base' const exporter = new JaegerExporter({ serviceName: 'my-service-name' diff --git a/packages/plugins/opentelemetry/package.json b/packages/plugins/opentelemetry/package.json index 680c6fada..d21792b0f 100644 --- a/packages/plugins/opentelemetry/package.json +++ b/packages/plugins/opentelemetry/package.json @@ -49,7 +49,7 @@ "dependencies": { "@envelop/on-resolve": "^2.0.6", "@opentelemetry/api": "^1.0.0", - "@opentelemetry/tracing": "^0.24.0", + "@opentelemetry/sdk-trace-base": "^1.11.0", "tslib": "^2.5.0" }, "devDependencies": { diff --git a/packages/plugins/opentelemetry/src/index.ts b/packages/plugins/opentelemetry/src/index.ts index 362d34c47..0bc1e12cb 100644 --- a/packages/plugins/opentelemetry/src/index.ts +++ b/packages/plugins/opentelemetry/src/index.ts @@ -1,8 +1,8 @@ import { Plugin, OnExecuteHookResult, isAsyncIterable } from '@envelop/core'; import { useOnResolve } from '@envelop/on-resolve'; -import { SpanAttributes, SpanKind } from '@opentelemetry/api'; +import { SpanAttributes, SpanKind, TracerProvider } from '@opentelemetry/api'; import * as opentelemetry from '@opentelemetry/api'; -import { BasicTracerProvider, ConsoleSpanExporter, SimpleSpanProcessor } from '@opentelemetry/tracing'; +import { BasicTracerProvider, ConsoleSpanExporter, SimpleSpanProcessor } from '@opentelemetry/sdk-trace-base'; import { print } from 'graphql'; export enum AttributeName { @@ -32,15 +32,16 @@ type PluginContext = { export const useOpenTelemetry = ( options: TracingOptions, - tracingProvider?: BasicTracerProvider, + tracingProvider?: TracerProvider, spanKind: SpanKind = SpanKind.SERVER, spanAdditionalAttributes: SpanAttributes = {}, serviceName = 'graphql' ): Plugin => { if (!tracingProvider) { - tracingProvider = new BasicTracerProvider(); - tracingProvider.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter())); - tracingProvider.register(); + const basicTraceProvider = new BasicTracerProvider(); + basicTraceProvider.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter())); + basicTraceProvider.register(); + tracingProvider = basicTraceProvider; } const tracer = tracingProvider.getTracer(serviceName); @@ -51,7 +52,6 @@ export const useOpenTelemetry = ( addPlugin( useOnResolve(({ info, context, args }) => { if (context && typeof context === 'object' && context[tracingSpanSymbol]) { - tracer.getActiveSpanProcessor(); const ctx = opentelemetry.trace.setSpan(opentelemetry.context.active(), context[tracingSpanSymbol]); const { fieldName, returnType, parentType } = info; diff --git a/packages/plugins/opentelemetry/test/use-open-telemetry.spec.ts b/packages/plugins/opentelemetry/test/use-open-telemetry.spec.ts index fecebd3d8..7ec69365c 100644 --- a/packages/plugins/opentelemetry/test/use-open-telemetry.spec.ts +++ b/packages/plugins/opentelemetry/test/use-open-telemetry.spec.ts @@ -1,5 +1,5 @@ import { assertSingleExecutionValue, createTestkit } from '@envelop/testing'; -import { BasicTracerProvider, SimpleSpanProcessor, InMemorySpanExporter } from '@opentelemetry/tracing'; +import { BasicTracerProvider, SimpleSpanProcessor, InMemorySpanExporter } from '@opentelemetry/sdk-trace-base'; import { buildSchema } from 'graphql'; import { useOpenTelemetry } from '../src/index.js';