Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
428bb0f
Create span pointers helpers
nhulston Dec 26, 2024
cd34f67
Add span_pointers field to `SpanInferrer` and create default implemen…
nhulston Dec 26, 2024
c643dca
Implement `get_span_pointers` for S3 and add span pointers to the `Sp…
nhulston Dec 26, 2024
6185643
Process and add span pointers to the Lambda execution span's meta und…
nhulston Dec 26, 2024
3ae4fd9
lint
nhulston Dec 26, 2024
d4922c4
unit tests for `generate_span_pointer_hash`
nhulston Dec 26, 2024
0f2a069
unit tests for S3's `get_span_pointers` implementation
nhulston Dec 26, 2024
1553895
unit tests for span link processing in `trace_processor.rs`
nhulston Dec 26, 2024
6ff8cf1
Merge branch 'main' into nicholas.hulston/s3-downstream-span-pointers
nhulston Jan 8, 2025
7efa1b0
move span pointers helper
nhulston Jan 9, 2025
96d4cbe
update imports
nhulston Jan 9, 2025
d1d63ec
Make `span_pointers` in span_inferrer.rs an Option
nhulston Jan 9, 2025
7e4a8df
Add some important comments & avoid magic number
nhulston Jan 9, 2025
a1b9ecb
Remove `get_span_pointers` from the `Trigger` interface and create it…
nhulston Jan 9, 2025
94a506e
add license
nhulston Jan 9, 2025
6bad4e3
Move the logic for adding span links to span meta to spanpointers.rs
nhulston Jan 9, 2025
d43d356
Rename spanpointers.rs to span_pointers.rs
nhulston Jan 9, 2025
facdb78
lint; reduce diff
nhulston Jan 9, 2025
8c8eef5
update 3rd party license
nhulston Jan 9, 2025
650e2b4
simplify Option assignment
nhulston Jan 10, 2025
c3e1280
set span pointer on root span rather than searching for aws.lambda span
nhulston Jan 10, 2025
f7f65e4
extract `Some(span_pointers)` check to `attach_span_pointers_to_meta`…
nhulston Jan 10, 2025
e0ce3c0
use SpanLink struct from libdatadog trace-protobuf instead of manuall…
nhulston Jan 10, 2025
b42544d
fix format
nhulston Jan 10, 2025
9071b08
refactor attach_span_pointers_to_meta
nhulston Jan 10, 2025
d5cf718
one liner improvement to attach_span_pointers_to_meta
nhulston Jan 13, 2025
89ed8a9
append span links instead of replacing
nhulston Jan 13, 2025
95bd0a4
add test for existing span links
nhulston Jan 13, 2025
eefaa85
Update `test_attach_span_pointers_to_span` existing links test to hav…
nhulston Jan 14, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion bottlecap/LICENSE-3rdparty.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,19 @@ third_party_libraries:
license: 0BSD OR MIT OR Apache-2.0
licenses:
- license: 0BSD
text: NOT FOUND
text: |
Copyright (C) Jonas Schievink <[email protected]>

Permission to use, copy, modify, and/or distribute this software for
any purpose with or without fee is hereby granted.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
Copy link
Contributor

Choose a reason for hiding this comment

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

This change seems important enough to me to warrant its own PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

cc @duncanista
He said he knows the issue and it's fine to keep it in this PR

- license: MIT
text: |
Permission is hereby granted, free of charge, to any
Expand Down
1 change: 1 addition & 0 deletions bottlecap/src/lifecycle/invocation/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,7 @@ impl Processor {
header_tags,
vec![traces],
body_size,
self.inferrer.span_pointers.clone(),
);

if let Err(e) = trace_agent_tx.send(send_data).await {
Expand Down
5 changes: 5 additions & 0 deletions bottlecap/src/lifecycle/invocation/span_inferrer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use crate::lifecycle::invocation::{
Trigger, FUNCTION_TRIGGER_EVENT_SOURCE_ARN_TAG,
},
};
use crate::traces::span_pointers::SpanPointer;
use crate::traces::{context::SpanContext, propagation::Propagator};

#[derive(Default)]
Expand All @@ -39,6 +40,8 @@ pub struct SpanInferrer {
generated_span_context: Option<SpanContext>,
// Tags generated from the trigger
trigger_tags: Option<HashMap<String, String>>,
// Span pointers from S3 or DynamoDB streams
pub span_pointers: Option<Vec<SpanPointer>>,
}

impl SpanInferrer {
Expand All @@ -52,6 +55,7 @@ impl SpanInferrer {
carrier: None,
generated_span_context: None,
trigger_tags: None,
span_pointers: None,
}
}

Expand Down Expand Up @@ -178,6 +182,7 @@ impl SpanInferrer {
} else if S3Record::is_match(payload_value) {
if let Some(t) = S3Record::new(payload_value.clone()) {
t.enrich_span(&mut inferred_span, &self.service_mapping);
self.span_pointers = t.get_span_pointers();

trigger = Some(Box::new(t));
}
Expand Down
70 changes: 70 additions & 0 deletions bottlecap/src/lifecycle/invocation/triggers/s3_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use crate::lifecycle::invocation::{
processor::MS_TO_NS,
triggers::{ServiceNameResolver, Trigger, FUNCTION_TRIGGER_EVENT_SOURCE_TAG},
};
use crate::traces::span_pointers::{generate_span_pointer_hash, SpanPointer};

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct S3Event {
Expand Down Expand Up @@ -133,6 +134,28 @@ impl ServiceNameResolver for S3Record {
}
}

impl S3Record {
pub fn get_span_pointers(&self) -> Option<Vec<SpanPointer>> {
let bucket_name = &self.s3.bucket.name;
let key = &self.s3.object.key;
// The AWS SDK sometimes wraps the S3 eTag in quotes, but sometimes doesn't.
let e_tag = self.s3.object.e_tag.trim_matches('"');

if bucket_name.is_empty() || key.is_empty() || e_tag.is_empty() {
debug!("Unable to create span pointer because bucket name, key, or etag is missing.");
return None;
}

// https://github.com/DataDog/dd-span-pointer-rules/blob/main/AWS/S3/Object/README.md
let hash = generate_span_pointer_hash(&[bucket_name, key, e_tag]);

Some(vec![SpanPointer {
hash,
kind: String::from("aws.s3.object"),
}])
}
}

#[cfg(test)]
#[allow(clippy::unwrap_used)]
mod tests {
Expand Down Expand Up @@ -274,4 +297,51 @@ mod tests {
"generic-service"
);
}

#[test]
fn test_get_span_pointers() {
let event = S3Record {
event_source: String::from("aws:s3"),
event_time: Utc::now(),
event_name: String::from("ObjectCreated:Put"),
s3: S3Entity {
bucket: S3Bucket {
name: String::from("test-bucket"),
arn: String::from("arn:aws:s3:::test-bucket"),
},
object: S3Object {
key: String::from("test/key"),
size: 1024,
e_tag: String::from("0123456789abcdef0123456789abcdef"),
},
},
}; //

let span_pointers = event.get_span_pointers().expect("Should return Some(vec)");
assert_eq!(span_pointers.len(), 1);
assert_eq!(span_pointers[0].kind, "aws.s3.object");
assert_eq!(span_pointers[0].hash, "40df87dbfdf59f32253a2668c23e51b4");
}

#[test]
fn test_get_span_pointers_missing_fields() {
let event = S3Record {
event_source: String::from("aws:s3"),
event_time: Utc::now(),
event_name: String::from("ObjectCreated:Put"),
s3: S3Entity {
bucket: S3Bucket {
name: String::new(), // Empty bucket name
arn: String::from("arn"),
},
object: S3Object {
key: String::from("key"),
size: 0,
e_tag: String::from("etag"),
},
},
};

assert!(event.get_span_pointers().is_none());
}
}
1 change: 1 addition & 0 deletions bottlecap/src/traces/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

pub mod context;
pub mod propagation;
pub mod span_pointers;
pub mod stats_flusher;
pub mod stats_processor;
pub mod trace_agent;
Expand Down
Loading
Loading