-
Notifications
You must be signed in to change notification settings - Fork 117
chore(contexts): Remove default-trace-ID option #5979
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
base: master
Are you sure you want to change the base?
Changes from all commits
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 |
|---|---|---|
|
|
@@ -23,7 +23,7 @@ use relay_event_schema::protocol::{ | |
| AsPair, Attributes, AutoInferSetting, ClientSdkInfo, Context, ContextInner, Contexts, | ||
| DebugImage, DeviceClass, Event, EventId, EventType, Exception, Headers, IpAddr, Level, | ||
| LogEntry, Measurement, Measurements, PerformanceScoreContext, ReplayContext, Request, Span, | ||
| SpanStatus, SpanV2, Tags, Timestamp, TraceContext, User, VALID_PLATFORMS, | ||
| SpanStatus, SpanV2, Tags, Timestamp, TraceContext, TraceId, User, VALID_PLATFORMS, | ||
| }; | ||
| use relay_protocol::{ | ||
| Annotated, Empty, Error, ErrorKind, FiniteF64, FromValue, Getter, Meta, Object, Remark, | ||
|
|
@@ -168,9 +168,6 @@ pub struct NormalizationConfig<'a> { | |
|
|
||
| /// Set a flag to enable performance issue detection on spans. | ||
| pub performance_issues_spans: bool, | ||
|
|
||
| /// Should add a random trace ID to events that lack one. | ||
| pub derive_trace_id: bool, | ||
|
Comment on lines
-172
to
-173
Member
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. I think we should keep this here, add some documentation why this is needed and then just permanently set it to Usually I'd agree with just by default enabling it, but there is a large impact on tests which are testing unrelated things but now need to assert a random trace id and context. We can still test the context creation with the boolean and have integration tests to ensure this actually is enabled. |
||
| } | ||
|
|
||
| impl Default for NormalizationConfig<'_> { | ||
|
|
@@ -205,7 +202,6 @@ impl Default for NormalizationConfig<'_> { | |
| span_allowed_hosts: Default::default(), | ||
| span_op_defaults: Default::default(), | ||
| performance_issues_spans: Default::default(), | ||
| derive_trace_id: Default::default(), | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -334,7 +330,7 @@ fn normalize(event: &mut Event, meta: &mut Meta, config: &NormalizationConfig) { | |
| let event_id = event.id.value().unwrap().0; | ||
|
|
||
| // Some contexts need to be normalized before metrics extraction takes place. | ||
| normalize_contexts(&mut event.contexts, event_id, config); | ||
| normalize_contexts(&mut event.contexts, event_id); | ||
|
|
||
| if config.normalize_spans && event.ty.value() == Some(&EventType::Transaction) { | ||
| crate::normalize::normalize_app_start_spans(event); | ||
|
|
@@ -1355,15 +1351,9 @@ fn remove_logger_word(tokens: &mut Vec<&str>) { | |
| } | ||
|
|
||
| /// Normalizes incoming contexts for the downstream metric extraction. | ||
| fn normalize_contexts( | ||
| contexts: &mut Annotated<Contexts>, | ||
| event_id: Uuid, | ||
| config: &NormalizationConfig, | ||
| ) { | ||
| if config.derive_trace_id { | ||
| // We will always need a TraceContext. | ||
| let _ = contexts.get_or_insert_with(Contexts::new); | ||
| } | ||
| fn normalize_contexts(contexts: &mut Annotated<Contexts>, event_id: Uuid) { | ||
| // We will always need a TraceContext. | ||
|
cursor[bot] marked this conversation as resolved.
|
||
| let _ = contexts.get_or_insert_with(Contexts::new); | ||
|
|
||
| let _ = processor::apply(contexts, |contexts, _meta| { | ||
| // Reprocessing context sent from SDKs must not be accepted, it is a Sentry-internal | ||
|
|
@@ -1374,8 +1364,13 @@ fn normalize_contexts( | |
| // We need a TraceId to ingest the event into EAP. | ||
| // If the event lacks a TraceContext, add a random one. | ||
|
|
||
| if config.derive_trace_id && !contexts.contains::<TraceContext>() { | ||
| if !contexts.contains::<TraceContext>() { | ||
|
Dav1dde marked this conversation as resolved.
Member
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. I think you could collapse this
Contributor
Author
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. So, there are four possible cases:
All this to say — what does
Member
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. I would say we should defer to @Dav1dde on the question of default span ID (whether or not that should be added, and where that should be added, or if it is already). But I think the code I attached above works for all of the cases in which trace ID needs to be populated (and additional if branches can be added if needed if there are other defaults we need to set)
Member
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. The more I look into this I begin to question whether this doesn't have a lot of unintentional side-effects.
The span_id is required on the context, that means if you want to generate a context it also needs to be filled with a span_id.
All attributes set to Annotated::empty() (practically None). There is an argument to be made, that it should not implement Default at all. |
||
| contexts.add(TraceContext::random(event_id)) | ||
|
Member
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. If there's a
Member
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.
If you want to make the trace context effectively required, instead we should add this marker to the context itself. |
||
| } else { | ||
| let trace_ctx = contexts.get_or_default::<TraceContext>(); | ||
| if trace_ctx.trace_id.0.is_none() { | ||
| trace_ctx.trace_id = Annotated::new(TraceId::from(event_id)) | ||
|
Member
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. Isn't this inconsistent with |
||
| } | ||
|
cursor[bot] marked this conversation as resolved.
|
||
| } | ||
|
Comment on lines
+1370
to
1374
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. Bug: If an event has an existing but empty Suggested FixIn the Prompt for AI Agent |
||
|
|
||
| for annotated in &mut contexts.0.values_mut() { | ||
|
|
@@ -4882,14 +4877,48 @@ mod tests { | |
| }, | ||
| ); | ||
|
|
||
| insta::assert_ron_snapshot!(SerializableAnnotated(&event.contexts), {}, @r###" | ||
| insta::assert_ron_snapshot!(SerializableAnnotated(&event.contexts), { | ||
| ".trace.trace_id" => "[trace-id]", | ||
| ".trace.span_id" => "[span-id]" | ||
| }, @r#" | ||
| { | ||
| "performance_score": { | ||
| "score_profile_version": "beta", | ||
| "type": "performancescore", | ||
| }, | ||
| "trace": { | ||
| "trace_id": "[trace-id]", | ||
| "span_id": "[span-id]", | ||
| "status": "unknown", | ||
| "exclusive_time": 5000.0, | ||
| "type": "trace", | ||
| }, | ||
| "_meta": { | ||
| "trace": { | ||
| "span_id": { | ||
| "": Meta(Some(MetaInner( | ||
| rem: [ | ||
| [ | ||
| "span_id.missing", | ||
| s, | ||
| ], | ||
| ], | ||
| ))), | ||
| }, | ||
| "trace_id": { | ||
| "": Meta(Some(MetaInner( | ||
| rem: [ | ||
| [ | ||
| "trace_id.missing", | ||
| s, | ||
| ], | ||
| ], | ||
| ))), | ||
| }, | ||
| }, | ||
| }, | ||
| } | ||
| "###); | ||
| "#); | ||
| insta::assert_ron_snapshot!(SerializableAnnotated(&event.measurements), {}, @r###" | ||
| { | ||
| "inp": { | ||
|
|
@@ -4958,7 +4987,6 @@ mod tests { | |
| &mut Meta::default(), | ||
| &NormalizationConfig { | ||
| performance_score: Some(&performance_score), | ||
| derive_trace_id: true, | ||
| ..Default::default() | ||
| }, | ||
| ); | ||
|
|
||
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.
Should we assert the fields contained in the trace context, e.g.
trace_idor other necessary fields are present?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.
Generally a good idea, but these are the Python library tests and this is a test for normalizing the user agent, so I think this is fine.