Skip to content

fix(id): reset and cancel Data Streams state - #10341

Open
litianningdatadog wants to merge 1 commit into
tianning.li/microvm-buffer-reset-01-common-exporter-agent-spanstats-reset-and-cancelfrom
tianning.li/microvm-buffer-reset-06-datastream-reset-and-cancel
Open

litianningdatadog wants to merge 1 commit into
tianning.li/microvm-buffer-reset-01-common-exporter-agent-spanstats-reset-and-cancelfrom
tianning.li/microvm-buffer-reset-06-datastream-reset-and-cancel

Conversation

@litianningdatadog

@litianningdatadog litianningdatadog commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

Prevent Data Streams state from leaking across AWS Lambda MicroVM identity refreshes.

On identity refresh, this PR:

  • Drops buffered Data Streams buckets, schema-sampling state, and checkpoint IDs.
  • Reuses the shared common request controller from fix(id): reset common exporter and span stats state #10338 to cancel active and scheduled Data Streams requests.
  • Rejects stale retry and compression work with ERR_DD_IDENTITY_REFRESH.
  • Keeps the active refresh subscription when a disabled processor is constructed.

Motivation

A MicroVM identity refresh must not carry buffered, sampling, checkpoint, or pending exporter state into the next identity. Without request cancellation, in-flight requests and retries can send pre-refresh payloads under the clone's new runtime identity.

This is a reviewable slice from the breakdown of monolithic PR #9814, tracked by SVLS-9768.

Additional Notes

This PR is stacked on #10338 and uses its shared request.getIdentityRefreshController() implementation. Non-MicroVM requests keep their existing lifecycle.

Focused verification:

  • ./node_modules/.bin/mocha packages/dd-trace/test/exporters/common/request.spec.js packages/dd-trace/test/datastreams/processor.spec.js packages/dd-trace/test/datastreams/writer.spec.js — 113 passing
  • git diff --check passes

Dependency tree

  • origin/master
    • #10338 01-common-exporter-agent-spanstats-reset-and-cancel
      • #10342 02-agentless-exporter-identity
      • #10341 06-datastream-reset-and-cancel ← current PR
    • #10339 03-dogstatsd-buffer-reset
    • #10340 04-otel-runtime-baseline
      • #10343 05-otel-runtime-metric-resets

@dd-octo-sts

dd-octo-sts Bot commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

Overall package size

Self size: 8.97 MB
Deduped: 9.7 MB
No deduping: 9.7 MB

Dependency sizes | name | version | self size | total size | |------|---------|-----------|------------| | import-in-the-middle | 3.5.1 | 127.66 kB | 513.61 kB | | opentracing | 0.14.7 | 194.81 kB | 194.81 kB | | dc-polyfill | 0.1.11 | 25.74 kB | 25.74 kB |

🤖 This report was automatically generated by heaviest-objects-in-the-universe

@codecov

codecov Bot commented Sep 15, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.48%. Comparing base (dda557a) to head (0f6d759).

❗ There is a different number of reports uploaded between BASE (dda557a) and HEAD (0f6d759). Click for more details.

HEAD has 13 uploads less than BASE
Flag BASE (dda557a) HEAD (0f6d759)
master-coverage 12 0
test-optimization 1 0
Additional details and impacted files
@@                                                    Coverage Diff                                                    @@
##           tianning.li/microvm-buffer-reset-01-common-exporter-agent-spanstats-reset-and-cancel   #10341       +/-   ##
=========================================================================================================================
- Coverage                                                                                 98.74%   87.48%   -11.26%     
=========================================================================================================================
  Files                                                                                      1029     1015       -14     
  Lines                                                                                    161396   156099     -5297     
  Branches                                                                                     74       74               
=========================================================================================================================
- Hits                                                                                     159374   136571    -22803     
- Misses                                                                                     2022    19528    +17506     
Flag Coverage Δ
ai-guard 65.27% <60.00%> (+0.24%) ⬆️
apm-capabilities 63.76% <100.00%> (+0.23%) ⬆️
apm-integrations 81.55% <82.85%> (-0.25%) ⬇️
appsec 58.95% <60.00%> (+0.28%) ⬆️
debugger 70.19% <100.00%> (-0.07%) ⬇️
instrumentation 54.48% <60.00%> (+0.19%) ⬆️
llmobs 78.21% <60.00%> (-0.43%) ⬇️
master-coverage ?
openfeature 66.51% <100.00%> (+0.09%) ⬆️
platform 69.38% <60.00%> (+0.06%) ⬆️
profiling 66.85% <100.00%> (-0.07%) ⬇️
serverless 66.01% <82.85%> (+0.37%) ⬆️
test-optimization ?

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@litianningdatadog litianningdatadog added the aws-microvm AWS MicroVM related features label Sep 15, 2026
@litianningdatadog
litianningdatadog requested a lite review from Copilot September 15, 2026 02:19
@litianningdatadog
litianningdatadog marked this pull request as ready for review September 15, 2026 02:21
@litianningdatadog
litianningdatadog requested review from a team as code owners September 15, 2026 02:21
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 15, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-18T21:07:03.056173Z 0f6d759 New commits
🔒 Security Review ✅ Completed 2026-09-18T21:07:46.659639Z 0f6d759 New commits
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Production request cancellation is unavailable, and processor refresh handling can leave state uncleared.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

This PR prevents Data Streams state from leaking across MicroVM identity refreshes.

Changes:

  • Reset processor buckets and tags.
  • Cancel pending writer requests and reject stale compression callbacks.
  • Add focused processor and writer tests.
File summaries
File Summary
packages/dd-trace/test/datastreams/writer.spec.js Tests request cancellation and stale payload handling.
packages/dd-trace/test/datastreams/processor.spec.js Tests processor reset and subscription behavior.
packages/dd-trace/src/datastreams/writer.js Adds reset integration and generation guards. Critical: the common request helper lacks the required reset-controller implementation.
packages/dd-trace/src/datastreams/processor.js Resets processor state. Moderate: unconditional unsubscription can remove the active refresh handler.
Review details

Suppressed comments (1)

packages/dd-trace/src/datastreams/processor.js:248

  • This unsubscribe runs before the this.enabled check, so constructing a disabled DataStreamsProcessor removes the currently active processor's refresh handler and does not install a replacement. A later identity refresh will then leave that active processor's buckets and pending requests untouched; keep the unsubscribe inside the enabled branch.
    unsubscribeBucketReset?.()
    unsubscribeBucketReset = null
  • Files reviewed: 4/4 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread packages/dd-trace/src/datastreams/writer.js Outdated
@datadog-datadog-prod-us1

datadog-datadog-prod-us1 Bot commented Sep 15, 2026 •

Copy link
Copy Markdown

Pipelines  Tests

⚠️ Warnings

Your PR has warnings. Tests failed — unable to determine if these are from required jobs.

🚦 4 Pipeline jobs failed

Project | lint — 🔧 Needs a code fix, caused by this PR

View more details · View in GitHub Actions

Project | lint-windows — 🔧 Needs a code fix, caused by this PR

View more details · View in GitHub Actions

LLMObs | claude-agent-sdk — 🔄 Retry may pass, looks flaky

View more details · View in GitHub Actions

View all 4 failed jobs.

🧪 3 Tests failed in 1 job

LLMObs | claude-agent-sdk — ❌ 3 tests failed

View more details · View in GitHub Actions

❌ Plugin claude-agent-sdk with @anthropic-ai/claude-agent-sdk >=0.2.113 (0.3.268) instruments a full agentic call with subagents from with @anthropic-ai/claude-agent-sdk >=0.2.113 (0.3.268)   View in Datadog
Timeout of 15000ms exceeded. For async tests and hooks, ensure &#34;done()&#34; is called; if returning a Promise, ensure it resolves. (/home/runner/work/dd-trace-js/dd-trace-js/packages/datadog-plugin-claude-agent-sdk/test/index.spec.js)

Error: Timeout of 15000ms exceeded. For async tests and hooks, ensure &#34;done()&#34; is called; if returning a Promise, ensure it resolves. (/home/runner/work/dd-trace-js/dd-trace-js/packages/datadog-plugin-claude-agent-sdk/test/index.spec.js)
    at listOnTimeout (node:internal/timers:605:17)
    at process.processTimers (node:internal/timers:541:7)
❌ esm with @anthropic-ai/claude-agent-sdk >=0.2.113 (0.3.268) is instrumented named from with @anthropic-ai/claude-agent-sdk >=0.2.113 (0.3.268)   View in Datadog
Timeout of 30000ms exceeded. For async tests and hooks, ensure &#34;done()&#34; is called; if returning a Promise, ensure it resolves. (/home/runner/work/dd-trace-js/dd-trace-js/packages/datadog-plugin-claude-agent-sdk/test/integration-test/client.spec.js)

Error: Timeout of 30000ms exceeded. For async tests and hooks, ensure &#34;done()&#34; is called; if returning a Promise, ensure it resolves. (/home/runner/work/dd-trace-js/dd-trace-js/packages/datadog-plugin-claude-agent-sdk/test/integration-test/client.spec.js)
    at listOnTimeout (node:internal/timers:605:17)
    at process.processTimers (node:internal/timers:541:7)
❌ esm with @anthropic-ai/claude-agent-sdk >=0.2.113 (0.3.268) is instrumented named-from-namespace from with @anthropic-ai/claude-agent-sdk >=0.2.113 (0.3.268)   View in Datadog
Timeout of 30000ms exceeded. For async tests and hooks, ensure &#34;done()&#34; is called; if returning a Promise, ensure it resolves. (/home/runner/work/dd-trace-js/dd-trace-js/packages/datadog-plugin-claude-agent-sdk/test/integration-test/client.spec.js)

Error: Timeout of 30000ms exceeded. For async tests and hooks, ensure &#34;done()&#34; is called; if returning a Promise, ensure it resolves. (/home/runner/work/dd-trace-js/dd-trace-js/packages/datadog-plugin-claude-agent-sdk/test/integration-test/client.spec.js)
    at listOnTimeout (node:internal/timers:605:17)
    at process.processTimers (node:internal/timers:541:7)

ℹ️ Info

No other issues found (see more)

❄️ No new flaky tests detected

🎯 Code Coverage (details)
• Patch Coverage: 100.00%
• Overall Coverage: 87.47% (-10.76%)

Useful? React with 👍 / 👎

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 0f6d759 | Docs | View more details | Give us feedback!

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 222ae63c47

ℹ️ 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".

Comment thread packages/dd-trace/src/datastreams/writer.js Outdated
Comment thread packages/dd-trace/src/datastreams/processor.js Outdated
@pr-commenter

pr-commenter Bot commented Sep 15, 2026 •

Copy link
Copy Markdown

Benchmarks

Benchmark execution time: 2026-09-18 21:16:47

Comparing candidate commit 0f6d759 in PR branch tianning.li/microvm-buffer-reset-06-datastream-reset-and-cancel with baseline commit dda557a in branch tianning.li/microvm-buffer-reset-01-common-exporter-agent-spanstats-reset-and-cancel.

📊 Benchmarking dashboard

Found 0 performance improvements and 0 performance regressions! Performance is the same for 2308 metrics, 5 unstable metrics.

Explanation

This is an A/B test comparing a candidate commit's performance against that of a baseline commit. Performance changes are noted in the tables below as:

  • 🟩 = significantly better candidate vs. baseline
  • 🟥 = significantly worse candidate vs. baseline

We compute a confidence interval (CI) over the relative difference of means between metrics from the candidate and baseline commits, considering the baseline as the reference.

If the CI is entirely outside the configured SIGNIFICANT_IMPACT_THRESHOLD (or the deprecated UNCONFIDENCE_THRESHOLD), the change is considered significant.

Feel free to reach out to #apm-benchmarking-platform on Slack if you have any questions.

More details about the CI and significant changes

You can imagine this CI as a range of values that is likely to contain the true difference of means between the candidate and baseline commits.

CIs of the difference of means are often centered around 0%, because often changes are not that big:

---------------------------------(------|---^--------)-------------------------------->
                              -0.6%    0%  0.3%     +1.2%
                                 |          |        |
         lower bound of the CI --'          |        |
sample mean (center of the CI) -------------'        |
         upper bound of the CI ----------------------'

As described above, a change is considered significant if the CI is entirely outside the configured SIGNIFICANT_IMPACT_THRESHOLD (or the deprecated UNCONFIDENCE_THRESHOLD).

For instance, for an execution time metric, this confidence interval indicates a significantly worse performance:

----------------------------------------|---------|---(---------^---------)---------->
                                       0%        1%  1.3%      2.2%      3.1%
                                                  |   |         |         |
       significant impact threshold --------------'   |         |         |
                      lower bound of CI --------------'         |         |
       sample mean (center of the CI) --------------------------'         |
                      upper bound of CI ----------------------------------'

Unstable benchmarks

These benchmarks have a confidence interval too wide to call a change; treat them as noise rather than signal.

scenario:appsec-iast-no-vulnerability-iast-enabled-default-config-20

  • unstable max_rss_usage [-16.355MB; +14.001MB] or [-7.078%; +6.059%]

scenario:dogstatsd-aggregated-26

  • unstable execution_time [-83.125ms; +102.240ms] or [-4.978%; +6.122%]

scenario:encoders-0.4-immediate-flush-20

  • unstable max_rss_usage [-7.624MB; +9.876MB] or [-9.785%; +12.676%]

scenario:llmobs-encode-unicode-mixed-20

  • unstable max_rss_usage [-4.946MB; +11.363MB] or [-6.476%; +14.878%]

scenario:plugin-graphql-long-with-depth-off-26

  • unstable max_rss_usage [-7.486MB; +46.010MB] or [-3.293%; +20.240%]

@litianningdatadog
litianningdatadog requested a review from a team as a code owner September 18, 2026 01:46

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: bbd1d73e05

ℹ️ 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".

Comment thread packages/dd-trace/src/datastreams/processor.js
@litianningdatadog
litianningdatadog force-pushed the tianning.li/microvm-buffer-reset-06-datastream-reset-and-cancel branch 2 times, most recently from c455a3c to 6b6f648 Compare September 18, 2026 19:46
@litianningdatadog
litianningdatadog requested a review from a team as a code owner September 18, 2026 19:46
@litianningdatadog
litianningdatadog requested review from khanayan123 and removed request for a team September 18, 2026 19:46
@litianningdatadog
litianningdatadog changed the base branch from master to tianning.li/microvm-buffer-reset-01-common-exporter-agent-spanstats-reset-and-cancel September 18, 2026 19:53
@chatgpt-codex-connector

Copy link
Copy Markdown

💡 Codex Review

this._identityRefreshController = IS_AWS_LAMBDA_MICROVM ? this._resetController : undefined

P1 Badge Reset the trace writer on identity refresh

When AWS_LAMBDA_MICROVM_IMAGE_ARN is set, this stores a per-writer controller from createResetController(), but that factory does not subscribe to datadog:identity:refresh, and the only production caller of resetPendingBatch() is the span-stats exporter. Consequently, an AgentExporter is never reset: traces queued in its encoder and active or retrying trace requests at snapshot time can still be emitted by every resumed clone. Subscribe the trace exporter or writer to the refresh event and cover the actual channel-driven reset rather than only simulating an ERR_DD_IDENTITY_REFRESH callback.

AGENTS.md reference: AGENTS.md:L78-L80


this.otlpExporter?.resetPendingState?.()

P1 Badge Implement OTLP span-stats request cancellation

When OTEL_TRACES_SPAN_METRICS_ENABLED selects the real OtlpStatsExporter, this optional call is always a no-op: neither that class nor OtlpHttpExporterBase implements resetPendingState(), and the base exporter does not track or abort active HTTP requests. An OTLP span-stats payload built before a MicroVM snapshot can therefore complete after refresh in every clone while still containing the old runtime resource attributes. Add cancellation to the concrete OTLP exporter and test the real exporter path; the current test substitutes an object that already has the missing method.

AGENTS.md reference: AGENTS.md:L78-L80


this.writer.resetPendingRequests()

P2 Badge Avoid resetting the shared request controller twice

DataStreamsWriter now obtains the shared controller from getIdentityRefreshController(), whose factory already subscribes that controller to this same refresh channel before the processor subscribes. This call therefore performs a second reset during one refresh. If an old telemetry, Remote Config, or Data Streams cancellation callback synchronously starts a replacement request—as the new controller tests explicitly permit—the first reset assigns it to the new generation, then this second reset immediately aborts it as well. Remove this redundant reset or make the processor own a separate controller, and cover the channel-driven interaction rather than invoking resetPendingRequests() in isolation.

AGENTS.md reference: AGENTS.md:L78-L80

ℹ️ 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".

@litianningdatadog
litianningdatadog force-pushed the tianning.li/microvm-buffer-reset-06-datastream-reset-and-cancel branch 2 times, most recently from 3bb01a0 to c228c5b Compare September 18, 2026 20:08

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c228c5b6b4

ℹ️ 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".

// Schema sampling and checkpoint IDs belong to the current runtime identity.
this._schemaSamplers = {}
this._checkpointRegistry = new CheckpointRegistry()
this.writer.resetPendingRequests()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Avoid resetting the shared controller twice

In AWS Lambda MicroVM mode, DataStreamsWriter obtains the shared controller whose getIdentityRefreshController() already subscribes it to datadog:identity:refresh; that subscription is registered during the writer construction, before this processor subscription. A refresh therefore calls reset() once in request.js and then again here. If the first cancellation callback synchronously starts a new telemetry, remote-config, or Data Streams request, the controller deliberately records it in the new generation, but this second reset immediately aborts it as well—contradicting the new controller tests that require callback-created requests to survive. Rely on the shared controller's channel subscription rather than resetting it again from the processor.

Useful? React with 👍 / 👎.

@litianningdatadog
litianningdatadog requested a review from a team as a code owner September 18, 2026 20:36
@litianningdatadog
litianningdatadog requested review from wconti27 and removed request for a team September 18, 2026 20:36
@litianningdatadog
litianningdatadog force-pushed the tianning.li/microvm-buffer-reset-06-datastream-reset-and-cancel branch 2 times, most recently from 0ec9cd6 to 7647956 Compare September 18, 2026 20:44
@litianningdatadog
litianningdatadog force-pushed the tianning.li/microvm-buffer-reset-01-common-exporter-agent-spanstats-reset-and-cancel branch from 56806c4 to dda557a Compare September 18, 2026 21:02
Drop stale Data Streams state and avoid resetting the shared identity controller twice.
@litianningdatadog
litianningdatadog force-pushed the tianning.li/microvm-buffer-reset-06-datastream-reset-and-cancel branch from 7647956 to 0f6d759 Compare September 18, 2026 21:04
@khanayan123

Copy link
Copy Markdown
Collaborator

Hi there's been no activity for 3 weeks, going to move this PR to draft. Please reopen once ready.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

aws-microvm AWS MicroVM related features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants