Skip to content

Commit 7367ac5

Browse files
committed
copy error count and code for parse, validate and execute
1 parent dfbb755 commit 7367ac5

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

packages/plugins/opentelemetry/src/hive-span-processor.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,12 @@ export class HiveTracingSpanProcessor implements SpanProcessor {
151151
return;
152152
}
153153

154-
if (span.name === 'graphql.execute') {
154+
if (SPANS_WITH_ERRORS.includes(span.name)) {
155155
copyAttribute(span, operationSpan, SEMATTRS_HIVE_GRAPHQL_ERROR_CODES);
156156
copyAttribute(span, operationSpan, SEMATTRS_HIVE_GRAPHQL_ERROR_COUNT);
157+
}
158+
159+
if (span.name === 'graphql.execute') {
157160
copyAttribute(
158161
span,
159162
operationSpan,
@@ -196,3 +199,9 @@ function copyAttribute(
196199
) {
197200
target.attributes[targetAttrName] = source.attributes[sourceAttrName];
198201
}
202+
203+
const SPANS_WITH_ERRORS = [
204+
'graphql.parse',
205+
'graphql.validate',
206+
'graphql.execute',
207+
];

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -770,9 +770,8 @@ describe('useOpenTelemetry', () => {
770770
});
771771
});
772772

773-
it('should handle validation error with hive processor', async () => {
773+
it.only('should handle validation error with hive processor', async () => {
774774
disableAll();
775-
const spanExporter = new MockSpanExporter();
776775
const traceProvider = new BasicTracerProvider({
777776
spanProcessors: [
778777
new HiveTracingSpanProcessor({
@@ -798,9 +797,15 @@ describe('useOpenTelemetry', () => {
798797
});
799798

800799
const operationSpan = spanExporter.assertRoot('graphql.operation test');
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;
800+
expect(operationSpan.span.attributes['graphql.operation.name']).toBe(
801+
'test',
802+
);
803+
expect(operationSpan.span.attributes['graphql.operation.type']).toBe(
804+
'query',
805+
);
806+
expect(
807+
operationSpan.span.attributes[SEMATTRS_HIVE_GRAPHQL_ERROR_COUNT],
808+
).toBe(1);
804809
});
805810
});
806811

0 commit comments

Comments
 (0)