Skip to content

Commit f8cabf3

Browse files
authored
fix(instrumentation-graphql): stop using types from graphql library in public api (open-telemetry#1268)
* fix(instrumentation-graphql): stop using types from graphql lib in instrumentation This ensures that whenever someone imports the graphql instrumentation lib while not having the `graphql` package installed, their typescript build still passes. The scenario can happen when using the auto instrumentation packages which import a ton of intrumentation libs but only load them if the instrumented package is present. Signed-off-by: Boris Bera <[email protected]> * fix(instrumentation-graphql): replace ExecutionResult with any in GraphQLInstrumentationExecutionResponseHook This ensures that we don't import types from the `graphql` library in our type declarations. Since the type annotation is now gone, I have added documentation linking to all the implementations of the `ExecutionResult` in the supported `graphql` versions. * fix(instrumentation-graphql): remove graphql as a peerDependency Now that the types are no longer re-exported the dependency on `graphql` doesn't make much sense. This change also has the benefit of letting users who use auto intrumentation and that have strict peerDependency requirements (if they're using pnpm for example) to use this intrumentation without needing to install `graphql`. Signed-off-by: Boris Bera <[email protected]>
1 parent aff84bb commit f8cabf3

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

plugins/node/opentelemetry-instrumentation-graphql/package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@
4444
"access": "public"
4545
},
4646
"peerDependencies": {
47-
"@opentelemetry/api": "^1.0.0",
48-
"graphql": "^14.0.0 || ^15.0.0 || ^16.0.0"
47+
"@opentelemetry/api": "^1.0.0"
4948
},
5049
"devDependencies": {
5150
"@opentelemetry/api": "^1.0.0",

plugins/node/opentelemetry-instrumentation-graphql/src/instrumentation.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export class GraphQLInstrumentation extends InstrumentationBase {
8383
}
8484

8585
protected init() {
86-
const module = new InstrumentationNodeModuleDefinition<typeof graphqlTypes>(
86+
const module = new InstrumentationNodeModuleDefinition<any>(
8787
'graphql',
8888
supportedVersions
8989
);

plugins/node/opentelemetry-instrumentation-graphql/src/types.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,10 @@
1515
*/
1616

1717
import { InstrumentationConfig } from '@opentelemetry/instrumentation';
18-
import type * as graphqlTypes from 'graphql';
1918
import type * as api from '@opentelemetry/api';
2019

2120
export interface GraphQLInstrumentationExecutionResponseHook {
22-
(span: api.Span, data: graphqlTypes.ExecutionResult): void;
21+
(span: api.Span, data: any): void;
2322
}
2423

2524
export interface GraphQLInstrumentationConfig extends InstrumentationConfig {
@@ -65,6 +64,11 @@ export interface GraphQLInstrumentationConfig extends InstrumentationConfig {
6564
* Hook that allows adding custom span attributes based on the data
6665
* returned from "execute" GraphQL action.
6766
*
67+
* @param data - A GraphQL `ExecutionResult` object. For the exact type definitions, see the following:
68+
* - {@linkcode https://github.com/graphql/graphql-js/blob/v14.7.0/src/execution/execute.js#L115 graphql@14}
69+
* - {@linkcode https://github.com/graphql/graphql-js/blob/15.x.x/src/execution/execute.d.ts#L31 graphql@15}
70+
* - {@linkcode https://github.com/graphql/graphql-js/blob/16.x.x/src/execution/execute.ts#L127 graphql@16}
71+
*
6872
* @default undefined
6973
*/
7074
responseHook?: GraphQLInstrumentationExecutionResponseHook;

0 commit comments

Comments
 (0)