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

opentelemetry: use semconv attributes #3786

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

guppy0130
Copy link

@guppy0130 guppy0130 commented Feb 17, 2025

opentelemetry: use semconv attributes

Description

Types of Changes

  • Core
  • Bugfix
  • New feature
  • Enhancement/optimization
  • Documentation

Issues Fixed or Closed by This PR

Checklist

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • 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 component span 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 component span 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.

Copy link
Contributor

sourcery-ai bot commented Feb 17, 2025

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
Loading

File-Level Changes

Change Details Files
Updated the OpenTelemetry extension to use semantic convention attributes for GraphQL, improving trace context and debugging.
  • Replaced hardcoded attribute keys with constants from the opentelemetry.semconv.trace module.
  • Set the GraphQL operation name and type as span attributes.
  • Stopped setting the deprecated component span attribute.
strawberry/extensions/tracing/opentelemetry.py
tests/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


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on 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 issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on 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 dismiss on 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 review to trigger a new review!
  • Generate a plan of action for an issue: Comment @sourcery-ai plan on
    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

* use attributes defined in opentelemetry's semconv
* stop setting span attribute `component`, as that's been deprecated
* fixes strawberry-graphql#3769
@guppy0130 guppy0130 marked this pull request as ready for review February 17, 2025 18:11
@botberry
Copy link
Member

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)

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @guppy0130 - I've reviewed your changes - here's some feedback:

Overall Comments:

  • It might be worth adding a test case that verifies the GRAPHQL_OPERATION_TYPE attribute is set correctly when the operation type is a mutation or subscription.
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟡 Testing: 1 issue found
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

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.

opentelemetry: use attributes from semconv registry
2 participants