Skip to content

feat(core): Ensure trace context only includes relevant data #11713

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

Merged
merged 3 commits into from
Apr 23, 2024

Conversation

mydea
Copy link
Member

@mydea mydea commented Apr 22, 2024

Today, we have different behavior for the trace context in core/browser & node:

In Node, we made the change so that contexts.trace only contains span_id, trace_id and parent_span_id for 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.

@mydea mydea requested review from Lms24 and AbhiPrasad April 22, 2024 09:43
@mydea mydea self-assigned this Apr 22, 2024
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);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I would be heavily in favor of creating a separate function instead of passing a flag.

ie

  • spanToTransactionTraceContext
  • spanToTraceContext

or similar

Copy link
Contributor

Choose a reason for hiding this comment

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

Reason being "includeAllData" is super undescriptive. What is not all data? Why would I use that?

Copy link
Member Author

Choose a reason for hiding this comment

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

sounds good to me! will update this.

Copy link
Contributor

github-actions bot commented Apr 22, 2024

size-limit report 📦

Path Size
@sentry/browser 21.65 KB (-0.1% 🔽)
@sentry/browser (incl. Tracing) 32.66 KB (+0.06% 🔺)
@sentry/browser (incl. Tracing, Replay) 67.93 KB (+0.01% 🔺)
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 61.34 KB (+0.02% 🔺)
@sentry/browser (incl. Tracing, Replay with Canvas) 71.94 KB (-0.01% 🔽)
@sentry/browser (incl. Tracing, Replay, Feedback) 84.17 KB (+0.02% 🔺)
@sentry/browser (incl. Feedback) 37.76 KB (-0.06% 🔽)
@sentry/browser (incl. sendFeedback) 26.43 KB (-0.08% 🔽)
@sentry/browser (incl. FeedbackAsync) 30.91 KB (-0.06% 🔽)
@sentry/react 24.33 KB (-0.1% 🔽)
@sentry/react (incl. Tracing) 35.56 KB (+0.05% 🔺)
@sentry/vue 25.26 KB (+0.05% 🔺)
@sentry/vue (incl. Tracing) 34.4 KB (+0.02% 🔺)
@sentry/svelte 21.77 KB (-0.08% 🔽)
CDN Bundle 23.95 KB (-0.09% 🔽)
CDN Bundle (incl. Tracing) 33.9 KB (+0.05% 🔺)
CDN Bundle (incl. Tracing, Replay) 67.46 KB (+0.04% 🔺)
CDN Bundle (incl. Tracing, Replay, Feedback) 83.25 KB (+0.02% 🔺)
CDN Bundle - uncompressed 70.56 KB (-0.09% 🔽)
CDN Bundle (incl. Tracing) - uncompressed 100.8 KB (+0.13% 🔺)
CDN Bundle (incl. Tracing, Replay) - uncompressed 210.24 KB (+0.07% 🔺)
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 256.56 KB (+0.06% 🔺)
@sentry/nextjs (client) 34.79 KB (+0.04% 🔺)
@sentry/sveltekit (client) 33.16 KB (+0.1% 🔺)
@sentry/node 152.84 KB (-0.02% 🔽)

@mydea mydea force-pushed the fn/trace-context branch from 4df32cd to 9d1af19 Compare April 23, 2024 07:39
@mydea mydea force-pushed the fn/trace-context branch from 9d1af19 to b35f4e5 Compare April 23, 2024 09:45
@mydea mydea merged commit 7de7dcc into develop Apr 23, 2024
97 checks passed
@mydea mydea deleted the fn/trace-context branch April 23, 2024 12:24
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.

3 participants