Skip to content

Commit b05b272

Browse files
committed
added test for validation errors
1 parent 8eef5e1 commit b05b272

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

packages/plugins/opentelemetry/tests/useOpenTelemetry.spec.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ import {
6767
getSpanProcessors,
6868
getTracerProvider,
6969
MockLogRecordExporter,
70+
MockSpanExporter,
7071
setupOtelForTests,
7172
spanExporter,
7273
} from './utils';
@@ -768,7 +769,41 @@ describe('useOpenTelemetry', () => {
768769
initSpan.expectChild('http.fetch');
769770
});
770771
});
772+
773+
it('should handle validation error with hive processor', async () => {
774+
disableAll();
775+
const spanExporter = new MockSpanExporter();
776+
const traceProvider = new BasicTracerProvider({
777+
spanProcessors: [
778+
new HiveTracingSpanProcessor({
779+
processor: new SimpleSpanProcessor(spanExporter),
780+
}),
781+
],
782+
});
783+
setupOtelForTests({ traceProvider });
784+
await using gateway = await buildTestGatewayForCtx({
785+
plugins: ({ fetch }) => {
786+
return [
787+
{
788+
onPluginInit() {
789+
fetch('http://foo.bar', {});
790+
},
791+
},
792+
];
793+
},
794+
});
795+
await gateway.query({
796+
body: { query: 'query test{ unknown }' },
797+
shouldReturnErrors: true,
798+
});
799+
800+
const operationSpan = spanExporter.assertRoot('graphql.operation');
801+
operationSpan.span.attributes['graphql.operation.name'] === 'test';
802+
operationSpan.span.attributes['graphql.operation.type'] === 'query';
803+
operationSpan.span.attributes['hive.graphql.error.count'] === 1;
804+
});
771805
});
806+
772807
it('should allow to create custom spans without explicit context passing', async () => {
773808
const expectedCustomSpans = {
774809
http: { root: 'POST /graphql', children: ['custom.request'] },

packages/plugins/opentelemetry/tests/utils.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
propagation,
1212
ProxyTracerProvider,
1313
trace,
14+
TracerProvider,
1415
TraceState,
1516
type TextMapPropagator,
1617
} from '@opentelemetry/api';
@@ -245,10 +246,12 @@ const traceProvider = new BasicTracerProvider({
245246

246247
export function setupOtelForTests({
247248
contextManager,
249+
traceProvider: temporaryTraceProvider,
248250
}: {
249251
contextManager?: boolean;
252+
traceProvider?: TracerProvider;
250253
} = {}) {
251-
trace.setGlobalTracerProvider(traceProvider);
254+
trace.setGlobalTracerProvider(temporaryTraceProvider ?? traceProvider);
252255
if (contextManager !== false) {
253256
context.setGlobalContextManager(new AsyncLocalStorageContextManager());
254257
}

0 commit comments

Comments
 (0)