Skip to content
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

Merged
merged 6 commits into from
Oct 1, 2020
Merged

Conversation

kamilogorek
Copy link
Contributor

@kamilogorek kamilogorek requested a review from a team September 16, 2020 09:42
Copy link
Contributor

@rhcarvalho rhcarvalho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 (pending fixing CI)


Event:

{"contexts": {"custom": "value"}, ...}

image

@github-actions
Copy link
Contributor

github-actions bot commented Sep 29, 2020

size-limit report

Path Size
@sentry/browser - CDN Bundle (gzipped) 18.02 KB (+0.05% 🔺)
@sentry/browser - Webpack 18.83 KB (+0.06% 🔺)
@sentry/react - Webpack 18.83 KB (+0.06% 🔺)
@sentry/browser + @sentry/tracing - CDN Bundle (gzipped) 23.82 KB (+0.05% 🔺)

@@ -853,7 +853,7 @@ export class Tracing implements Integration {
Tracing._log(`[Tracing] Transaction: ${SpanStatus.Cancelled} since it maxed out maxTransactionDuration`);
if (event.contexts && event.contexts.trace) {
event.contexts.trace = {
...event.contexts.trace,
...(typeof event.contexts.trace === 'object' && event.contexts.trace),
Copy link
Contributor

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?

Copy link
Contributor Author

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 than any, and requires type check before it can be spread. On the other hand, it doesnt require unnecessary no-explcit-any linting rule.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

event.contexts.trace has type Context, it must be an object, mustn't it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

public setContext(key: string, context: Context | null): this {
if (context === null) {
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
delete this._contexts[key];
Copy link
Contributor

Choose a reason for hiding this comment

The 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?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From https://develop.sentry.dev/sdk/unified-api/
image

So now setting a context to null deletes it. Let's document this in the changelog.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was a bug, fixed.

@kamilogorek kamilogorek merged commit bb40f48 into master Oct 1, 2020
@kamilogorek kamilogorek deleted the context-type branch October 1, 2020 12:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants