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

feat: Remove normalization of contexts #2649

Closed
wants to merge 3 commits into from

Conversation

rhcarvalho
Copy link
Contributor

All of the context types documented in 1 are flat objects.

The more recent addition contexts.trace is the only context type that
may have nested objects under contexts.trace.data. That value holds the
data for the Transaction Span and matches spans[].data for invidual
Spans.

Removing normalization is one solution to the inconsistency in which
data in Transactions is heavily limited, while data in Span is ignored
by normalization.

This is the simplest to implement fix to #2646, thus what we implement
here to evaluate. We expect that no other key under contexts will be
affected negatively by this change.

Fixes #2646

All of the context types documented in [1] are flat objects.

The more recent addition contexts.trace is the only context type that
may have nested objects under contexts.trace.data. That value holds the
data for the Transaction Span and matches spans[].data for invidual
Spans.

Removing normalization is one solution to the inconsistency in which
data in Transactions is heavily limited, while data in Span is ignored
by normalization.

This is the simplest to implement fix to #2646, thus what we implement
here to evaluate. We expect that no other key under contexts will be
affected negatively by this change.

[1]: https://develop.sentry.dev/sdk/event-payloads/contexts/

Fixes #2646
@getsentry-bot
Copy link
Contributor

getsentry-bot commented Jun 5, 2020

Messages
📖

@sentry/browser bundle gzip'ed minified size: (ES5: 17.001 kB) (ES6: 16.0479 kB)

📖 ✅ TSLint passed

Generated by 🚫 dangerJS against 71b2ad3

@rhcarvalho
Copy link
Contributor Author

Talking to @bruno-garcia about a different subject, I learned that historically Event.contexts may have also been used (or might still be used today) to store arbitrary data, similar to Event.extra.

In that case, if this possibility is used in the wild in JS, we could have undesirable side effects.

I'd like to think this through in the light of the new learning.


normalizeDepth and the normalize function may indirectly shrink nested objects by converting potentially large object trees into a string like "[Object]", but it doesn't prevent people from replacing their deeply nested objects with long JSON strings by doing JSON.stringify(originalValue), which retains the large payload while making it less useful because of double JSON encoding.

/**
* normalize()
*
* - Creates a copy to prevent original input mutation
* - Skip non-enumerablers
* - Calls `toJSON` if implemented
* - Removes circular references
* - Translates non-serializeable values (undefined/NaN/Functions) to serializable format
* - Translates known global objects/Classes to a string representations
* - Takes care of Error objects serialization
* - Optionally limit depth of final output
*/
export function normalize(input: any, depth?: number): any {
try {
// tslint:disable-next-line:no-unsafe-any
return JSON.parse(JSON.stringify(input, (key: string, value: any) => walk(key, value, depth)));
} catch (_oO) {
return '**non-serializable**';
}
}


And alternative I'd like to consider is to do normalize all of Event.contexts, but then overwrite Event.contexts.trace with the original non-normalized value. That seems to be the path of least harm.

@rhcarvalho
Copy link
Contributor Author

The documentation for scope.setContext corroborates the idea that event.contexts is used as a bag of arbitrary data: https://docs.sentry.io/platforms/javascript/#extra-context

image

@rhcarvalho
Copy link
Contributor Author

Given my last two comments, I'm closing this in favor of #2655.

@rhcarvalho rhcarvalho closed this Jun 8, 2020
@rhcarvalho rhcarvalho deleted the rhcarvalho/no-normalize-contexts branch June 8, 2020 11:32
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.

Inconsistent normalization of Transaction/Span data
3 participants