From 99db4bb89d717b65c6f91461e466882b09677852 Mon Sep 17 00:00:00 2001 From: Diogo Torres Date: Tue, 14 Nov 2023 19:13:10 +0000 Subject: [PATCH] chore(graphql): update span name to show the resolver name (#1796) Co-authored-by: Daniel Dyla --- .../src/utils.ts | 2 +- .../test/graphql.test.ts | 12 +++++++----- .../test/helper.ts | 5 ++++- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/plugins/node/opentelemetry-instrumentation-graphql/src/utils.ts b/plugins/node/opentelemetry-instrumentation-graphql/src/utils.ts index 9e183fb2a95..04085fbe5db 100644 --- a/plugins/node/opentelemetry-instrumentation-graphql/src/utils.ts +++ b/plugins/node/opentelemetry-instrumentation-graphql/src/utils.ts @@ -129,7 +129,7 @@ function createResolverSpan( }; const span = tracer.startSpan( - SpanNames.RESOLVE, + `${SpanNames.RESOLVE} ${attributes[AttributeNames.FIELD_PATH]}`, { attributes, }, diff --git a/plugins/node/opentelemetry-instrumentation-graphql/test/graphql.test.ts b/plugins/node/opentelemetry-instrumentation-graphql/test/graphql.test.ts index a9e379592d8..d570a38e1aa 100644 --- a/plugins/node/opentelemetry-instrumentation-graphql/test/graphql.test.ts +++ b/plugins/node/opentelemetry-instrumentation-graphql/test/graphql.test.ts @@ -613,7 +613,7 @@ describe('graphql', () => { await graphql({ schema: simpleSchemaWithResolver, source: '{ hello }' }); const resovleSpans = exporter .getFinishedSpans() - .filter(span => span.name === SpanNames.RESOLVE); + .filter(span => span.name === `${SpanNames.RESOLVE} hello`); assert.deepStrictEqual(resovleSpans.length, 1); const resolveSpan = resovleSpans[0]; assert(resolveSpan.attributes[AttributeNames.FIELD_PATH] === 'hello'); @@ -633,7 +633,7 @@ describe('graphql', () => { await graphql({ schema, source: '{ hello }', rootValue }); const resovleSpans = exporter .getFinishedSpans() - .filter(span => span.name === SpanNames.RESOLVE); + .filter(span => span.name === `${SpanNames.RESOLVE} hello`); assert.deepStrictEqual(resovleSpans.length, 1); const resolveSpan = resovleSpans[0]; assert(resolveSpan.attributes[AttributeNames.FIELD_PATH] === 'hello'); @@ -653,7 +653,7 @@ describe('graphql', () => { await graphql({ schema, source: '{ hello }', rootValue }); const resovleSpans = exporter .getFinishedSpans() - .filter(span => span.name === SpanNames.RESOLVE); + .filter(span => span.name === `${SpanNames.RESOLVE} hello`); assert.deepStrictEqual(resovleSpans.length, 0); }); @@ -682,7 +682,7 @@ describe('graphql', () => { await graphql({ schema, source: '{ hello }', rootValue, fieldResolver }); const resovleSpans = exporter .getFinishedSpans() - .filter(span => span.name === SpanNames.RESOLVE); + .filter(span => span.name === `${SpanNames.RESOLVE} hello`); assert.deepStrictEqual(resovleSpans.length, 1); const resolveSpan = resovleSpans[0]; assert(resolveSpan.attributes[AttributeNames.FIELD_PATH] === 'hello'); @@ -1355,7 +1355,9 @@ describe('graphql', () => { const spans = exporter.getFinishedSpans(); // single resolve span with error and event for exception - const resolveSpans = spans.filter(s => s.name === SpanNames.RESOLVE); + const resolveSpans = spans.filter( + s => s.name === `${SpanNames.RESOLVE} hello` + ); assert.deepStrictEqual(resolveSpans.length, 1); const resolveSpan = resolveSpans[0]; assert.deepStrictEqual(resolveSpan.status.code, SpanStatusCode.ERROR); diff --git a/plugins/node/opentelemetry-instrumentation-graphql/test/helper.ts b/plugins/node/opentelemetry-instrumentation-graphql/test/helper.ts index e7f564096b2..56ebe30fda1 100644 --- a/plugins/node/opentelemetry-instrumentation-graphql/test/helper.ts +++ b/plugins/node/opentelemetry-instrumentation-graphql/test/helper.ts @@ -28,7 +28,10 @@ export function assertResolveSpan( parentSpanId?: string ) { const attrs = span.attributes; - assert.deepStrictEqual(span.name, SpanNames.RESOLVE); + assert.deepStrictEqual( + span.name, + `${SpanNames.RESOLVE} ${attrs[AttributeNames.FIELD_PATH]}` + ); assert.deepStrictEqual(attrs[AttributeNames.FIELD_NAME], fieldName); assert.deepStrictEqual(attrs[AttributeNames.FIELD_PATH], fieldPath); assert.deepStrictEqual(attrs[AttributeNames.FIELD_TYPE], fieldType);