Skip to content

Commit 6e05169

Browse files
committed
add test
1 parent 6de209a commit 6e05169

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

packages/node/src/otel/instrument.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import type { Instrumentation } from '@opentelemetry/instrumentation';
22
import { addOpenTelemetryInstrumentation } from '@sentry/opentelemetry';
33

4-
const INSTRUMENTED: Record<string, Instrumentation> = {};
4+
/** Exported only for tests. */
5+
export const INSTRUMENTED: Record<string, Instrumentation> = {};
56

67
/**
78
* Instrument an OpenTelemetry instrumentation once.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { GraphQLInstrumentation } from '@opentelemetry/instrumentation-graphql';
2+
import { graphqlIntegration, instrumentGraphql } from '../../../src/integrations/tracing/graphql';
3+
import { INSTRUMENTED } from '../../../src/otel/instrument';
4+
5+
jest.mock('@opentelemetry/instrumentation-graphql');
6+
7+
describe('GraphQL', () => {
8+
beforeEach(() => {
9+
jest.clearAllMocks();
10+
delete INSTRUMENTED.Graphql;
11+
12+
(GraphQLInstrumentation as unknown as jest.SpyInstance).mockImplementation(() => {
13+
return {
14+
setTracerProvider: () => undefined,
15+
setMeterProvider: () => undefined,
16+
getConfig: () => ({}),
17+
setConfig: () => ({}),
18+
enable: () => undefined,
19+
};
20+
});
21+
});
22+
23+
it('defaults are correct for instrumentGraphql', () => {
24+
instrumentGraphql({ ignoreTrivialResolveSpans: false });
25+
26+
expect(GraphQLInstrumentation).toHaveBeenCalledTimes(1);
27+
expect(GraphQLInstrumentation).toHaveBeenCalledWith({
28+
ignoreResolveSpans: true,
29+
ignoreTrivialResolveSpans: false,
30+
useOperationNameForRootSpan: true,
31+
responseHook: expect.any(Function),
32+
});
33+
});
34+
35+
it('defaults are correct for _graphqlIntegration', () => {
36+
graphqlIntegration({ ignoreTrivialResolveSpans: false }).setupOnce!();
37+
38+
expect(GraphQLInstrumentation).toHaveBeenCalledTimes(1);
39+
expect(GraphQLInstrumentation).toHaveBeenCalledWith({
40+
ignoreResolveSpans: true,
41+
ignoreTrivialResolveSpans: false,
42+
useOperationNameForRootSpan: true,
43+
responseHook: expect.any(Function),
44+
});
45+
});
46+
});

0 commit comments

Comments
 (0)