-
Notifications
You must be signed in to change notification settings - Fork 17
[APMSVLS-197] Add check to extract trace context present within event.request.headers #1011
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
Changes from all commits
e677d7e
50ae32f
87af0a4
3ef4752
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 |
|---|---|---|
|
|
@@ -1076,6 +1076,15 @@ impl Processor { | |
| return Some(sc); | ||
| } | ||
|
|
||
| if let Some(sc) = payload_value | ||
| .get("request") | ||
| .and_then(|req| req.get("headers")) | ||
| .and_then(|headers| propagator.extract(headers)) | ||
| { | ||
| debug!("Extracted trace context from event.request.headers"); | ||
| return Some(sc); | ||
| } | ||
|
|
||
| if let Some(payload_headers) = payload_value.get("headers") { | ||
| if let Some(sc) = propagator.extract(payload_headers) { | ||
| debug!("Extracted trace context from event headers"); | ||
|
|
@@ -1851,4 +1860,71 @@ mod tests { | |
| "Should be snapstart span (id=3), not cold start span (id=2)" | ||
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_extract_span_context_priority_order() { | ||
| let config = Arc::new(config::Config { | ||
| trace_propagation_style_extract: vec![ | ||
| config::trace_propagation_style::TracePropagationStyle::Datadog, | ||
| config::trace_propagation_style::TracePropagationStyle::TraceContext, | ||
| ], | ||
| ..config::Config::default() | ||
| }); | ||
| let propagator = Arc::new(DatadogCompositePropagator::new(Arc::clone(&config))); | ||
|
|
||
| let mut headers = HashMap::new(); | ||
| headers.insert(DATADOG_TRACE_ID_KEY.to_string(), "111".to_string()); | ||
| headers.insert(DATADOG_PARENT_ID_KEY.to_string(), "222".to_string()); | ||
|
|
||
| let payload = json!({ | ||
| "headers": { | ||
| "x-datadog-trace-id": "333", | ||
| "x-datadog-parent-id": "444" | ||
| }, | ||
| "request": { | ||
| "headers": { | ||
| "x-datadog-trace-id": "555", | ||
| "x-datadog-parent-id": "666" | ||
| } | ||
| } | ||
| }); | ||
|
|
||
| let result = Processor::extract_span_context(&headers, &payload, propagator); | ||
|
|
||
| assert!(result.is_some()); | ||
| let context = result.unwrap(); | ||
| assert_eq!( | ||
| context.trace_id, 555, | ||
| "Should prioritize event.request.headers as service-specific extraction" | ||
|
Comment on lines
+1897
to
+1898
|
||
| ); | ||
|
Comment on lines
+1896
to
+1899
|
||
| } | ||
|
|
||
| #[test] | ||
| fn test_extract_span_context_no_request_headers() { | ||
| let config = Arc::new(config::Config { | ||
| trace_propagation_style_extract: vec![ | ||
| config::trace_propagation_style::TracePropagationStyle::Datadog, | ||
| config::trace_propagation_style::TracePropagationStyle::TraceContext, | ||
| ], | ||
| ..config::Config::default() | ||
| }); | ||
| let propagator = Arc::new(DatadogCompositePropagator::new(Arc::clone(&config))); | ||
| let headers = HashMap::new(); | ||
|
|
||
| let payload = json!({ | ||
| "argumentsMap": { | ||
| "id": "123" | ||
| }, | ||
| "request": { | ||
| "body": "some body" | ||
| } | ||
| }); | ||
|
|
||
| let result = Processor::extract_span_context(&headers, &payload, propagator); | ||
|
|
||
| assert!( | ||
| result.is_none(), | ||
| "Should return None when no trace context found" | ||
| ); | ||
| } | ||
| } | ||
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.
Could you add some unit testing and show an example trace in the PR description? Just to see what were we missing