File tree Expand file tree Collapse file tree 2 files changed +55
-0
lines changed
dev-packages/browser-integration-tests/suites/public-api/beforeSendTransaction Expand file tree Collapse file tree 2 files changed +55
-0
lines changed Original file line number Diff line number Diff line change 1+ import * as Sentry from '@sentry/browser' ;
2+
3+ window . Sentry = Sentry ;
4+
5+ Sentry . init ( {
6+ dsn :
'https://[email protected] /1337' , 7+ integrations : [ Sentry . browserTracingIntegration ( ) ] ,
8+ beforeSendTransaction : transactionEvent => {
9+ const op = transactionEvent . contexts . trace . op ;
10+ if ( op === 'pageload' || op === 'navigation' ) {
11+ // use whatever logic you want to set the name
12+ transactionEvent . transaction = 'customName' ;
13+
14+ transactionEvent . transaction_info . source = 'route' ;
15+ transactionEvent . contexts . trace . data = {
16+ ...transactionEvent . contexts . trace . data ,
17+ [ Sentry . SEMANTIC_ATTRIBUTE_SENTRY_SOURCE ] : 'route' ,
18+ } ;
19+ }
20+ return transactionEvent ;
21+ } ,
22+ tracesSampleRate : 1 ,
23+ } ) ;
Original file line number Diff line number Diff line change 1+ import { expect } from '@playwright/test' ;
2+ import type { Event } from '@sentry/types' ;
3+
4+ import { SEMANTIC_ATTRIBUTE_SENTRY_SOURCE } from '@sentry/browser' ;
5+ import { sentryTest } from '../../../utils/fixtures' ;
6+ import { getFirstSentryEnvelopeRequest , shouldSkipTracingTest } from '../../../utils/helpers' ;
7+
8+ sentryTest (
9+ 'allows modification of the transaction name and source but overwrites source to custom' ,
10+ async ( { getLocalTestUrl, page } ) => {
11+ if ( shouldSkipTracingTest ( ) ) {
12+ sentryTest . skip ( ) ;
13+ }
14+
15+ const url = await getLocalTestUrl ( { testDir : __dirname } ) ;
16+
17+ const eventData = await getFirstSentryEnvelopeRequest < Event > ( page , url ) ;
18+
19+ expect ( eventData . type ) . toBe ( 'transaction' ) ;
20+
21+ // user-changed name
22+ expect ( eventData . transaction ) . toBe ( 'customName' ) ;
23+
24+ // Despite the user setting the source to 'route', the SDK detects that the txn name was changed
25+ // and therefore sets the transaction_info.source to 'custom'. This is not ideal but also not easily changeable.
26+ // Given that Relay doesn't differentiate between 'source' and 'route', we'll keep this as-is for now.
27+ expect ( eventData . transaction_info ?. source ) . toBe ( 'custom' ) ;
28+
29+ // This stays the same but it has no effect on Relay.
30+ expect ( eventData . contexts ?. trace ?. data ?. [ SEMANTIC_ATTRIBUTE_SENTRY_SOURCE ] ) . toBe ( 'route' ) ;
31+ } ,
32+ ) ;
You can’t perform that action at this time.
0 commit comments