Skip to content

refactor(telemetry): pull the AppSec settings from a telemetry provider - #22140

Open
gnufede wants to merge 2 commits into
gnufede/package-split-telemetryfrom
gnufede/package-split-telemetry-appsec
Open

gnufede wants to merge 2 commits into
gnufede/package-split-telemetryfrom
gnufede/package-split-telemetry-appsec

Conversation

@gnufede

@gnufede gnufede commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

Part of replacing #22018 with smaller PRs on main.

Stacked on the telemetry PR (gnufede/package-split-telemetry,
itself stacked on #22130). Review after both; it uses ddtrace/internal/telemetry/inputs.py and the shared
entry-point helper from them.

Telemetry read the AppSec settings (SCA, endpoint collection) by importing ddtrace.internal.settings.appsec_telemetry,
and reported that configuration at import. Telemetry moves to ddtrace-internal, which never imports ddtrace. This
PR addresses the AppSec part of #22018 (comment) by pulling,
not pushing:

  • pyproject.toml declares appsec = "ddtrace.internal.settings.appsec_telemetry:provider" in the
    ddtrace_internal.telemetry_providers entry-point group.
  • appsec_telemetry.py gains AppSecTelemetryProvider with optional hooks: configurations(),
    dependency_metadata_enabled(), endpoint_collection_enabled(), endpoint_collection_limit(). They read the
    settings on each call, so runtime changes still apply.
  • telemetry/inputs.py resolves the providers on first use (entry point name order, a provider that fails to load is
    skipped) and caches them. writer.py, dependency_tracker.py and telemetry/__init__.py read the hooks instead of
    the AppSec config. Nothing is registered at import.
  • The configuration report order stays pinned: provided configurations, then agent and process tags. Without a
    provider the defaults apply: no dependency metadata, endpoint collection on, 300 endpoints per message.

Tests: tests/telemetry/test_inputs.py (provider declared and resolved lazily, cached, failing provider skipped,
defaults without a provider, settings read on each use, partial providers, report order, nothing loaded before
telemetry is imported), plus the shutdown-failure tests in tests/telemetry/test_dependency.py and
tests/appsec/sca/test_telemetry.py, which now break the AppSec config behind the provider.

🤖 Generated with Claude Code

Telemetry moves to ddtrace-internal, which can't import dd-trace-py's
AppSec settings. AppSec now declares a provider in the
ddtrace_internal.telemetry_providers entry point group, and telemetry
resolves it lazily on first use and reads its hooks on each use: the
configurations to report at import, whether to collect full dependency
metadata, and API endpoint collection. Nothing registers at import time,
the configuration report order is unchanged, and without a provider the
defaults match the AppSec ones.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@gnufede gnufede added the changelog/no-changelog A changelog entry is not required for this PR. label Nov 26, 2026
@cit-pr-commenter-54b7da

Copy link
Copy Markdown

Codeowners resolved as

Resolved from the full PR diff against gnufede/package-split-telemetry using the target branch CODEOWNERS file.
CODEOWNERS team requests not listed below are not required by the current file set.

ddtrace/internal/settings/appsec_telemetry.py                           @DataDog/asm-python
ddtrace/internal/telemetry/__init__.py                                  @DataDog/apm-python
ddtrace/internal/telemetry/dependency_tracker.py                        @DataDog/apm-python
ddtrace/internal/telemetry/inputs.py                                    @DataDog/apm-python
ddtrace/internal/telemetry/writer.py                                    @DataDog/apm-python
pyproject.toml                                                          @DataDog/apm-python-guild
tests/appsec/sca/test_telemetry.py                                      @DataDog/asm-python
tests/telemetry/test_dependency.py                                      @DataDog/apm-core-python @DataDog/apm-python
tests/telemetry/test_inputs.py                                          @DataDog/apm-core-python @DataDog/apm-python

@cit-pr-commenter-54b7da

cit-pr-commenter-54b7da Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Dependency direction analysis

⚠️ Existing dependency direction violations

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

Show existing violations (showing 5 of 22 highest severity)
ddtrace.internal.tracemethods -×-> ddtrace.trace  (internal-core -> product:tracing, score=103)
ddtrace.llmobs._integrations.base -×-> ddtrace.trace  (product:llmobs -> product:tracing, score=101)
ddtrace.llmobs._integrations.bedrock_agents -×-> ddtrace.trace  (product:llmobs -> product:tracing, score=101)
ddtrace.internal.span_bus -×-> ddtrace._trace.span  (internal-core -> product:tracing, score=35)
ddtrace.llmobs._llmobs -×-> ddtrace._trace.span  (product:llmobs -> product:tracing, score=33)

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-official

datadog-official Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Pipelines  Tests

🎉 All green!

🧪 All tests passed
❄️ No new flaky tests detected

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

@pr-commenter

pr-commenter Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Benchmarks

Benchmark execution time: 2026-11-26 19:31:57

Comparing candidate commit b8432b7 in PR branch gnufede/package-split-telemetry-appsec with baseline commit 71805dc in branch gnufede/package-split-telemetry.

📊 Benchmarking dashboard

Found 0 performance improvements and 3 performance regressions! Performance is the same for 625 metrics, 10 unstable metrics, 1 flaky benchmarks without significant changes.

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:packagesupdateimporteddependencies-import_one_cache

  • 🟥 execution_time [+1.334µs; +1.462µs] or [+16.557%; +18.145%]

scenario:packagesupdateimporteddependencies-import_one_stdlib_cache

  • 🟥 execution_time [+1.212µs; +1.303µs] or [+14.905%; +16.032%]

scenario:packagesupdateimporteddependencies-import_one_unknown_cache

  • 🟥 execution_time [+1.263µs; +1.327µs] or [+15.545%; +16.337%]

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 [-722.059ns; +736.206ns] or [-6.775%; +6.908%]

scenario:coreapiscenario-core_dispatch_1_listener

  • unstable execution_time [-38.732ns; +32.583ns] or [-5.965%; +5.018%]

scenario:coreapiscenario-core_dispatch_50_listeners

  • unstable execution_time [-1862.145ns; +1942.514ns] or [-9.302%; +9.703%]

scenario:coreapiscenario-core_dispatch_exception_listeners

  • unstable execution_time [-2111.400ns; +1523.726ns] or [-10.839%; +7.822%]

scenario:coreapiscenario-core_dispatch_listeners

  • unstable execution_time [-360.114ns; +382.621ns] or [-8.440%; +8.967%]

scenario:coreapiscenario-core_dispatch_no_args_listeners

  • unstable execution_time [-225.118ns; +222.133ns] or [-8.430%; +8.318%]

scenario:coreapiscenario-core_dispatch_with_results_1_listener

  • unstable execution_time [-103.591ns; +69.529ns] or [-7.512%; +5.042%]

scenario:coreapiscenario-core_dispatch_with_results_50_listeners

  • unstable execution_time [-4529.958ns; +4567.959ns] or [-9.425%; +9.504%]

scenario:coreapiscenario-core_dispatch_with_results_listeners

  • unstable execution_time [-864.241ns; +1015.645ns] or [-8.550%; +10.048%]

scenario:packagesupdateimporteddependencies-import_many_stdlib_cached

  • unstable execution_time [-45.470µs; +69.013µs] or [-7.755%; +11.771%]

Known flaky benchmarks

These benchmarks are marked as flaky and will not trigger a failure. Modify FLAKY_BENCHMARKS_REGEX to control which benchmarks are marked as flaky.

Known flaky benchmarks without significant changes:

  • scenario:packagespackageforrootmodulemapping-cache_off

@gnufede
gnufede marked this pull request as ready for review November 26, 2026 19:00
@gnufede
gnufede requested review from a team as code owners November 26, 2026 19:00
@gnufede
gnufede requested review from christophe-papazian and juanjux and removed request for a team November 26, 2026 19:00
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-26T19:04:18.820747Z b8432b7 Draft marked ready
ℹ️ 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.

@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: b8432b7eb8

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

# first.
if _providers is None:
providers = []
for entry_point, _ in sorted(entry_points_with_distributions(PROVIDERS_GROUP), key=lambda ep: ep[0].name):

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Provide startup benchmarks for provider discovery

Provider discovery adds another installed-distribution entry-point enumeration to cold imports: telemetry.__init__ unconditionally calls _report_initial_configurations(), which reaches this loop even when telemetry is disabled. The supplied change documents functional tests but provides no startup benchmark evidence. Run the run-benchmarks startup comparison, including telemetry enabled and disabled, to validate the added cost; repository instructions explicitly require benchmarks for startup changes and reporting missing coverage.

AGENTS.md reference: AGENTS.md:L16-L18

Useful? React with 👍 / 👎.

Comment on lines +259 to +260
def _report_initial_configurations() -> None:
# The configurations the telemetry providers ask for come before telemetry's own.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Preserve or update the existing telemetry TODO

This replacement deletes the existing TODO: Remove this once the telemetry feature is refactored to a better design. Although removal appears intentional as part of the refactor, repository instructions explicitly prohibit deleting TODO/NOTE comments without human authorization and require updating them when related code changes. No supplied instruction authorizes removal, so preserve or update the comment to reflect the provider-based reporting.

AGENTS.md reference: AGENTS.md:L15-L15

Useful? React with 👍 / 👎.

@datadog-official datadog-official Bot 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.

Bits Code Review: PASS

More details

The provider hooks preserve runtime AppSec settings reads, configuration reporting order, and defaults when no provider is available. The completed static review found no actionable defect.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit b8432b7

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

Labels

changelog/no-changelog A changelog entry is not required for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant