Skip to content

Commit

Permalink
chore(graphql): update span name to show the resolver name (open-tele…
Browse files Browse the repository at this point in the history
…metry#1796)

Co-authored-by: Daniel Dyla <dyladan@users.noreply.github.com>
  • Loading branch information
diogotorres97 and dyladan committed Nov 14, 2023
1 parent eee50d8 commit 99db4bb
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ function createResolverSpan(
};

const span = tracer.startSpan(
SpanNames.RESOLVE,
`${SpanNames.RESOLVE} ${attributes[AttributeNames.FIELD_PATH]}`,
{
attributes,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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');
Expand All @@ -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);
});

Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 99db4bb

Please sign in to comment.