Skip to content

Commit

Permalink
Update OpenTelemetry plugin to use latest packages (#1754)
Browse files Browse the repository at this point in the history
  • Loading branch information
darren-west authored Apr 19, 2023
1 parent bb23f34 commit 8ddd919
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 10 deletions.
5 changes: 5 additions & 0 deletions .changeset/loud-swans-serve.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@envelop/opentelemetry': minor
---

chore: upgrade opentelemetry
2 changes: 1 addition & 1 deletion packages/plugins/opentelemetry/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion packages/plugins/opentelemetry/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
14 changes: 7 additions & 7 deletions packages/plugins/opentelemetry/src/index.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -32,15 +32,16 @@ type PluginContext = {

export const useOpenTelemetry = (
options: TracingOptions,
tracingProvider?: BasicTracerProvider,
tracingProvider?: TracerProvider,
spanKind: SpanKind = SpanKind.SERVER,
spanAdditionalAttributes: SpanAttributes = {},
serviceName = 'graphql'
): Plugin<PluginContext> => {
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);
Expand All @@ -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;

Expand Down
Original file line number Diff line number Diff line change
@@ -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';

Expand Down

0 comments on commit 8ddd919

Please sign in to comment.