feat(core): Ensure trace context only includes relevant data#11713
Merged
feat(core): Ensure trace context only includes relevant data#11713
Conversation
lforst
reviewed
Apr 22, 2024
packages/core/src/utils/spanUtils.ts
Outdated
Comment on lines
37
to
60
| export function spanToTraceContext(span: Span, includeAllData = false): TraceContext { | ||
| const { spanId: span_id, traceId: trace_id } = span.spanContext(); | ||
| const { data, op, parent_span_id, status, origin } = spanToJSON(span); | ||
|
|
||
| return dropUndefinedKeys({ | ||
| data, | ||
| op, | ||
| parent_span_id, | ||
| span_id, | ||
| status, | ||
| trace_id, | ||
| origin, | ||
| }); | ||
| const reqFields = { parent_span_id, span_id, trace_id }; | ||
| // These are only included if `includeAllData` is true | ||
| const optFields = { data, op, status, origin }; | ||
|
|
||
| return dropUndefinedKeys(includeAllData ? { ...reqFields, ...optFields } : reqFields); | ||
| } |
Contributor
There was a problem hiding this comment.
I would be heavily in favor of creating a separate function instead of passing a flag.
ie
- spanToTransactionTraceContext
- spanToTraceContext
or similar
Contributor
There was a problem hiding this comment.
Reason being "includeAllData" is super undescriptive. What is not all data? Why would I use that?
Member
Author
There was a problem hiding this comment.
sounds good to me! will update this.
Contributor
size-limit report 📦
|
lforst
approved these changes
Apr 23, 2024
Lms24
approved these changes
Apr 23, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Today, we have different behavior for the
tracecontext in core/browser & node:In Node, we made the change so that
contexts.traceonly containsspan_id,trace_idandparent_span_idfor non-transaction events.In contrast, in core/browser we are always adding the full span trace context, if there is an active span (including e.g. data, status, etc.)
This PR aligns this to use the node behavior everywhere.
Transaction events are unchanged by this PR.