fix(serverless): drop stale traces on MicroVM identity refresh - #20089
litianningdatadog wants to merge 0 commit into
Conversation
bb98270 to
6e93b2f
Compare
Codeowners resolved asResolved from the full PR diff against |
Circular import analysis
|
Dependency direction analysis
|
|
There was a problem hiding this comment.
🟡 Changes recommended
Three critical stale-data and synchronization issues must be resolved before approval.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Prevents stale runtime-ID trace data from surviving AWS Lambda MicroVM identity refreshes.
Changes:
- Resets active trace and writer buffers during identity refresh.
- Adds writer-level buffer-discard support and focused tests.
- Updates the release note.
Three critical issues remain: in-flight trace completion can race the reset, live pre-refresh spans can repopulate the aggregator, and native exporter shutdown can emit old-identity data.
File summaries
| File | Description |
|---|---|
tests/tracer/test_writer.py |
Tests native writer buffer clearing. |
tests/tracer/runtime/test_runtime_id.py |
Tests identity-refresh trace cleanup. |
releasenotes/notes/aws-lambda-microvm-identity-refresh-3a672cd6bcbad16d.yaml |
Documents stale-trace prevention. |
ddtrace/internal/writer/writer.py |
Adds buffer discard, but normal exporter shutdown can still emit buffered native stats with the old runtime ID. |
ddtrace/_trace/tracer.py |
Enables reset during refresh, but live pre-refresh spans can later produce stale or orphaned trace fragments. |
ddtrace/_trace/processor/__init__.py |
Coordinates reset behavior, but trace completion and writer replacement are not atomic. |
Review details
Suppressed comments (1)
ddtrace/_trace/tracer.py:437
reset_buffer=Trueclears the aggregator map but leaves the current execution's active Span/Context intact. If the MicroVM snapshot restores an active old span, the first post-refresh request will still be parented to it;start_span()only addsruntime-idwhen there is no local parent, so that trace can be written by the new writer without the refreshed runtime ID. Clear the active context as part of this identity reset.
self._recreate(reset_buffer=True, drop_buffered_traces=True)
- Files reviewed: 6/6 changed files
- Comments generated: 3
- Review effort level: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| elif drop_buffered_traces: | ||
| self.writer.drop_buffered_traces() |
|
|
||
| def _refresh_runtime_identity(self, _runtime_id: str) -> None: | ||
| self._recreate(reset_buffer=False) | ||
| self._recreate(reset_buffer=True, drop_buffered_traces=True) |
| def drop_buffered_traces(self) -> None: | ||
| for client in self._clients: | ||
| getattr(client.encoder, "flush")() |
BenchmarksBenchmark execution time: 2026-09-07 20:59:14 Comparing candidate commit 057569d in PR branch Found 0 performance improvements and 7 performance regressions! Performance is the same for 577 metrics, 10 unstable metrics, 3 known flaky benchmarks, 15 flaky benchmarks without significant changes.
|
8bb966d to
eb6e4ff
Compare
6e93b2f to
eb6e4ff
Compare
Description
When a Lambda MicroVM refreshes its runtime identity, discard active traces and writer-buffered entities that may still contain the previous runtime ID. The reset is enabled only by the MicroVM identity-refresh path; normal configuration and post-fork recreation paths retain their existing behavior.
Testing
Risks
None beyond the intended discard of pre-refresh trace data.
Additional Notes
This is a stacked draft PR on top of #19822.