Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(graphql): update span name to show the resolver name #1796

Conversation

diogotorres97
Copy link
Contributor

@diogotorres97 diogotorres97 commented Nov 13, 2023

BEGIN_COMMIT_OVERRIDE
feat!(graphql): update span name to show the resolver name
END_COMMIT_OVERRIDE

Which problem is this PR solving?

Fixes #1791

Short description of the changes

This PR updates (opentelemetry-instrumentation-graphql) the resolvers' span name.
It will show something like: graphql-resolve hello instead of graphql-resolve. This is very useful to easily understand at a top level which field is being resolved.

E.g.,

query ExampleQuery {
  me {
    name 
    }
}
Screenshot 2023-11-13 at 11 25 18

@diogotorres97 diogotorres97 requested a review from a team November 13, 2023 11:26
Copy link

linux-foundation-easycla bot commented Nov 13, 2023

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: diogotorres97 / name: Diogo Torres (a92bfc4)
  • ✅ login: dyladan / name: Daniel Dyla (c5c1e99)

@diogotorres97 diogotorres97 force-pushed the enhancement/add-query-name-to-graphql-instrumentation branch 2 times, most recently from 0f4c241 to 2fe1471 Compare November 13, 2023 11:35
@satazor
Copy link
Contributor

satazor commented Nov 13, 2023

Not sure who to ping here for visibility, cc @blumamir

Copy link

codecov bot commented Nov 13, 2023

Codecov Report

Merging #1796 (c5c1e99) into main (eee50d8) will decrease coverage by 0.43%.
The diff coverage is n/a.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1796      +/-   ##
==========================================
- Coverage   91.42%   91.00%   -0.43%     
==========================================
  Files         143      133      -10     
  Lines        7303     6580     -723     
  Branches     1461     1311     -150     
==========================================
- Hits         6677     5988     -689     
+ Misses        626      592      -34     
Files Coverage Δ
...opentelemetry-instrumentation-graphql/src/utils.ts 93.17% <ø> (ø)

... and 10 files with indirect coverage changes

@diogotorres97 diogotorres97 force-pushed the enhancement/add-query-name-to-graphql-instrumentation branch from 2fe1471 to 633f733 Compare November 13, 2023 17:14
@diogotorres97 diogotorres97 force-pushed the enhancement/add-query-name-to-graphql-instrumentation branch from b4b8beb to a92bfc4 Compare November 13, 2023 17:17
@diogotorres97
Copy link
Contributor Author

Rebased and fixed linter issues

@dyladan
Copy link
Member

dyladan commented Nov 13, 2023

Looks like there's no code owner for these files. @open-telemetry/javascript-approvers please take a look if you have time

Copy link
Member

@Flarna Flarna left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To my understanding this doesn't fit the graphql semantic conventions.

I guess first step here should be a PR on the semantic-conventions repo to get consensus if this is wanted or not.

@diogotorres97
Copy link
Contributor Author

diogotorres97 commented Nov 14, 2023

To my understanding this doesn't fit the graphql semantic conventions.

I guess first step here should be a PR on the semantic-conventions repo to get consensus if this is wanted or not.

@Flarna I didn't understand why it doesn't fit, here we are updating the resolver part (inside of a query or mutation). That link refers to graphql.operation.type: query, mutation and subscription. But this is something more internal and not a graphql operation.

@dyladan
Copy link
Member

dyladan commented Nov 14, 2023

It looks like there is no resolver in the semconv. It might be worth opening a semconv issue or PR to cover this area to ensure all languages are handling it the same way. Do we know if other languages have instrumentations for graphql and how they're handling this?

@Flarna
Copy link
Member

Flarna commented Nov 14, 2023

Ah ok sorry. Seems I lack graphql knowledge.
As long as the names fit to the general span requirements it should be fine I think.

But I agree with @dyladan that a spec improvement might make sense if this is something other languages have also to keep consistency.

Copy link
Member

@dyladan dyladan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As long as the names fit to the general span requirements it should be fine I think.

I agree. I'm not a graphql expert but I think this fits the requirement to be limited cardinality and should be fine. In any case it can't be higher cardinality than the attribute which should also be limited.

@dyladan dyladan merged commit 99db4bb into open-telemetry:main Nov 14, 2023
15 checks passed
@jcarres-mdsol
Copy link

IMHO it does not fit the requirement of limited cardinality.
This graph is showing the cardinality of the operation name, the orange is our graphql in develop where we updated this library
Screenshot 2024-03-07 at 11 48 46 AM

Moving this to production would make this much worse. I think any organization with a lot going on with graphql will suffer from this.

@satazor
Copy link
Contributor

satazor commented Mar 7, 2024

@jcarres-mdsol I have to disagree. The document you linked lists examples of good and bad values in regards to cardinality. With this PR, the span name is no longer a generic name, increasing cardinality but it doesn’t include any dynamic identifier, such as a user id, which would violate the rules set in the document. I would argue that having resolve like it was before would actually violate the rules because it’s too generic (too generic is listed as a bad value).

Now span names in graphql resolvers are identifiable and we can make aggregations on which ones are slower etc, much like you have different span names for different functions etc.

If this raises concerns about performance or other issues, perhaps this could be under an option.

@jcarres-mdsol
Copy link

We have solved this with a regex in the collector.

The original operation names are something like x.y.z.a.b , it is true it is not infinite like if they were UUIDs or something but still 10s/100s of 1000s. So we have regex this to x.y this is enough in our case to identify it enough, also the whole path is keep in an attribute anyways.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add path to span name of graphq.resolve spans created by graphql instrumentation
6 participants