|
| 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