strawberry
strawberry copied to clipboard
opentelemetry: use semconv attributes
opentelemetry: use semconv attributes
Description
- use attributes defined in opentelemetry's semconv
- stop setting span attribute
component, as that's been deprecated - fixes #3769
Types of Changes
- [ ] Core
- [x] Bugfix
- [ ] New feature
- [x] Enhancement/optimization
- [ ] Documentation
Issues Fixed or Closed by This PR
- #3769
Checklist
- [x] My code follows the code style of this project.
- [ ] My change requires a change to the documentation.
- [x] I have updated the documentation accordingly.
- [x] I have read the CONTRIBUTING document.
- [x] I have added tests to cover my changes.
- [x] I have tested the changes and verified that they work and don't break anything (as well as I can manage).
Summary by Sourcery
Updates the OpenTelemetry extension to use semantic convention attributes, set the GraphQL operation name and type as span attributes, and stop setting the deprecated component span attribute.
Bug Fixes:
- Stops setting the deprecated
componentspan attribute.
Enhancements:
- Updates the OpenTelemetry extension to use attributes defined in the OpenTelemetry semantic conventions for GraphQL.
- Sets the GraphQL operation name and type as span attributes, improving trace context and debugging.
Tests:
- Adds tests to verify that the GraphQL operation name is correctly added to the span's attributes.
Summary by Sourcery
Updates the OpenTelemetry extension to use semantic convention attributes, set the GraphQL operation name and type as span attributes, and stop setting the deprecated component span attribute.
Bug Fixes:
- Stops setting the deprecated
componentspan attribute.
Enhancements:
- Updates the OpenTelemetry extension to use attributes defined in the OpenTelemetry semantic conventions for GraphQL.
- Sets the GraphQL operation name and type as span attributes, improving trace context and debugging.
Tests:
- Adds tests to verify that the GraphQL operation name is correctly added to the span's attributes.
Reviewer's Guide by Sourcery
This pull request updates the OpenTelemetry extension to use semantic convention attributes, sets the GraphQL operation name and type as span attributes, and stops setting the deprecated component span attribute. This improves trace context and debugging.
Sequence diagram for GraphQL operation tracing with OpenTelemetry
sequenceDiagram
participant Client
participant Strawberry
participant OpenTelemetryTracer as Tracer
Client->>Strawberry: Sends GraphQL request
Strawberry->>Tracer: Start span (SERVER)
Tracer-->>Strawberry: Span started
Strawberry->>Tracer: Set attribute graphql.operation.name
Strawberry->>Tracer: Set attribute graphql.document
Strawberry-->>Strawberry: Executes GraphQL operation
Strawberry->>Tracer: Set attribute graphql.operation.name (if not already set)
Strawberry->>Tracer: Set attribute graphql.operation.type
Strawberry->>Tracer: End span
Tracer-->>Strawberry: Span ended
Strawberry-->>Client: Returns result
File-Level Changes
| Change | Details | Files |
|---|---|---|
| Updated the OpenTelemetry extension to use semantic convention attributes for GraphQL, improving trace context and debugging. |
|
strawberry/extensions/tracing/opentelemetry.pytests/schema/extensions/test_opentelemetry.py |
Assessment against linked issues
| Issue | Objective | Addressed | Explanation |
|---|---|---|---|
| #3769 | Use graphql.document, graphql.operation.name, and graphql.operation.type attributes as suggested by the opentelemetry semconv registry. |
✅ | |
| #3769 | Stop setting the component span attribute, as it has been deprecated. |
✅ |
Possibly linked issues
- #3769: PR implements the requested changes to use semconv attributes and deprecate "component".
- #3769: PR fixes issue by using semantic convention attributes and setting GraphQL operation name/type as span attributes.
Tips and commands
Interacting with Sourcery
- Trigger a new review: Comment
@sourcery-ai reviewon the pull request. - Continue discussions: Reply directly to Sourcery's review comments.
- Generate a GitHub issue from a review comment: Ask Sourcery to create an
issue from a review comment by replying to it. You can also reply to a
review comment with
@sourcery-ai issueto create an issue from it. - Generate a pull request title: Write
@sourcery-aianywhere in the pull request title to generate a title at any time. You can also comment@sourcery-ai titleon the pull request to (re-)generate the title at any time. - Generate a pull request summary: Write
@sourcery-ai summaryanywhere in the pull request body to generate a PR summary at any time exactly where you want it. You can also comment@sourcery-ai summaryon the pull request to (re-)generate the summary at any time. - Generate reviewer's guide: Comment
@sourcery-ai guideon the pull request to (re-)generate the reviewer's guide at any time. - Resolve all Sourcery comments: Comment
@sourcery-ai resolveon the pull request to resolve all Sourcery comments. Useful if you've already addressed all the comments and don't want to see them anymore. - Dismiss all Sourcery reviews: Comment
@sourcery-ai dismisson the pull request to dismiss all existing Sourcery reviews. Especially useful if you want to start fresh with a new review - don't forget to comment@sourcery-ai reviewto trigger a new review! - Generate a plan of action for an issue: Comment
@sourcery-ai planon an issue to generate a plan of action for it.
Customizing Your Experience
Access your dashboard to:
- Enable or disable review features such as the Sourcery-generated pull request summary, the reviewer's guide, and others.
- Change the review language.
- Add, remove or edit custom review instructions.
- Adjust other review settings.
Getting Help
- Contact our support team for questions or feedback.
- Visit our documentation for detailed guides and information.
- Keep in touch with the Sourcery team by following us on X/Twitter, LinkedIn or GitHub.
Thanks for adding the RELEASE.md file!

Here's a preview of the changelog:
Use OTEL's semconv attribute registry for span attributes. Stops setting component, which has been deprecated.
Here's the tweet text:
🆕 Release (next) is out! Thanks to Nick Yang for the PR 👏
Get it here 👉 https://strawberry.rocks/release/(next)
I really like the idea of adjusting our OTEL support to the standards. However, I'd prefer a gradual transition over to a new OTEL v2 extension instead of changing the attribute names. We do not want to break any metrics or alerts in production relying on the old attributes. Putting out a breaking change for this seems excessive, so I'd favor a new OTEL extension while a deprecation warning is printed every time the old extension is used. Maybe we can already add a scheduled removal date. Pinging @patrick91 for a second opinion on this though, as usually we just release breaking changes. I just think the workaround for users relying on OTEL here is cumbersome :D
this makes a lot of sense, not sure if another extension or a configuration in the extension, I think I'd prefer passing a flag, I don't think I want a OpenTelemetryV2Extension :D