File tree Expand file tree Collapse file tree 2 files changed +49
-0
lines changed
dev-packages/browser-integration-tests/suites/public-api/beforeSendTransaction Expand file tree Collapse file tree 2 files changed +49
-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 } 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+ const url = await getLocalTestUrl ( { testDir : __dirname } ) ;
12+
13+ const eventData = await getFirstSentryEnvelopeRequest < Event > ( page , url ) ;
14+
15+ expect ( eventData . type ) . toBe ( 'transaction' ) ;
16+
17+ // user-changed name
18+ expect ( eventData . transaction ) . toBe ( 'customName' ) ;
19+
20+ // Despite the user setting the source to 'route', the SDK detects that the txn name was changed
21+ // and therefore sets the source to 'custom'. This is not ideal but also not easily changeable.
22+ // Given that Relay doesn't differentiate between 'source' and 'route', we'll keep this as-is for now.
23+ expect ( eventData . transaction_info ?. source ) . toBe ( 'custom' ) ;
24+ expect ( eventData . contexts ?. trace ?. data ?. [ SEMANTIC_ATTRIBUTE_SENTRY_SOURCE ] ) . toBe ( 'custom' ) ;
25+ } ,
26+ ) ;
You can’t perform that action at this time.
0 commit comments