feat(native-spans)!: change buffer foundation#2046
Conversation
|
Clippy Allow Annotation ReportComparing clippy allow annotations between branches:
Summary by Rule
Annotation Counts by File
Annotation Stats by Crate
About This ReportThis report tracks Clippy allow annotations for specific rules, showing how they've changed in this PR. Decreasing the number of these annotations generally improves code quality. |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## yannham/span-vec-fields-integration #2046 +/- ##
=======================================================================
+ Coverage 72.91% 73.01% +0.10%
=======================================================================
Files 460 465 +5
Lines 76558 76881 +323
=======================================================================
+ Hits 55824 56137 +313
- Misses 20734 20744 +10
🚀 New features to boost your workflow:
|
Artifact Size Benchmark Reportaarch64-alpine-linux-musl
aarch64-unknown-linux-gnu
libdatadog-x64-windows
libdatadog-x86-windows
x86_64-alpine-linux-musl
x86_64-unknown-linux-gnu
|
8962592 to
66fb3e6
Compare
3dc15ea to
57b3ec4
Compare
Add the supporting types for the change-buffer module behind a `change-buffer` feature flag: ChangeBuffer (raw memory wrapper), OpCode/BufferedOperation, SpanHeader (repr(C)), SmallTraceMap, Trace, and error types. These are the building blocks for ChangeBufferState which follows in the next commit. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
66fb3e6 to
8431f28
Compare
📚 Documentation Check Results📦
|
🔒 Cargo Deny Results📦
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8431f288d1
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| //! | ||
| //! The change buffer is currently designed and used for dd-trace-js, but the idea could be extended | ||
| //! to other runtime where the FFI cost is high. | ||
| #[allow(unused)] |
There was a problem hiding this comment.
Make the unused allow cover the module
With the change-buffer feature enabled, this outer attribute only applies to the following ChangeBufferError enum, so the rest of the new module still emits unused-import and dead-code warnings. I checked RUSTFLAGS='-D warnings' cargo check -p libdd-trace-utils --features change-buffer, and it fails on the unused imports/helpers and BufferedOperation; the required all-features clippy invocation also promotes these warnings to errors. Make this an inner module attribute (or remove the unused items) so the feature can pass CI.
Useful? React with 👍 / 👎.
|
|
||
| /// A handle to a change buffer shared with another runtime. The memory is shared, meaning that | ||
| /// cloning is cheap (copying the pointer and length). | ||
| #[derive(Clone, Copy)] |
There was a problem hiding this comment.
Would it be better for this to be only Clone to prevent any accidental implicit copying?
Actually, does this need to even be clone?
There was a problem hiding this comment.
Is this file supposed to be here? It doesn't look like it's used for anything.
| "serialization", | ||
| ] } | ||
| indexmap = "2.11" | ||
| rustc-hash = "2" |
| .get(*index..*index + size) | ||
| .ok_or(ChangeBufferError::ReadOutOfBounds { | ||
| offset: *index, | ||
| len: self.len, |
There was a problem hiding this comment.
minor: could len for this this error be slightly confusing? Is it reasonable for someone reading this error to assume len means the length of bytes attempting to be read? self.len is the length of the entire buffer.
| // construction time. We do not materialize other references during the lifetime of `slice`. | ||
| let slice = unsafe { self.as_mut_slice() }; | ||
| let target = slice | ||
| .get_mut(offset..offset + 4) |
There was a problem hiding this comment.
This is doing unchecked usize adds, which I think is normally fine. Is there any chance that we could get a corrupted or malicious offset value upstream that would trigger an overflow here?
| pub service_id: u32, // offset 56 | ||
| pub resource_id: u32, // offset 60 | ||
| pub type_id: u32, // offset 64 | ||
| /// Index into ChangeBufferState.spans for meta/metrics overflow data. |
There was a problem hiding this comment.
I may just be confused, but is this doc comment accurate?
| //! In order to amortize the cost of crossing the FFI when using native spans, the runtime write | ||
| //! events in the change buffer instead many times and only flush it by batch, where the call to | ||
| //! libdatadog happens. Libdatadog processes the change buffer and reconstruct the corresponding | ||
| //! spans. |
There was a problem hiding this comment.
minor grammar tweak:
| //! In order to amortize the cost of crossing the FFI when using native spans, the runtime write | |
| //! events in the change buffer instead many times and only flush it by batch, where the call to | |
| //! libdatadog happens. Libdatadog processes the change buffer and reconstruct the corresponding | |
| //! spans. | |
| //! In order to amortize the cost of crossing the FFI when using native spans, the runtime writes | |
| //! events into the change buffer instead of calling libdatadog many times, and only flushes by | |
| //! batch — that flush is where the call to libdatadog happens. Libdatadog then processes the change | |
| //! buffer and reconstructs the corresponding spans. |
What does this PR do?
Add foundation types for dd-trace-js change buffer: buffer, opcodes and trace. Follow up of #2043.
Motivation
See #2022. Required for the integration of native spans into dd-trace-js.
Additional Notes
This PR just introduces the types and doesn't use them yet, hence the
allow(unused).How to test the change?
Unit tests provided.