88 ScopeContext ,
99 Severity ,
1010 Span ,
11+ Transaction ,
1112 User ,
1213} from '@sentry/types' ;
1314import { getGlobalObject , isPlainObject , isThenable , SyncPromise , timestampWithMs } from '@sentry/utils' ;
@@ -47,8 +48,8 @@ export class Scope implements ScopeInterface {
4748 /** Severity */
4849 protected _level ?: Severity ;
4950
50- /** Transaction */
51- protected _transaction ?: string ;
51+ /** Transaction Name */
52+ protected _transactionName ?: string ;
5253
5354 /** Span */
5455 protected _span ?: Span ;
@@ -185,12 +186,20 @@ export class Scope implements ScopeInterface {
185186 /**
186187 * @inheritDoc
187188 */
188- public setTransaction ( transaction ?: string ) : this {
189- this . _transaction = transaction ;
189+ public setTransactionName ( name ?: string ) : this {
190+ this . _transactionName = name ;
190191 this . _notifyScopeListeners ( ) ;
191192 return this ;
192193 }
193194
195+ /**
196+ * Can be removed in major version.
197+ * @deprecated in favor of {@link this.setTransactionName}
198+ */
199+ public setTransaction ( name ?: string ) : this {
200+ return this . setTransactionName ( name ) ;
201+ }
202+
194203 /**
195204 * @inheritDoc
196205 */
@@ -210,13 +219,23 @@ export class Scope implements ScopeInterface {
210219 }
211220
212221 /**
213- * Internal getter for Span, used in Hub.
214- * @hidden
222+ * @inheritDoc
215223 */
216224 public getSpan ( ) : Span | undefined {
217225 return this . _span ;
218226 }
219227
228+ /**
229+ * @inheritDoc
230+ */
231+ public getTransaction ( ) : Transaction | undefined {
232+ const span = this . getSpan ( ) as Span & { spanRecorder : { spans : Span [ ] } } ;
233+ if ( span && span . spanRecorder && span . spanRecorder . spans [ 0 ] ) {
234+ return span . spanRecorder . spans [ 0 ] as Transaction ;
235+ }
236+ return undefined ;
237+ }
238+
220239 /**
221240 * Inherit values from the parent scope.
222241 * @param scope to clone.
@@ -231,7 +250,7 @@ export class Scope implements ScopeInterface {
231250 newScope . _user = scope . _user ;
232251 newScope . _level = scope . _level ;
233252 newScope . _span = scope . _span ;
234- newScope . _transaction = scope . _transaction ;
253+ newScope . _transactionName = scope . _transactionName ;
235254 newScope . _fingerprint = scope . _fingerprint ;
236255 newScope . _eventProcessors = [ ...scope . _eventProcessors ] ;
237256 }
@@ -294,7 +313,7 @@ export class Scope implements ScopeInterface {
294313 this . _user = { } ;
295314 this . _contexts = { } ;
296315 this . _level = undefined ;
297- this . _transaction = undefined ;
316+ this . _transactionName = undefined ;
298317 this . _fingerprint = undefined ;
299318 this . _span = undefined ;
300319 this . _notifyScopeListeners ( ) ;
@@ -374,8 +393,8 @@ export class Scope implements ScopeInterface {
374393 if ( this . _level ) {
375394 event . level = this . _level ;
376395 }
377- if ( this . _transaction ) {
378- event . transaction = this . _transaction ;
396+ if ( this . _transactionName ) {
397+ event . transaction = this . _transactionName ;
379398 }
380399 // We want to set the trace context for normal events only if there isn't already
381400 // a trace context on the event. There is a product feature in place where we link
0 commit comments