feat(tracebuffer): flush on drop, drain on shutdown, and support nested tokio runtimes#2005
feat(tracebuffer): flush on drop, drain on shutdown, and support nested tokio runtimes#2005Aaalibaba42 wants to merge 4 commits into
Conversation
📚 Documentation Check Results📦
|
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. |
🔒 Cargo Deny Results📦
|
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #2005 +/- ##
==========================================
+ Coverage 72.75% 72.78% +0.03%
==========================================
Files 452 452
Lines 74895 75074 +179
==========================================
+ Hits 54489 54645 +156
- Misses 20406 20429 +23
🚀 New features to boost your workflow:
|
🎉 All green!🧪 All tests passed 🎯 Code Coverage (details) 🔗 Commit SHA: 463495c | Docs | Datadog PR Page | Give us feedback! |
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
|
b5a716f to
d55d383
Compare
d55d383 to
d4d669c
Compare
d4d669c to
463495c
Compare
What?
Make the
TraceBufferandSharedRuntimesafe to use from within a tokio runtime, add a synchronousflush_and_waitAPI, ensure pending spans are drained on shutdown, and fire a best-effort flush onDrop.Why?
SharedRuntime::block_onandshutdownpanic with "Cannot start a runtime from within a runtime" when called from inside a tokio context (e.g. the Rust tracer embedded in an async application).TraceBufferwithout an explicit flush also lost any buffered spans.How?
SharedRuntime(libdd-shared-runtime):block_onandshutdownnow detect a running tokioHandleviaHandle::try_current()and, when found, drive the blocking work on a scoped OS thread (std::thread::scope) instead of callingRuntime::block_ondirectly. TheArc<Runtime>is explicitly dropped on that same thread so its join-on-drop doesn't panic either. AddedSendbounds on the future and its output to support this.TraceBuffer(libdd-data-pipeline): Addedflush_and_wait(timeout)— triggers a flush, captures the batch generation, and blocks until the worker has processed it. AddedReceiver::drain()to synchronously pull remaining chunks without waiting for a flush trigger;TraceExporterWorker::shutdownnow calls it to export any leftover spans. ImplementedDrop for TraceBuffer<T>that fires a non-blocking flush notify.TraceExporter: AddedSendbounds onT::TextandT::Bytesforsend_trace_chunksto satisfy the newblock_onsignature.Additional Notes
Dropimpl is intentionally best-effort (errors are swallowed) — if the runtime is already gone, there's nothing useful to do.flush_and_waitshort-circuits and returns immediately when the batch is empty.block_on,shutdown, anddropfrom inside#[tokio::test].