Skip to content

Txn source: "url" even though set manually in beforeNavigate() #8182

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

Closed
3 tasks done
realkosty opened this issue May 22, 2023 · 13 comments
Closed
3 tasks done

Txn source: "url" even though set manually in beforeNavigate() #8182

realkosty opened this issue May 22, 2023 · 13 comments
Labels
Sync: Jira apply to auto-create a Jira shadow ticket

Comments

@realkosty
Copy link

realkosty commented May 22, 2023

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/browser

SDK Version

7.51.1

Framework Version

No response

Link to Sentry event

*** See linked Jira ticket ***

SDK Setup

Sentry.init({
      dsn: _dsn,
     
      integrations: [
        new Sentry.BrowserTracing({
          tracingOrigins: [
            // ...
          ],
          beforeNavigate: (context) => {
            return {
              ...context,
              name: transactionName()
            };
          }
        }),
       
      // ...

      routingInstrumentation: Sentry.reactRouterV5Instrumentation(
        history,
        REACT_ROUTER_ROUTES,
        matchPath
      ),

      // ...

    });

// ...

export const transactionName = () => {
  const { pathname } = window.location;

  // ...

  // temporarily fixes <<unparameterized>> grouping as recommended by sentry engineers
  // this unblocks analytics performance monitoring until sentry fixes an issue
  // with transaction grouping on their end. 
  // ref - https://develop.sentry.dev/transaction-clustering/
  if (pathname === '/') {
    return '/';
  }

  // ...

};

Steps to Reproduce

Go to customer website *** see linked Jira ticket ***
Capture a few dozen pageloads until transaction is sampled (their tracesSampleRate is 0.1), get the id
Look at txn in Sentry.
Examine their sentry.js if needed for more detail

Expected Result

transaction.source: "custom"

Actual Result

transaction.source: "url"

ROOT CAUSE: https://github.com/getsentry/sentry-javascript/blob/ff4b1a85b3c04d2782880629b0d5be591568deaf/packages/tracing-internal/src/browser/browsertracing.ts#LL297C49-L297C49

Original PR: #5396

┆Issue is synchronized with this Jira Improvement by Unito

@realkosty realkosty added the Sync: Jira apply to auto-create a Jira shadow ticket label May 22, 2023
@Lms24
Copy link
Member

Lms24 commented May 23, 2023

What should the change look like? Removing the name change check would always set the source to custom even if users change around different stuff in beforeNavigate but don't change the transaction name.

@realkosty
Copy link
Author

@lforst what do you think?

@lforst
Copy link
Contributor

lforst commented May 23, 2023

@realkosty I don't think the code section you identified as the root cause is the actual problem - unless I am missing somthing ofc. Can you elaborate a bit how "url" may end up in the new transaction source here?

@realkosty
Copy link
Author

@lforst this behavior happens specifically when name set in beforeNavigate is identical to name derived from URL. The !== condition in the code results in source: custom not being set.

@Lms24
Copy link
Member

Lms24 commented May 24, 2023

Hmm I honestly still think this is fine generally but I can see how this is a problem for users who manually try to parameterize their routes and come across routes that don't have parameters at all. Like /.

The problem I see with removing this check is that if users leave urls with params as-is (e.g. /users/123), we mark an unparameterized URL as parameterized by always setting the source to custom as soon as beforeNavigate was invoked.

@lforst
Copy link
Contributor

lforst commented May 24, 2023

I am not sure if we should change the current behaviour. What the user could do however is something like:

beforeNavigate: (context) => {
  return {
    ...context,
	metadata: {
		source: transactionName() === '/' ? 'custom' : undefined
	}
  };
}

Does that sound reasonable?

In general, I am wondering if we should set transactions with the name "/" to custom always.

@Lms24
Copy link
Member

Lms24 commented May 24, 2023

Unless we want to remove the equality check (i.e. assume calling beforeNavigate always results in a custom txn name source), I agree that users should set the source manually to custom.

In general, I am wondering if we should set transactions with the name "/" to custom always.

It's worth a thought IMO but probably quite intransparent for users ("i.e. why is / shown as parameterized while /users is unparamterized - both have no params?!")

@realkosty
Copy link
Author

realkosty commented May 24, 2023

I can see how this may be tricky to implement but don't get the principal objections:

  • If users sets txn name explicitly in beforeSend source should be "custom".
  • If txn name is automatically derived from URL source should be "url".

What's so controversial about this?

@lforst
Copy link
Contributor

lforst commented May 24, 2023

What's so controversial about this?

Nothing's controversial. Maybe the tone of the conversation didn't transfer well here ^^ I also get the frustration.

I think the reason Lukas and I are a bit careful and not jumping to fixes is because this has gone through a 💩-ton of discussions already, and we basically settled that we were gonna have server-side heuristics in relay to parameterize transactions in cases where it's not possible to parameterize with 100% certainty (like in this case).

As for "/" it is the only case where I would say we can make an exception. The other cases you mentioned ("/asdf" etc.) are unfixable from the SDK side of things. IMO it's more correct if we continue sending "/" with source "url" and let relay make the special casing here.

Btw if "/" shows up under unparameterized, we likely have an issue in Relay with the auto-grouping logic. These transactions should very likely be promoted to parameterized. cc @jjbayer @iker-barriocanal

@realkosty
Copy link
Author

realkosty commented May 24, 2023

@lforst Got it, thanks for the context. I understand the pushback/caution since changing this may have all sorts of implications and might miss something important that came up in those past discussions.

Btw if "/" shows up under unparameterized, we likely have an issue in Relay with the auto-grouping logic. These transactions should very likely be promoted to parameterized. cc @jjbayer @iker-barriocanal

There is indeed an issue and Relay team is aware of it. Sorry if I didn't make that clear. But there always be edge-cases - after all it's heuristic, don't you think? Customers need a way to override it by manually specifying txn name.

Right now in the when you click on << unparameterized >> in the transactions list you get this callout:
Screenshot 2023-05-24 at 7 35 52 AM
that links to https://docs.sentry.io/platforms/javascript/performance/instrumentation/automatic-instrumentation/#beforenavigate

@hubertdeng123 hubertdeng123 added Sync: Jira apply to auto-create a Jira shadow ticket and removed Sync: Jira apply to auto-create a Jira shadow ticket labels May 24, 2023
@jjbayer
Copy link
Member

jjbayer commented May 25, 2023

In general, whenever the user sets the transaction name, its source should be set to custom (see docs). I always assumed that the only way for the user to do so is via setTransactionName(). If there are other APIs for manually changing the transaction name, they should set the source to custom as well.

@github-actions
Copy link
Contributor

This issue has gone three weeks without activity. In another week, I will close it.

But! If you comment or otherwise update it, I will reset the clock, and if you label it Status: Backlog or Status: In Progress, I will leave it alone ... forever!


"A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀

@github-actions
Copy link
Contributor

github-actions bot commented Jul 8, 2023

This issue has gone three weeks without activity. In another week, I will close it.

But! If you comment or otherwise update it, I will reset the clock, and if you label it Status: Backlog or Status: In Progress, I will leave it alone ... forever!


"A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 Jul 25, 2023
@AbhiPrasad AbhiPrasad closed this as not planned Won't fix, can't repro, duplicate, stale Jul 27, 2023
@getsantry getsantry bot removed the status in GitHub Issues with 👀 Aug 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Sync: Jira apply to auto-create a Jira shadow ticket
Projects
Archived in project
Development

No branches or pull requests

7 participants