Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
mydea committed Oct 8, 2024
1 parent 6de209a commit 6e05169
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/node/src/otel/instrument.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import type { Instrumentation } from '@opentelemetry/instrumentation';
import { addOpenTelemetryInstrumentation } from '@sentry/opentelemetry';

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

/**
* Instrument an OpenTelemetry instrumentation once.
Expand Down
46 changes: 46 additions & 0 deletions packages/node/test/integrations/tracing/graphql.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { GraphQLInstrumentation } from '@opentelemetry/instrumentation-graphql';
import { graphqlIntegration, instrumentGraphql } from '../../../src/integrations/tracing/graphql';
import { INSTRUMENTED } from '../../../src/otel/instrument';

jest.mock('@opentelemetry/instrumentation-graphql');

describe('GraphQL', () => {
beforeEach(() => {
jest.clearAllMocks();
delete INSTRUMENTED.Graphql;

(GraphQLInstrumentation as unknown as jest.SpyInstance).mockImplementation(() => {
return {
setTracerProvider: () => undefined,
setMeterProvider: () => undefined,
getConfig: () => ({}),
setConfig: () => ({}),
enable: () => undefined,
};
});
});

it('defaults are correct for instrumentGraphql', () => {
instrumentGraphql({ ignoreTrivialResolveSpans: false });

expect(GraphQLInstrumentation).toHaveBeenCalledTimes(1);
expect(GraphQLInstrumentation).toHaveBeenCalledWith({
ignoreResolveSpans: true,
ignoreTrivialResolveSpans: false,
useOperationNameForRootSpan: true,
responseHook: expect.any(Function),
});
});

it('defaults are correct for _graphqlIntegration', () => {
graphqlIntegration({ ignoreTrivialResolveSpans: false }).setupOnce!();

expect(GraphQLInstrumentation).toHaveBeenCalledTimes(1);
expect(GraphQLInstrumentation).toHaveBeenCalledWith({
ignoreResolveSpans: true,
ignoreTrivialResolveSpans: false,
useOperationNameForRootSpan: true,
responseHook: expect.any(Function),
});
});
});

0 comments on commit 6e05169

Please sign in to comment.