@@ -15,6 +15,7 @@ import type {
1515 RequestSession ,
1616 Scope as ScopeInterface ,
1717 ScopeContext ,
18+ ScopeData ,
1819 Session ,
1920 Severity ,
2021 SeverityLevel ,
@@ -26,6 +27,7 @@ import { arrayify, dateTimestampInSeconds, isPlainObject, uuid4 } from '@sentry/
2627
2728import { getGlobalEventProcessors , notifyEventProcessors } from './eventProcessors' ;
2829import { updateSession } from './session' ;
30+ import { applyScopeDataToEvent } from './utils/applyScopeDataToEvent' ;
2931
3032/**
3133 * Default value for maximum number of breadcrumbs added to an event.
@@ -466,78 +468,65 @@ export class Scope implements ScopeInterface {
466468 return this ;
467469 }
468470
471+ /** @inheritDoc */
472+ public getScopeData ( ) : ScopeData {
473+ const {
474+ _breadcrumbs,
475+ _attachments,
476+ _contexts,
477+ _tags,
478+ _extra,
479+ _user,
480+ _level,
481+ _fingerprint,
482+ _eventProcessors,
483+ _propagationContext,
484+ _sdkProcessingMetadata,
485+ _transactionName,
486+ _span,
487+ } = this ;
488+
489+ return {
490+ breadcrumbs : _breadcrumbs ,
491+ attachments : _attachments ,
492+ contexts : _contexts ,
493+ tags : _tags ,
494+ extra : _extra ,
495+ user : _user ,
496+ level : _level ,
497+ fingerprint : _fingerprint || [ ] ,
498+ eventProcessors : _eventProcessors ,
499+ propagationContext : _propagationContext ,
500+ sdkProcessingMetadata : _sdkProcessingMetadata ,
501+ transactionName : _transactionName ,
502+ span : _span ,
503+ } ;
504+ }
505+
469506 /**
470507 * Applies data from the scope to the event and runs all event processors on it.
471508 *
472509 * @param event Event
473510 * @param hint Object containing additional information about the original exception, for use by the event processors.
474511 * @hidden
512+ * @deprecated Use `applyScopeDataToEvent()` directly
475513 */
476514 public applyToEvent (
477515 event : Event ,
478516 hint : EventHint = { } ,
479- additionalEventProcessors ? : EventProcessor [ ] ,
517+ additionalEventProcessors : EventProcessor [ ] = [ ] ,
480518 ) : PromiseLike < Event | null > {
481- if ( this . _extra && Object . keys ( this . _extra ) . length ) {
482- event . extra = { ...this . _extra , ...event . extra } ;
483- }
484- if ( this . _tags && Object . keys ( this . _tags ) . length ) {
485- event . tags = { ...this . _tags , ...event . tags } ;
486- }
487- if ( this . _user && Object . keys ( this . _user ) . length ) {
488- event . user = { ...this . _user , ...event . user } ;
489- }
490- if ( this . _contexts && Object . keys ( this . _contexts ) . length ) {
491- event . contexts = { ...this . _contexts , ...event . contexts } ;
492- }
493- if ( this . _level ) {
494- event . level = this . _level ;
495- }
496- if ( this . _transactionName ) {
497- event . transaction = this . _transactionName ;
498- }
499-
500- // We want to set the trace context for normal events only if there isn't already
501- // a trace context on the event. There is a product feature in place where we link
502- // errors with transaction and it relies on that.
503- if ( this . _span ) {
504- event . contexts = { trace : this . _span . getTraceContext ( ) , ...event . contexts } ;
505- const transaction = this . _span . transaction ;
506- if ( transaction ) {
507- event . sdkProcessingMetadata = {
508- dynamicSamplingContext : transaction . getDynamicSamplingContext ( ) ,
509- ...event . sdkProcessingMetadata ,
510- } ;
511- const transactionName = transaction . name ;
512- if ( transactionName ) {
513- event . tags = { transaction : transactionName , ...event . tags } ;
514- }
515- }
516- }
517-
518- this . _applyFingerprint ( event ) ;
519-
520- const scopeBreadcrumbs = this . _getBreadcrumbs ( ) ;
521- const breadcrumbs = [ ...( event . breadcrumbs || [ ] ) , ...scopeBreadcrumbs ] ;
522- event . breadcrumbs = breadcrumbs . length > 0 ? breadcrumbs : undefined ;
523-
524- event . sdkProcessingMetadata = {
525- ...event . sdkProcessingMetadata ,
526- ...this . _sdkProcessingMetadata ,
527- propagationContext : this . _propagationContext ,
528- } ;
519+ applyScopeDataToEvent ( event , this . getScopeData ( ) ) ;
529520
530521 // TODO (v8): Update this order to be: Global > Client > Scope
531- return notifyEventProcessors (
532- [
533- ...( additionalEventProcessors || [ ] ) ,
534- // eslint-disable-next-line deprecation/deprecation
535- ...getGlobalEventProcessors ( ) ,
536- ...this . _eventProcessors ,
537- ] ,
538- event ,
539- hint ,
540- ) ;
522+ const eventProcessors : EventProcessor [ ] = [
523+ ...additionalEventProcessors ,
524+ // eslint-disable-next-line deprecation/deprecation
525+ ...getGlobalEventProcessors ( ) ,
526+ ...this . _eventProcessors ,
527+ ] ;
528+
529+ return notifyEventProcessors ( eventProcessors , event , hint ) ;
541530 }
542531
543532 /**
@@ -564,13 +553,6 @@ export class Scope implements ScopeInterface {
564553 return this . _propagationContext ;
565554 }
566555
567- /**
568- * Get the breadcrumbs for this scope.
569- */
570- protected _getBreadcrumbs ( ) : Breadcrumb [ ] {
571- return this . _breadcrumbs ;
572- }
573-
574556 /**
575557 * This will be called on every set call.
576558 */
@@ -586,25 +568,6 @@ export class Scope implements ScopeInterface {
586568 this . _notifyingListeners = false ;
587569 }
588570 }
589-
590- /**
591- * Applies fingerprint from the scope to the event if there's one,
592- * uses message if there's one instead or get rid of empty fingerprint
593- */
594- private _applyFingerprint ( event : Event ) : void {
595- // Make sure it's an array first and we actually have something in place
596- event . fingerprint = event . fingerprint ? arrayify ( event . fingerprint ) : [ ] ;
597-
598- // If we have something on the scope, then merge it with event
599- if ( this . _fingerprint ) {
600- event . fingerprint = event . fingerprint . concat ( this . _fingerprint ) ;
601- }
602-
603- // If we have no data at all, remove empty array default
604- if ( event . fingerprint && ! event . fingerprint . length ) {
605- delete event . fingerprint ;
606- }
607- }
608571}
609572
610573function generatePropagationContext ( ) : PropagationContext {
0 commit comments