Skip to content

Commit 4befd67

Browse files
committed
Process and add span pointers to the Lambda execution span's meta under _dd.span_links
1 parent 2f7a0b1 commit 4befd67

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

bottlecap/src/lifecycle/invocation/processor.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,7 @@ impl Processor {
359359
header_tags,
360360
vec![traces],
361361
body_size,
362+
Some(self.inferrer.span_pointers.clone()),
362363
);
363364

364365
if let Err(e) = trace_agent_tx.send(send_data).await {

bottlecap/src/traces/trace_agent.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ impl TraceAgent {
258258
tracer_header_tags,
259259
traces,
260260
body_size,
261+
None,
261262
);
262263

263264
// send trace payload to our trace flusher

bottlecap/src/traces/trace_processor.rs

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ use datadog_trace_obfuscation::obfuscate::obfuscate_span;
2121
use datadog_trace_protobuf::pb::Span;
2222
use datadog_trace_utils::trace_utils::SendData;
2323
use datadog_trace_utils::trace_utils::{self};
24+
use serde_json::{json, Value};
25+
use crate::span_pointers::SpanPointer;
2426

2527
#[derive(Clone)]
2628
#[allow(clippy::module_name_repetitions)]
@@ -32,6 +34,7 @@ pub struct ServerlessTraceProcessor {
3234
struct ChunkProcessor {
3335
obfuscation_config: Arc<obfuscation_config::ObfuscationConfig>,
3436
tags_provider: Arc<provider::Provider>,
37+
span_pointers: Option<Vec<SpanPointer>>,
3538
}
3639

3740
impl TraceChunkProcessor for ChunkProcessor {
@@ -48,6 +51,32 @@ impl TraceChunkProcessor for ChunkProcessor {
4851
}
4952
}
5053

54+
if span.name == "aws.lambda" {
55+
if let Some(span_pointers) = &self.span_pointers {
56+
if !span_pointers.is_empty() {
57+
let span_links: Vec<Value> = span_pointers
58+
.iter()
59+
.map(|sp| {
60+
json!({
61+
"attributes": {
62+
"link.kind": "span-pointer",
63+
"ptr.dir": "u",
64+
"ptr.hash": sp.hash,
65+
"ptr.kind": sp.kind,
66+
},
67+
"span_id": "0",
68+
"trace_id": "0"
69+
})
70+
})
71+
.collect();
72+
73+
if let Ok(span_links_json) = serde_json::to_string(&span_links) {
74+
span.meta.insert("_dd.span_links".to_string(), span_links_json);
75+
}
76+
}
77+
}
78+
}
79+
5180
self.tags_provider.get_tags_map().iter().for_each(|(k, v)| {
5281
span.meta.insert(k.clone(), v.clone());
5382
});
@@ -116,6 +145,7 @@ pub trait TraceProcessor {
116145
header_tags: tracer_header_tags::TracerHeaderTags,
117146
traces: Vec<Vec<pb::Span>>,
118147
body_size: usize,
148+
span_pointers: Option<Vec<SpanPointer>>,
119149
) -> SendData;
120150
}
121151

@@ -127,13 +157,15 @@ impl TraceProcessor for ServerlessTraceProcessor {
127157
header_tags: tracer_header_tags::TracerHeaderTags,
128158
traces: Vec<Vec<pb::Span>>,
129159
body_size: usize,
160+
span_pointers: Option<Vec<SpanPointer>>,
130161
) -> SendData {
131162
let payload = trace_utils::collect_trace_chunks(
132163
V07(traces),
133164
&header_tags,
134165
&mut ChunkProcessor {
135166
obfuscation_config: self.obfuscation_config.clone(),
136167
tags_provider: tags_provider.clone(),
168+
span_pointers,
137169
},
138170
true,
139171
);
@@ -270,7 +302,7 @@ mod tests {
270302
let config = create_test_config();
271303
let tags_provider = create_tags_provider(config.clone());
272304
let tracer_payload =
273-
trace_processor.process_traces(config, tags_provider.clone(), header_tags, traces, 100);
305+
trace_processor.process_traces(config, tags_provider.clone(), header_tags, traces, 100, None);
274306

275307
let expected_tracer_payload = pb::TracerPayload {
276308
container_id: "33".to_string(),

0 commit comments

Comments
 (0)