File tree Expand file tree Collapse file tree 5 files changed +24
-15
lines changed Expand file tree Collapse file tree 5 files changed +24
-15
lines changed Original file line number Diff line number Diff line change 22import {
33 Breadcrumb ,
44 CaptureContext ,
5+ Context ,
6+ Contexts ,
57 Event ,
68 EventHint ,
79 EventProcessor ,
@@ -40,12 +42,10 @@ export class Scope implements ScopeInterface {
4042 protected _tags : { [ key : string ] : string } = { } ;
4143
4244 /** Extra */
43- // eslint-disable-next-line @typescript-eslint/no-explicit-any
44- protected _extra : { [ key : string ] : any } = { } ;
45+ protected _extra : Extras = { } ;
4546
4647 /** Contexts */
47- // eslint-disable-next-line @typescript-eslint/no-explicit-any
48- protected _contexts : { [ key : string ] : any } = { } ;
48+ protected _contexts : Contexts = { } ;
4949
5050 /** Fingerprint */
5151 protected _fingerprint ?: string [ ] ;
@@ -185,9 +185,14 @@ export class Scope implements ScopeInterface {
185185 /**
186186 * @inheritDoc
187187 */
188- // eslint-disable-next-line @typescript-eslint/no-explicit-any
189- public setContext ( key : string , context : { [ key : string ] : any } | null ) : this {
190- this . _contexts = { ...this . _contexts , [ key ] : context } ;
188+ public setContext ( key : string , context : Context | null ) : this {
189+ if ( context === null ) {
190+ // eslint-disable-next-line @typescript-eslint/no-dynamic-delete
191+ delete this . _contexts [ key ] ;
192+ } else {
193+ this . _contexts = { ...this . _contexts , [ key ] : context } ;
194+ }
195+
191196 this . _notifyScopeListeners ( ) ;
192197 return this ;
193198 }
Original file line number Diff line number Diff line change 1+ export type Context = Record < string , unknown > ;
2+ export type Contexts = Record < string , Context > ;
Original file line number Diff line number Diff line change 11import { Breadcrumb } from './breadcrumb' ;
2+ import { Contexts } from './context' ;
23import { Exception } from './exception' ;
4+ import { Extras } from './extra' ;
35import { Request } from './request' ;
46import { CaptureContext } from './scope' ;
57import { SdkInfo } from './sdkinfo' ;
@@ -31,11 +33,9 @@ export interface Event {
3133 } ;
3234 stacktrace ?: Stacktrace ;
3335 breadcrumbs ?: Breadcrumb [ ] ;
34- contexts ?: {
35- [ key : string ] : Record < any , any > ;
36- } ;
36+ contexts ?: Contexts ;
3737 tags ?: { [ key : string ] : string } ;
38- extra ?: { [ key : string ] : any } ;
38+ extra ?: Extras ;
3939 user ?: User ;
4040 type ?: EventType ;
4141 spans ?: Span [ ] ;
Original file line number Diff line number Diff line change 11export { Breadcrumb , BreadcrumbHint } from './breadcrumb' ;
22export { Client } from './client' ;
3+ export { Context , Contexts } from './context' ;
34export { Dsn , DsnComponents , DsnLike , DsnProtocol } from './dsn' ;
45export { ExtendedError } from './error' ;
56export { Event , EventHint } from './event' ;
Original file line number Diff line number Diff line change 11import { Breadcrumb } from './breadcrumb' ;
2+ import { Context , Contexts } from './context' ;
23import { EventProcessor } from './eventprocessor' ;
34import { Extra , Extras } from './extra' ;
45import { Severity } from './severity' ;
@@ -13,8 +14,8 @@ export type CaptureContext = Scope | Partial<ScopeContext> | ((scope: Scope) =>
1314export interface ScopeContext {
1415 user : User ;
1516 level : Severity ;
16- extra : { [ key : string ] : any } ;
17- contexts : { [ key : string ] : any } ;
17+ extra : Extras ;
18+ contexts : Contexts ;
1819 tags : { [ key : string ] : string } ;
1920 fingerprint : string [ ] ;
2021}
@@ -80,9 +81,9 @@ export interface Scope {
8081 /**
8182 * Sets context data with the given name.
8283 * @param name of the context
83- * @param context Any kind of data. This data will be normailzed.
84+ * @param context an object containing context data. This data will be normailzed. Pass `null` to unset the context .
8485 */
85- setContext ( name : string , context : { [ key : string ] : any } | null ) : this;
86+ setContext ( name : string , context : Context | null ) : this;
8687
8788 /**
8889 * Sets the Span on the scope.
You can’t perform that action at this time.
0 commit comments