diff --git a/examples/graphql/tracer.js b/examples/graphql/tracer.js index 4be5684dfd..6e3a782f25 100644 --- a/examples/graphql/tracer.js +++ b/examples/graphql/tracer.js @@ -1,7 +1,7 @@ 'use strict'; +const { registerInstrumentations } = require('@opentelemetry/instrumentation'); const { GraphQLInstrumentation } = require('@opentelemetry/instrumentation-graphql'); - const { ConsoleSpanExporter, SimpleSpanProcessor } = require('@opentelemetry/tracing'); const { NodeTracerProvider } = require('@opentelemetry/node'); const { CollectorTraceExporter } = require('@opentelemetry/exporter-collector'); @@ -10,24 +10,25 @@ 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({ - // allowAttributes: true, - // depth: 2, - // mergeItems: true, -}); - -graphQLInstrumentation.setTracerProvider(provider); - -graphQLInstrumentation.enable(); +const provider = new NodeTracerProvider(); provider.addSpanProcessor(new SimpleSpanProcessor(exporter)); provider.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter())); provider.register(); + +registerInstrumentations({ + instrumentations: [ + new GraphQLInstrumentation({ + // allowAttributes: true, + // depth: 2, + // mergeItems: true, + }), + { + plugins: { + http: { enabled: false, path: '@opentelemetry/plugin-http' }, + https: { enabled: false, path: '@opentelemetry/plugin-https' }, + express: { enabled: false, path: '@opentelemetry/plugin-express' }, + }, + }, + ], +}); diff --git a/plugins/node/opentelemetry-instrumentation-graphql/src/graphql.ts b/plugins/node/opentelemetry-instrumentation-graphql/src/graphql.ts index 4c90795f4b..c0b9a80e97 100644 --- a/plugins/node/opentelemetry-instrumentation-graphql/src/graphql.ts +++ b/plugins/node/opentelemetry-instrumentation-graphql/src/graphql.ts @@ -23,7 +23,6 @@ import { InstrumentationNodeModuleFile, safeExecuteInTheMiddle, } from '@opentelemetry/instrumentation'; -import { Maybe } from 'graphql/jsutils/Maybe'; import type * as graphqlTypes from 'graphql'; import { GraphQLFieldResolver } from 'graphql/type/definition'; import { SpanAttributes, SpanNames } from './enum'; @@ -40,6 +39,7 @@ import { OtelExecutionArgs, ObjectWithGraphQLData, OPERATION_NOT_SUPPORTED, + Maybe, } from './types'; import { addSpanSource, @@ -59,7 +59,7 @@ const DEFAULT_CONFIG: GraphQLInstrumentationConfig = { allowValues: false, }; -const supportedVersions = ['15.*']; +const supportedVersions = ['>=14']; export class GraphQLInstrumentation extends InstrumentationBase { constructor( diff --git a/plugins/node/opentelemetry-instrumentation-graphql/src/types.ts b/plugins/node/opentelemetry-instrumentation-graphql/src/types.ts index 5390c37887..b3b232ef94 100644 --- a/plugins/node/opentelemetry-instrumentation-graphql/src/types.ts +++ b/plugins/node/opentelemetry-instrumentation-graphql/src/types.ts @@ -17,7 +17,6 @@ import { InstrumentationConfig } from '@opentelemetry/instrumentation'; import type * as graphqlTypes from 'graphql'; import type * as api from '@opentelemetry/api'; -import type { Maybe } from 'graphql/jsutils/Maybe'; import type { PromiseOrValue } from 'graphql/jsutils/PromiseOrValue'; import { DocumentNode } from 'graphql/language/ast'; import { @@ -137,5 +136,14 @@ export interface OtelPatched { export interface GraphQLPath { prev: GraphQLPath | undefined; key: string | number; - typename: string | undefined; + /** + * optional as it didn't exist yet in ver 14 + */ + typename?: string | undefined; } + +/** + * Moving this type from ver 15 of graphql as it is nto available in ver. 14s + * this way it can compile against ver 14. + */ +export type Maybe = null | undefined | T; diff --git a/plugins/node/opentelemetry-instrumentation-graphql/src/utils.ts b/plugins/node/opentelemetry-instrumentation-graphql/src/utils.ts index 59dd669bed..9b5d4e047a 100644 --- a/plugins/node/opentelemetry-instrumentation-graphql/src/utils.ts +++ b/plugins/node/opentelemetry-instrumentation-graphql/src/utils.ts @@ -16,7 +16,6 @@ import type * as graphqlTypes from 'graphql'; import * as api from '@opentelemetry/api'; -import type { Maybe } from 'graphql/jsutils/Maybe'; import { GraphQLObjectType } from 'graphql/type/definition'; import { AllowedOperationTypes, @@ -32,6 +31,7 @@ import { GraphQLInstrumentationParsedConfig, ObjectWithGraphQLData, OtelPatched, + Maybe, } from './types'; const OPERATION_VALUES = Object.values(AllowedOperationTypes);