question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Setting transaction name doesn't work from child span.

See original GitHub issue

Environment

How do you use Sentry? Sentry SaaS (sentry.io)

Which SDK and version? Python/Django: django-sentry-1.13.5, sentry-sdk-1.3.0 (also tried sentry-sdk-1.1.0)

Steps to Reproduce

We’re using Sentry in Django and Graphene (for GraphQL support). We would like to set the transaction name based on GraphQL operation name.


urlpatterns = [
    # ...snip
    path(
        'graphql',
        csrf_exempt(MyGraphQLView.as_view(graphiql=settings.GRAPHIQL_ENABLED)),
    ),
]

class MyGraphQLView(graphene_django.views.GraphQLView):
    def execute_graphql_request(
        self, request, data, query, variables, operation_name, show_graphiql=False
    ):
        with sentry_sdk.configure_scope() as scope:
            transaction_name = f'graphql.{operation_name}' # graphql.OperationName
            scope.transaction = transaction_name
            # This works:
            scope._span._containing_transaction.name = transaction_name
            return super().execute_graphql_request(
                request, data, query, variables, operation_name, show_graphiql
            )

From the trace view in Sentry, the GraphQLView span is nested several spans down (in Django middlewares). From my understanding of the sentry documentation: set transaction name It seems like the scope.transaction = 'name' setter should be enough, but doesn’t seem to work from child spans.

Expected Result

Sentry transaction name updated to graphql.OperationName.

Actual Result

Sentry transaction name stays as /graphql

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
CoatedMoosecommented, Feb 28, 2022

I’m in the middle of some tasks and I can’t check right now, but will hopefully be able to later in the week.

0reactions
lobsterkatiecommented, Mar 9, 2022

Hi, @CoatedMoose. While you’re not wrong in your expectation, given the docs, making scope.transaction = new_name work means you’re relying on the weird type mismatch between the transaction getter and setter. Much better to do scope.transaction.name, both because it makes more sense and because it future-proofs you for the day when we finally fix that mismatch.

I’ll fix the docs to reflect this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Span records missing transaction.name
I believe the issue is that not all Span records have their transaction.name attribute set. As an example,. There is one Transaction record...
Read more >
Some spans are missing in a transaction and span parent ...
Some spans are missing in a transaction and span parent child relationship (Child span starting position) is incorrect in APM Timeline. #1088.
Read more >
HTTP spans doesn't show the full information about the request
Hi! I'm using Opentelemetry + Elastic. The problem that I'm facing is that the http requests child spans doesn't show the full information....
Read more >
Guidelines for Performance Monitoring
The Span class stores each individual span in a trace. The Transaction class is like a span, with a few key differences: Transactions...
Read more >
Using Transactions in Quarkus
You don't need to worry about setting it up most of the time as ... child, String giftDescription) { // some transaction work...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found