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 2
2
import {
3
3
Breadcrumb ,
4
4
CaptureContext ,
5
+ Context ,
6
+ Contexts ,
5
7
Event ,
6
8
EventHint ,
7
9
EventProcessor ,
@@ -40,12 +42,10 @@ export class Scope implements ScopeInterface {
40
42
protected _tags : { [ key : string ] : string } = { } ;
41
43
42
44
/** Extra */
43
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
44
- protected _extra : { [ key : string ] : any } = { } ;
45
+ protected _extra : Extras = { } ;
45
46
46
47
/** Contexts */
47
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
48
- protected _contexts : { [ key : string ] : any } = { } ;
48
+ protected _contexts : Contexts = { } ;
49
49
50
50
/** Fingerprint */
51
51
protected _fingerprint ?: string [ ] ;
@@ -185,9 +185,14 @@ export class Scope implements ScopeInterface {
185
185
/**
186
186
* @inheritDoc
187
187
*/
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
+
191
196
this . _notifyScopeListeners ( ) ;
192
197
return this ;
193
198
}
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 1
1
import { Breadcrumb } from './breadcrumb' ;
2
+ import { Contexts } from './context' ;
2
3
import { Exception } from './exception' ;
4
+ import { Extras } from './extra' ;
3
5
import { Request } from './request' ;
4
6
import { CaptureContext } from './scope' ;
5
7
import { SdkInfo } from './sdkinfo' ;
@@ -31,11 +33,9 @@ export interface Event {
31
33
} ;
32
34
stacktrace ?: Stacktrace ;
33
35
breadcrumbs ?: Breadcrumb [ ] ;
34
- contexts ?: {
35
- [ key : string ] : Record < any , any > ;
36
- } ;
36
+ contexts ?: Contexts ;
37
37
tags ?: { [ key : string ] : string } ;
38
- extra ?: { [ key : string ] : any } ;
38
+ extra ?: Extras ;
39
39
user ?: User ;
40
40
type ?: EventType ;
41
41
spans ?: Span [ ] ;
Original file line number Diff line number Diff line change 1
1
export { Breadcrumb , BreadcrumbHint } from './breadcrumb' ;
2
2
export { Client } from './client' ;
3
+ export { Context , Contexts } from './context' ;
3
4
export { Dsn , DsnComponents , DsnLike , DsnProtocol } from './dsn' ;
4
5
export { ExtendedError } from './error' ;
5
6
export { Event , EventHint } from './event' ;
Original file line number Diff line number Diff line change 1
1
import { Breadcrumb } from './breadcrumb' ;
2
+ import { Context , Contexts } from './context' ;
2
3
import { EventProcessor } from './eventprocessor' ;
3
4
import { Extra , Extras } from './extra' ;
4
5
import { Severity } from './severity' ;
@@ -13,8 +14,8 @@ export type CaptureContext = Scope | Partial<ScopeContext> | ((scope: Scope) =>
13
14
export interface ScopeContext {
14
15
user : User ;
15
16
level : Severity ;
16
- extra : { [ key : string ] : any } ;
17
- contexts : { [ key : string ] : any } ;
17
+ extra : Extras ;
18
+ contexts : Contexts ;
18
19
tags : { [ key : string ] : string } ;
19
20
fingerprint : string [ ] ;
20
21
}
@@ -80,9 +81,9 @@ export interface Scope {
80
81
/**
81
82
* Sets context data with the given name.
82
83
* @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 .
84
85
*/
85
- setContext ( name : string , context : { [ key : string ] : any } | null ) : this;
86
+ setContext ( name : string , context : Context | null ) : this;
86
87
87
88
/**
88
89
* Sets the Span on the scope.
You can’t perform that action at this time.
0 commit comments