1- import type { Hub , Scope , Span , SpanTimeInput , StartSpanOptions , TransactionContext } from '@sentry/types' ;
1+ import type {
2+ ClientOptions ,
3+ Hub ,
4+ Scope ,
5+ Span ,
6+ SpanTimeInput ,
7+ StartSpanOptions ,
8+ TransactionContext ,
9+ } from '@sentry/types' ;
210
311import { dropUndefinedKeys , logger , tracingContextFromHeaders } from '@sentry/utils' ;
412import type { AsyncContextStrategy } from '../asyncContext' ;
513import { getMainCarrier } from '../asyncContext' ;
6- import { getCurrentScope , getIsolationScope , withScope } from '../currentScopes' ;
14+ import { getClient , getCurrentScope , getIsolationScope , withScope } from '../currentScopes' ;
715
816import { DEBUG_BUILD } from '../debug-build' ;
917import { getAsyncContextStrategy , getCurrentHub } from '../hub' ;
@@ -17,9 +25,11 @@ import {
1725 spanToJSON ,
1826} from '../utils/spanUtils' ;
1927import { getDynamicSamplingContextFromSpan } from './dynamicSamplingContext' ;
28+ import { sampleTransaction } from './sampling' ;
2029import { SentryNonRecordingSpan } from './sentryNonRecordingSpan' ;
2130import type { SentrySpan } from './sentrySpan' ;
2231import { SPAN_STATUS_ERROR } from './spanstatus' ;
32+ import { Transaction } from './transaction' ;
2333import { setCapturedScopesOnSpan } from './utils' ;
2434
2535/**
@@ -324,8 +334,7 @@ function createChildSpanOrTransaction(
324334 const { traceId, spanId : parentSpanId } = parentSpan . spanContext ( ) ;
325335 const sampled = spanIsSampled ( parentSpan ) ;
326336
327- // eslint-disable-next-line deprecation/deprecation
328- span = hub . startTransaction ( {
337+ span = _startTransaction ( {
329338 traceId,
330339 parentSpanId,
331340 parentSampled : sampled ,
@@ -342,8 +351,7 @@ function createChildSpanOrTransaction(
342351 ...scope . getPropagationContext ( ) ,
343352 } ;
344353
345- // eslint-disable-next-line deprecation/deprecation
346- span = hub . startTransaction ( {
354+ span = _startTransaction ( {
347355 traceId,
348356 parentSpanId,
349357 parentSampled : sampled ,
@@ -390,3 +398,26 @@ function getAcs(): AsyncContextStrategy {
390398 const carrier = getMainCarrier ( ) ;
391399 return getAsyncContextStrategy ( carrier ) ;
392400}
401+
402+ function _startTransaction ( transactionContext : TransactionContext ) : Transaction {
403+ const client = getClient ( ) ;
404+ const options : Partial < ClientOptions > = ( client && client . getOptions ( ) ) || { } ;
405+
406+ // eslint-disable-next-line deprecation/deprecation
407+ let transaction = new Transaction ( transactionContext , getCurrentHub ( ) ) ;
408+ transaction = sampleTransaction ( transaction , options , {
409+ name : transactionContext . name ,
410+ parentSampled : transactionContext . parentSampled ,
411+ transactionContext,
412+ attributes : {
413+ // eslint-disable-next-line deprecation/deprecation
414+ ...transactionContext . data ,
415+ ...transactionContext . attributes ,
416+ } ,
417+ } ) ;
418+ if ( client ) {
419+ client . emit ( 'startTransaction' , transaction ) ;
420+ client . emit ( 'spanStart' , transaction ) ;
421+ }
422+ return transaction ;
423+ }
0 commit comments