Skip to content

Commit

Permalink
chore: fixing the graphql example and allowing support version of gra…
Browse files Browse the repository at this point in the history
…ph from ver 14 (#381)

* chore: fixing the graphql example and allowing support version of graphql from ver 14

* chore: fixing types mismatch between ver. 14 and 15 of graphql
  • Loading branch information
obecny authored Mar 5, 2021
1 parent 3116928 commit 19c5496
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 23 deletions.
37 changes: 19 additions & 18 deletions examples/graphql/tracer.js
Original file line number Diff line number Diff line change
@@ -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');
Expand All @@ -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' },
},
},
],
});
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -40,6 +39,7 @@ import {
OtelExecutionArgs,
ObjectWithGraphQLData,
OPERATION_NOT_SUPPORTED,
Maybe,
} from './types';
import {
addSpanSource,
Expand All @@ -59,7 +59,7 @@ const DEFAULT_CONFIG: GraphQLInstrumentationConfig = {
allowValues: false,
};

const supportedVersions = ['15.*'];
const supportedVersions = ['>=14'];

export class GraphQLInstrumentation extends InstrumentationBase {
constructor(
Expand Down
12 changes: 10 additions & 2 deletions plugins/node/opentelemetry-instrumentation-graphql/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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<T> = null | undefined | T;
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -32,6 +31,7 @@ import {
GraphQLInstrumentationParsedConfig,
ObjectWithGraphQLData,
OtelPatched,
Maybe,
} from './types';

const OPERATION_VALUES = Object.values(AllowedOperationTypes);
Expand Down

0 comments on commit 19c5496

Please sign in to comment.