Skip to content

fix(runtime): refresh identity-bound consumers - #19780

Draft
litianningdatadog wants to merge 2 commits into
tianning.li/2-web-request-starting-eventfrom
tianning.li/3-runtime-id-refresh-consumers
Draft

fix(runtime): refresh identity-bound consumers#19780
litianningdatadog wants to merge 2 commits into
tianning.li/2-web-request-starting-eventfrom
tianning.li/3-runtime-id-refresh-consumers

Conversation

@litianningdatadog

Copy link
Copy Markdown
Contributor

Description

Refreshing the runtime id alone leaves stale identity in components that cache it at construction time. Remote Config, telemetry, trace writer, runtime metrics, Symbol DB, crashtracking, and AppSec RC tagging each have some runtime or client identity baked into long-lived state.

This wires those components to explicit identity refreshes and rebuilds only the state that captures those ids. It keeps fork cleanup on the existing fork hooks so this path does not drop buffers or report fake fork lineage.

Testing

Added direct refresh_identity() coverage for the affected consumers, including RC client renewal, telemetry worker rebuild, trace exporter rebuild, runtime metric tag refresh, Symbol DB metadata refresh, crashtracking reconfiguration, and live AppSec RC client-id tagging.

Risks

Medium. This touches several long-lived product components, but the behavior is only reached through explicit identity refresh and is not activated from request traffic until the next PR.

Additional Notes

Stacked on #19779.

@cit-pr-commenter-54b7da

cit-pr-commenter-54b7da Bot commented Aug 20, 2026

Copy link
Copy Markdown

Codeowners resolved as

Resolved from the full PR diff against tianning.li/2-web-request-starting-event using the target branch CODEOWNERS file.
CODEOWNERS team requests not listed below are not required by the current file set.

ddtrace/appsec/_asm_request_context.py                                  @DataDog/asm-python
ddtrace/appsec/_remoteconfiguration.py                                  @DataDog/asm-python
ddtrace/debugging/_probe/status.py                                      @DataDog/debugger-python
ddtrace/internal/core/crashtracking.py                                  @DataDog/profiling-python @DataDog/apm-core-python
ddtrace/internal/native/_native.pyi                                     @DataDog/apm-core-python
ddtrace/internal/remoteconfig/client.py                                 @DataDog/remote-config @DataDog/apm-core-python
ddtrace/internal/runtime/runtime_metrics.py                             @DataDog/apm-sdk-capabilities-python
ddtrace/internal/settings/asm.py                                        @DataDog/asm-python
ddtrace/internal/symbol_db/symbols.py                                   @DataDog/debugger-python
ddtrace/internal/telemetry/writer.py                                    @DataDog/apm-python
ddtrace/internal/writer/writer.py                                       @DataDog/apm-core-python
src/native/crashtracker.rs                                              @DataDog/profiling-python @DataDog/apm-core-python
src/native/lib.rs                                                       @DataDog/apm-core-python
tests/appsec/appsec/test_asm_request_context.py                         @DataDog/asm-python
tests/appsec/appsec/test_remoteconfiguration.py                         @DataDog/asm-python
tests/crashtracker/test_crashtracker.py                                 @DataDog/profiling-python
tests/internal/remoteconfig/test_remoteconfig_native.py                 @DataDog/remote-config @DataDog/apm-core-python
tests/internal/symbol_db/test_symbols.py                                @DataDog/debugger-python
tests/runtime/test_runtime_metrics_api.py                               @DataDog/apm-sdk-capabilities-python
tests/telemetry/test_writer.py                                          @DataDog/apm-python
tests/tracer/test_writer.py                                             @DataDog/apm-sdk-capabilities-python

@cit-pr-commenter-54b7da

cit-pr-commenter-54b7da Bot commented Aug 20, 2026

Copy link
Copy Markdown

Dependency direction analysis

📈 Existing violations got worse

10 pre-existing violation(s) increased in severity (e.g. their target became more depended-on, or got pulled into an import cycle), though the edge itself isn't new:

Show violations that got worse (showing 5 of 10 highest severity)
ddtrace.internal.remoteconfig.client -×-> ddtrace.internal.runtime  (internal-core -> product:runtime, score=15, +1 vs base)
ddtrace.internal.symbol_db.remoteconfig -×-> ddtrace.internal.runtime  (internal-core -> product:runtime, score=15, +1 vs base)
ddtrace.internal.symbol_db.symbols -×-> ddtrace.internal.runtime  (internal-core -> product:runtime, score=15, +1 vs base)
ddtrace.internal.core.crashtracking -×-> ddtrace.internal.runtime  (internal-core -> product:runtime, score=15, +1 vs base)
ddtrace.internal.ci_visibility.writer -×-> ddtrace.internal.runtime  (product:ci_visibility -> product:runtime, score=13, +1 vs base)

To see all violations, download the layers-base.json and layers-pr.json artifacts from this CI job and run:

uv run --script scripts/import-analysis/layers.py compare layers-base.json layers-pr.json

⚠️ Existing dependency direction violations

There are 254 dependency direction violations that already exist on the base branch and have not been changed by this PR.

Show existing violations (showing 5 of 254 highest severity)
ddtrace.internal.tracemethods -×-> ddtrace.trace  (internal-core -> product:tracing, score=134)
ddtrace.appsec._contrib.django -×-> ddtrace.trace  (product:appsec -> product:tracing, score=132)
ddtrace.debugging._signal.model -×-> ddtrace.trace  (product:debugging -> product:tracing, score=132)
ddtrace.llmobs._integrations.anthropic -×-> ddtrace.trace  (product:llmobs -> product:tracing, score=132)
ddtrace.internal.test_visibility.api -×-> ddtrace.trace  (product:ci_visibility -> product:tracing, score=132)

To see all violations, download the layers-base.json and layers-pr.json artifacts from this CI job and run:

uv run --script scripts/import-analysis/layers.py compare layers-base.json layers-pr.json

@datadog-prod-us1-6

datadog-prod-us1-6 Bot commented Aug 20, 2026

Copy link
Copy Markdown

Pipelines  Tests

Unblock PR with BitsAI

⚠️ Warnings

🚦 11 Pipeline jobs failed

DataDog/apm-reliability/dd-trace-py | build linux serverless: [amd64, cp315-cp315, v113741238-d2b8243-manylinux2014_x86_64, 1] — 🔧 Needs a code fix, caused by this PR

View in Datadog · View in GitLab

DataDog/apm-reliability/dd-trace-py | build linux serverless: [amd64, cp315-cp315, v126532274-233089d-musllinux_1_2_x86_64, 1] — 🔧 Needs a code fix, caused by this PR

View in Datadog · View in GitLab

DataDog/apm-reliability/dd-trace-py | build linux serverless: [arm64, cp315-cp315, v113741357-d2b8243-manylinux2014_aarch64, 1] — 🔧 Needs a code fix, caused by this PR

View in Datadog · View in GitLab

View all 11 failed jobs.

ℹ️ Info

No other issues found (see more)

🧪 All tests passed
❄️ No new flaky tests detected

Useful? React with 👍 / 👎

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

@cit-pr-commenter-54b7da

cit-pr-commenter-54b7da Bot commented Aug 20, 2026

Copy link
Copy Markdown

Circular import analysis

⚠️ Existing circular imports

There are 5 circular imports that already exist on the base branch and have not been changed by this PR.

ddtrace.contrib.internal.pytorch._distributed -> ddtrace.contrib.internal.pytorch._rank_root -> ddtrace.contrib.internal.pytorch._distributed
ddtrace.contrib.internal.django.patch -> ddtrace.contrib.internal.django.response -> ddtrace.contrib.internal.django.patch
ddtrace.llmobs -> ddtrace.llmobs._evaluators -> ddtrace.llmobs._evaluators.format -> ddtrace.llmobs._experiment -> ddtrace.llmobs
ddtrace.errortracking._handled_exceptions.bytecode_injector -> ddtrace.errortracking._handled_exceptions.callbacks -> ddtrace.errortracking._handled_exceptions.collector -> ddtrace.errortracking._handled_exceptions.bytecode_reporting -> ddtrace.errortracking._handled_exceptions.bytecode_injector
ddtrace.appsec._asm_request_context -> ddtrace.appsec._iast._iast_request_context_base -> ddtrace.appsec._iast._iast_env -> ddtrace.appsec._iast.reporter -> ddtrace.appsec._exploit_prevention.stack_traces -> ddtrace.appsec._asm_request_context

if asm_config._rc_client_id is not None:
entry_span.set_tag(APPSEC.RC_CLIENT_ID, asm_config._rc_client_id)
if asm_config._rc_client_id_enabled:
rc_client_id = remoteconfig_poller._client.id

@litianningdatadog litianningdatadog Aug 20, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We use remoteconfig_poller as client id's SOT instead of asm_config as we refresh remoteconfig_poller

@pr-commenter

pr-commenter Bot commented Aug 20, 2026

Copy link
Copy Markdown

Benchmarks

Benchmark execution time: 2026-08-20 11:52:47

Comparing candidate commit d424d55 in PR branch tianning.li/3-runtime-id-refresh-consumers with baseline commit c9ede47 in branch main.

📊 Benchmarking dashboard

Found 0 performance improvements and 8 performance regressions! Performance is the same for 610 metrics, 10 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 ----------------------------------'

scenario:httppropagationinject-ids_only

  • 🟥 execution_time [+2.864µs; +3.042µs] or [+13.308%; +14.133%]

scenario:iastaspects-repr_aspect

  • 🟥 execution_time [+64.159µs; +74.423µs] or [+16.915%; +19.621%]

scenario:iastaspects-upper_aspect

  • 🟥 execution_time [+47.293µs; +53.506µs] or [+19.541%; +22.108%]

scenario:iastaspectsospath-ospathbasename_aspect

  • 🟥 execution_time [+121.977µs; +128.502µs] or [+28.909%; +30.456%]

scenario:iastaspectssplit-rsplit_aspect

  • 🟥 execution_time [+13.410µs; +17.607µs] or [+9.362%; +12.293%]

scenario:span-start

  • 🟥 execution_time [+1.450ms; +1.600ms] or [+9.568%; +10.557%]

scenario:telemetryaddmetric-1-count-metric-1-times

  • 🟥 execution_time [+363.943ns; +407.326ns] or [+13.730%; +15.366%]

scenario:tracer-small

  • 🟥 execution_time [+31.045µs; +33.579µs] or [+9.157%; +9.904%]

Unstable benchmarks

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

scenario:coreapiscenario-context_with_data_listeners

  • unstable execution_time [-598.555ns; +865.584ns] or [-5.488%; +7.936%]

scenario:coreapiscenario-core_dispatch_1_listener

  • unstable execution_time [-23.564ns; +42.472ns] or [-3.856%; +6.950%]

scenario:coreapiscenario-core_dispatch_50_listeners

  • unstable execution_time [-1738.948ns; +1530.741ns] or [-10.258%; +9.030%]

scenario:coreapiscenario-core_dispatch_exception_listeners

  • unstable execution_time [-1016.944ns; +1480.947ns] or [-7.878%; +11.472%]

scenario:coreapiscenario-core_dispatch_listeners

  • unstable execution_time [-330.001ns; +318.225ns] or [-9.006%; +8.685%]

scenario:coreapiscenario-core_dispatch_no_args_listeners

  • unstable execution_time [-280.016ns; +224.868ns] or [-9.589%; +7.700%]

scenario:coreapiscenario-core_dispatch_with_results_1_listener

  • unstable execution_time [-66.907ns; +88.121ns] or [-5.777%; +7.608%]

scenario:coreapiscenario-core_dispatch_with_results_50_listeners

  • unstable execution_time [-3533.981ns; +4541.854ns] or [-8.649%; +11.115%]

scenario:coreapiscenario-core_dispatch_with_results_listeners

  • unstable execution_time [-711.332ns; +855.935ns] or [-8.735%; +10.510%]

scenario:packagesupdateimporteddependencies-import_many_stdlib_cached

  • unstable execution_time [-64.228µs; +55.663µs] or [-10.033%; +8.695%]

_rc_client_id: Optional[str] = None
# Set by enable_appsec_rc()/disable_appsec_rc(); gates _dd.rc.client_id span tagging so it's
# only emitted while AppSec RC is actually enabled, not just whenever a live RC client exists.
_rc_client_id_enabled: bool = False

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

use _rc_client_id_enabled to replace the existence check of _rc_client_id to accurately identify whether to access client id

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.

Pull request overview

This PR extends runtime.refresh_identity() to actively refresh/rebuild long-lived components that cache runtime-identity at construction time (e.g., Remote Config native client, telemetry worker, trace exporter, runtime-metrics tags, Symbol DB context, crashtracking metadata, and AppSec RC tagging), ensuring identity changes propagate without fork-style buffer loss.

Changes:

  • Introduces a on_runtime_id_change() subscription mechanism and wires multiple consumers to rebuild/refresh identity-bound state on refresh_identity().
  • Adds a native crashtracker reconfigure binding and uses it to refresh crashtracking metadata on identity refresh.
  • Adjusts AppSec RC client-id span tagging to read the client id live (and gates tagging to only when AppSec RC is enabled), plus adds focused test coverage for the new refresh behavior.

Reviewed changes

Copilot reviewed 20 out of 20 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tests/tracer/test_writer.py Adds coverage that identity refresh rebuilds the trace exporter without recreating the writer/buffer.
tests/telemetry/test_writer.py Adds coverage for telemetry worker teardown/rebuild behavior on identity refresh (including live-worker stop).
tests/runtime/test_runtime_metrics_api.py Adds coverage that runtime-id metric tags refresh after refresh_identity().
tests/internal/symbol_db/test_symbols.py Adds coverage that Symbol DB context runtimeId/uploadId refresh on identity refresh.
tests/internal/remoteconfig/test_remoteconfig_native.py Adds coverage that RC client-id is renewed and native client dropped/rebuilt on identity refresh.
tests/crashtracker/test_crashtracker.py Adds coverage that crashtracking reconfigures metadata on identity refresh (Linux-only).
tests/appsec/appsec/test_remoteconfiguration.py Adds coverage that AppSec RC client-id tagging is live and correctly gated when RC is disabled.
src/native/lib.rs Exposes crashtracker_reconfigure to the Python native module.
src/native/crashtracker.rs Implements the crashtracker_reconfigure PyO3 binding calling libdd’s reconfigure.
ddtrace/internal/writer/writer.py Subscribes the trace writer to runtime-id changes and rebuilds the exporter on identity refresh.
ddtrace/internal/telemetry/writer.py Subscribes telemetry writer to runtime-id changes; stops/drops worker for lazy rebuild on identity refresh.
ddtrace/internal/symbol_db/symbols.py Subscribes Symbol DB uploader context to runtime-id changes and refreshes cached event identity fields.
ddtrace/internal/settings/asm.py Replaces cached RC client-id storage with an enablement gate flag for tagging.
ddtrace/internal/runtime/runtime_metrics.py Adds runtime-id change subscription to refresh platform tags when runtime-id tagging is enabled.
ddtrace/internal/remoteconfig/client.py Subscribes RC client to runtime-id changes to renew client id and drop native client for rebuild.
ddtrace/internal/native/_native.pyi Updates typing stubs to include crashtracker_reconfigure.
ddtrace/internal/core/crashtracking.py Subscribes crashtracking to runtime-id changes and reconfigures native crashtracking metadata on identity refresh.
ddtrace/debugging/_probe/status.py Switches debugging probe status payload to import runtime-id helpers directly (import hygiene).
ddtrace/appsec/_remoteconfiguration.py Sets/clears the AppSec RC client-id tagging enablement flag on enable/disable.
ddtrace/appsec/_asm_request_context.py Emits _dd.rc.client_id from the live RC client id when AppSec RC is enabled (instead of a cached value).
Suppressed comments (1)

ddtrace/appsec/_asm_request_context.py:407

  • This code path only needs Remote Config state when AppSec RC is enabled. If you switch to a lazy import (see earlier comment), add the import inside this branch so RemoteConfigPoller is only instantiated when the tag is actually being emitted.
        if asm_config._rc_client_id_enabled:
            rc_client_id = remoteconfig_poller._client.id
            if rc_client_id is not None:
                entry_span.set_tag(APPSEC.RC_CLIENT_ID, rc_client_id)

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

Comment thread ddtrace/internal/core/crashtracking.py
Comment thread ddtrace/appsec/_asm_request_context.py Outdated
from ddtrace.internal.constants import Constant_Class
from ddtrace.internal.core.events import Event
import ddtrace.internal.logger as ddlogger
from ddtrace.internal.remoteconfig.worker import remoteconfig_poller

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

acked

@litianningdatadog
litianningdatadog force-pushed the tianning.li/2-web-request-starting-event branch from c595b5b to 2724ad8 Compare August 20, 2026 10:08
The MicroVM /run hook needs to be observed before a web root span reads process identity, but Python has no single HTTP server substrate across WSGI, ASGI, and framework integrations.

Introduce a shared core event that web integrations emit once method and path are available, before root span creation. The event is deliberately generic here; it does not know about MicroVMs or refresh runtime ids yet.
@litianningdatadog
litianningdatadog force-pushed the tianning.li/2-web-request-starting-event branch from 2724ad8 to 2df658b Compare August 20, 2026 10:10
@litianningdatadog
litianningdatadog force-pushed the tianning.li/3-runtime-id-refresh-consumers branch from b9a5154 to c992c42 Compare August 20, 2026 11:08
Rotating the runtime id is not enough by itself. Several long-lived components bake runtime or Remote Config client identity into native clients, workers, upload metadata, or tag caches.

Have those components subscribe to explicit identity refreshes and rebuild only the state that captures those ids. Fork-specific cleanup remains on the existing fork hooks so this path does not drop buffers or invent fork lineage.
@litianningdatadog
litianningdatadog force-pushed the tianning.li/3-runtime-id-refresh-consumers branch from c992c42 to d424d55 Compare August 20, 2026 11:22
@litianningdatadog
litianningdatadog force-pushed the tianning.li/2-web-request-starting-event branch 5 times, most recently from 4c72681 to 4e70948 Compare August 20, 2026 19:02
@litianningdatadog litianningdatadog added the aws-microvm Work related to AWS MicroVM onboarding label Aug 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

aws-microvm Work related to AWS MicroVM onboarding

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants