/**
 * Parts of code taken from: https://github.com/getsentry/sentry-javascript/blob/06d6bd87971b22dcaba99b03e1f885158c7dd66f/packages/hub/src/scope.ts
 */ import { Scope as SentryScope } from '@sentry/hub' ; import { Extra , Extras , Primitive , User } from '@sentry/types' ; import { Breadcrumb , Event } from './types' ; class SentryScopeAdapter extends SentryScope { param event applyToEventSync ( event ) { if ( this . _extra && Object . keys ( this . _extra ) . length ) { event . extra = { ... this . _extra , ... event . extra } ; } if ( this . _tags && Object . keys ( this . _tags ) . length ) { event . tags = { ... this . _tags , ... event . tags } ; } if ( this . _user && Object . keys ( this . _user ) . length ) { event . user = { ... this . _user , ... event . user } ; } event . fingerprint = [ ... ( event . fingerprint ?? [ ] ) , ... ( this . _fingerprint ?? [ ] ) , ] ; event . fingerprint = event . fingerprint . length > 0 ? event . fingerprint : undefined ; event . breadcrumbs = [ ... ( event . breadcrumbs ?? [ ] ) , ... ( this . _breadcrumbs ?? [ ] ) , ] ; event . breadcrumbs = event . breadcrumbs . length > 0 ? event . breadcrumbs : undefined ; return event ; } param scope static clone ( scope ? ) { const newScope = new SentryScopeAdapter ( ) ; if ( scope ) { newScope . _breadcrumbs = [ ... scope . _breadcrumbs ] ; newScope . _tags = { ... scope . _tags } ; newScope . _extra = { ... scope . _extra } ; newScope . _contexts = { ... scope . _contexts } ; newScope . _user = scope . _user ; newScope . _level = scope . _level ; newScope . _span = scope . _span ; newScope . _session = scope . _session ; newScope . _transactionName = scope . _transactionName ; newScope . _fingerprint = scope . _fingerprint ; newScope . _eventProcessors = [ ... scope . _eventProcessors ] ; } return newScope ; } } export class Scope { private adapter : SentryScopeAdapter ; constructor ( ) { this . adapter = new SentryScopeAdapter ( ) ; } param breadcrumb param maxBreadcrumbs addBreadcrumb ( breadcrumb , maxBreadcrumbs ? ) { return this . adapter . addBreadcrumb ( breadcrumb as any , maxBreadcrumbs ) ; } param key param value setTag ( key , value ) { this . adapter . setTag ( key , value ) ; } param tags setTags ( tags ) { this . adapter . setTags ( tags ) ; } param key param extra setExtra ( key , extra ) { this . adapter . setExtra ( key , extra ) ; } param extras setExtras ( extras ) { this . adapter . setExtras ( extras ) ; } param fingerprint setFingerprint ( fingerprint ) { this . adapter . setFingerprint ( fingerprint ) ; } param user setUser ( user ) { this . adapter . setUser ( user ) ; } param event applyToEvent ( event ) { return this . adapter . applyToEventSync ( event ) ; } param scope static clone ( scope ? ) { const newScope = new Scope ( ) ; if ( scope ) { newScope . adapter = SentryScopeAdapter . clone ( scope . adapter ) ; } return newScope ; } }