-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Use correct types for event context data #2910
Changes from 3 commits
150f7f2
9fc9d6d
56e2c62
1c2472a
4236dce
166d1dd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,8 @@ | |
import { | ||
Breadcrumb, | ||
CaptureContext, | ||
Context, | ||
Contexts, | ||
Event, | ||
EventHint, | ||
EventProcessor, | ||
|
@@ -40,12 +42,10 @@ export class Scope implements ScopeInterface { | |
protected _tags: { [key: string]: string } = {}; | ||
|
||
/** Extra */ | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
protected _extra: { [key: string]: any } = {}; | ||
protected _extra: Extras = {}; | ||
|
||
/** Contexts */ | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
protected _contexts: { [key: string]: any } = {}; | ||
protected _contexts: Contexts = {}; | ||
|
||
/** Fingerprint */ | ||
protected _fingerprint?: string[]; | ||
|
@@ -185,9 +185,14 @@ export class Scope implements ScopeInterface { | |
/** | ||
* @inheritDoc | ||
*/ | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
public setContext(key: string, context: { [key: string]: any } | null): this { | ||
this._contexts = { ...this._contexts, [key]: context }; | ||
public setContext(key: string, context: Context | null): this { | ||
if (context === null) { | ||
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete | ||
delete this._contexts[key]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm this is more than changing the types, would the previous code delete keys?! Was this a bug? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From https://develop.sentry.dev/sdk/unified-api/ So now setting a context to null deletes it. Let's document this in the changelog. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Was a bug, fixed. |
||
} else { | ||
this._contexts = { ...this._contexts, [key]: context }; | ||
} | ||
|
||
this._notifyScopeListeners(); | ||
return this; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export type Context = unknown; | ||
kamilogorek marked this conversation as resolved.
Show resolved
Hide resolved
|
||
export type Contexts = Record<string, Context>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we now do a type check here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because
unknown
is more restrictive thanany
, and requires type check before it can be spread. On the other hand, it doesnt require unnecessaryno-explcit-any
linting rule.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
event.contexts.trace
has typeContext
, it must be an object, mustn't it?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed