Skip to content

feat(opentelemetry): include lightweight metrics exporters - #20839

Draft
mabdinur wants to merge 4 commits into
mainfrom
codex/otel-http-grpclib-exporter
Draft

mabdinur wants to merge 4 commits into
mainfrom
codex/otel-http-grpclib-exporter

Conversation

@mabdinur

@mabdinur mabdinur commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Description

This draft adds an opt-in lightweight OpenTelemetry metrics export path without making grpcio a dependency of the new path.

  • Adds ddtrace[opentelemetry-metrics], which installs the upstream HTTP/protobuf exporter and grpclib.
  • Uses the OpenTelemetry Python SDK for aggregation, periodic collection, protobuf encoding, and HTTP export.
  • Adds a small gRPC transport built on grpclib and the upstream OTLP protobuf encoder.
  • Preserves the existing ddtrace[opentelemetry] extra and falls back to the upstream gRPC exporter when the lightweight stack is unavailable.
  • Preserves OpenTelemetry attribute types instead of converting values to strings.

The initial experiment made the HTTP exporter a required dependency. CI showed that this is not safe: its exact OpenTelemetry SDK/protobuf coupling conflicts with supported Molten, MySQL, and Ray dependency sets. Keeping the exporter opt-in isolates those constraints and leaves default installations unchanged.

Aggregation and periodic work remain in the OpenTelemetry Python SDK. This PR does not claim the native libdatadog design's CPU, RSS, or GIL improvements.

Installed footprint

Measured from installed distribution files in clean macOS arm64/Python 3.13 environments, excluding generated bytecode.

Installation Size Change from current default
Current default dependencies 31.90 MiB —
This PR's default installation ~31.91 MiB +9.6 KiB / ~0.03% source
Lightweight HTTP + grpclib stack 37.37 MiB +5.47 MiB / +17.1%
Same stack plus upstream grpcio exporter 76.04 MiB +44.14 MiB / +138.3%

The lightweight stack is about 50.9% smaller than the equivalent environment with the upstream gRPC exporter. Users who do not install the new extra gain no runtime dependencies.

Testing

  • Full OpenTelemetry suite with the legacy exporter baseline: 148 passed, 6 skipped, 1 expected failure.
  • Full OpenTelemetry suite on Python 3.13/OpenTelemetry 1.34: 150 passed, 4 skipped, 1 expected failure.
  • Full OpenTelemetry suite on Python 3.14/OpenTelemetry 1.44: 151 passed, 3 skipped, 1 expected failure.
  • Real grpclib client/server OTLP metrics round trip.
  • Typed scalar and sequence metric attributes, headers, timeout behavior, and delta temporality.
  • Full repository formatting, typing, security, suite-spec, dependency, and configuration checks.

Risks

  • The optional exporter stack still has OpenTelemetry SDK/protobuf version coupling.
  • The custom gRPC transport adds maintenance around retries, TLS, shutdown, and fork behavior. gRPC compression is not supported in this draft.
  • Aggregation and periodic export still run in Python.

Follow-up

Logs still use the existing upstream exporters. A follow-up can add the same HTTP/grpclib transport for logs; only then should we consider replacing or deprecating the existing full opentelemetry extra.

@cit-pr-commenter-54b7da

cit-pr-commenter-54b7da Bot commented Oct 6, 2026 •

Copy link
Copy Markdown

Codeowners resolved as

Resolved from the full PR diff against main using the target branch CODEOWNERS file.
CODEOWNERS team requests not listed below are not required by the current file set.

.gitlab/scripts/build-wheel-helpers.sh                                  @DataDog/python-guild @DataDog/apm-core-python
.riot/requirements/14ddd29.txt                                          @DataDog/apm-python
.riot/requirements/15ae5de.txt                                          @DataDog/apm-python
.riot/requirements/16728b4.txt                                          @DataDog/apm-python
.riot/requirements/16b433d.txt                                          @DataDog/apm-python
.riot/requirements/174be1c.txt                                          @DataDog/apm-python
.riot/requirements/18321a0.txt                                          @DataDog/apm-python
.riot/requirements/1970422.txt                                          @DataDog/apm-python
.riot/requirements/1a1fe3b.txt                                          @DataDog/apm-python
.riot/requirements/1c4046b.txt                                          @DataDog/apm-python
.riot/requirements/1d43940.txt                                          @DataDog/apm-python
.riot/requirements/1efaa99.txt                                          @DataDog/apm-python
.riot/requirements/3108254.txt                                          @DataDog/apm-python
.riot/requirements/3b2045e.txt                                          @DataDog/apm-python
.riot/requirements/58ea88b.txt                                          @DataDog/apm-python
.riot/requirements/600bba7.txt                                          @DataDog/apm-python
.riot/requirements/8f4eb1c.txt                                          @DataDog/apm-python
ddtrace/internal/openfeature/_flageval_metrics.py                       @DataDog/feature-flagging-and-experimentation-sdk
ddtrace/internal/opentelemetry/grpclib_metric_exporter.py               @DataDog/apm-sdk-capabilities-python
ddtrace/internal/opentelemetry/metrics.py                               @DataDog/apm-sdk-capabilities-python
docs/configuration.rst                                                  @DataDog/python-guild
lib-injection/sources/requirements.csv                                  @DataDog/apm-core-python
pyproject.toml                                                          @DataDog/python-guild
releasenotes/notes/built-in-otel-metrics-exporters-4f809ffac6a523c9.yaml  @DataDog/apm-python
requirements.csv                                                        @DataDog/python-guild
tests/contrib/suitespec.yml                                             @DataDog/python-guild
tests/opentelemetry/test_metrics.py                                     @DataDog/apm-sdk-capabilities-python

@cit-pr-commenter-54b7da

Copy link
Copy Markdown

Circular import analysis

⚠️ Existing circular imports

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

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

@cit-pr-commenter-54b7da

cit-pr-commenter-54b7da Bot commented Oct 6, 2026 •

Copy link
Copy Markdown

Dependency direction analysis

⚠️ Existing dependency direction violations

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

Show existing violations (showing 5 of 201 highest severity)
ddtrace.internal.tracemethods -×-> ddtrace.trace  (internal-core -> product:tracing, score=132)
ddtrace.debugging._debugger -×-> ddtrace.trace  (product:debugging -> product:tracing, score=130)
ddtrace.llmobs._integrations.langgraph -×-> ddtrace.trace  (product:llmobs -> product:tracing, score=130)
ddtrace.debugging._exception.replay -×-> ddtrace.trace  (product:debugging -> product:tracing, score=130)
ddtrace.llmobs._evaluators.runner -×-> ddtrace.trace  (product:llmobs -> product:tracing, score=130)

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

datadog-prod-us1-4 Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Tests

✅ All CI checks and tests passed.

🎉 All green!

🧪 All tests passed
❄️ No new flaky tests detected

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

@pr-commenter

pr-commenter Bot commented Oct 6, 2026 •

Copy link
Copy Markdown

Benchmarks

Benchmark execution time: 2026-10-06 18:11:49

Comparing candidate commit 20c26bd in PR branch codex/otel-http-grpclib-exporter with baseline commit 8385955 in branch main.

📊 Benchmarking dashboard

Found 0 performance improvements and 5 performance regressions! Performance is the same for 609 metrics, 10 unstable metrics, 6 known flaky benchmarks, 18 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:httppropagationextract-empty_headers

  • 🟥 execution_time [+103.261ns; +123.899ns] or [+13.995%; +16.792%]

scenario:iastaspectsremodule-re_expand_aspect

  • 🟥 execution_time [+67.757µs; +78.410µs] or [+10.740%; +12.429%]

scenario:msgpackencoderscenario-simple_one_span

  • 🟥 execution_time [+458.264ns; +537.384ns] or [+10.932%; +12.819%]

scenario:openfeatureflagevaluation-hook-enqueue-typical

  • 🟥 execution_time [+1.755µs; +1.893µs] or [+8.218%; +8.866%]

scenario:otelspan-start

  • 🟥 execution_time [+1.791ms; +2.609ms] or [+7.112%; +10.364%]

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 [-756.338ns; +720.000ns] or [-7.227%; +6.880%]

scenario:coreapiscenario-core_dispatch_1_listener

  • unstable execution_time [-38.458ns; +39.624ns] or [-5.742%; +5.916%]

scenario:coreapiscenario-core_dispatch_50_listeners

  • unstable execution_time [-1909.711ns; +1947.984ns] or [-9.537%; +9.728%]

scenario:coreapiscenario-core_dispatch_exception_listeners

  • unstable execution_time [-1952.992ns; +2049.718ns] or [-10.095%; +10.594%]

scenario:coreapiscenario-core_dispatch_listeners

  • unstable execution_time [-373.212ns; +387.431ns] or [-8.714%; +9.045%]

scenario:coreapiscenario-core_dispatch_no_args_listeners

  • unstable execution_time [-231.708ns; +229.759ns] or [-8.556%; +8.484%]

scenario:coreapiscenario-core_dispatch_with_results_1_listener

  • unstable execution_time [-104.635ns; +86.592ns] or [-7.496%; +6.203%]

scenario:coreapiscenario-core_dispatch_with_results_50_listeners

  • unstable execution_time [-4889.124ns; +4435.221ns] or [-10.030%; +9.099%]

scenario:coreapiscenario-core_dispatch_with_results_listeners

  • unstable execution_time [-1081.646ns; +824.635ns] or [-10.452%; +7.969%]

scenario:packagesupdateimporteddependencies-import_many_stdlib_cached

  • unstable execution_time [-57.775µs; +51.264µs] or [-10.171%; +9.025%]

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.

scenario:httppropagationinject-ids_only

  • 🟥 execution_time [+2.936µs; +3.051µs] or [+20.547%; +21.352%]

scenario:iastaspects-translate_aspect

  • 🟥 execution_time [+107.759µs; +112.430µs] or [+16.126%; +16.825%]

scenario:iastaspectsospath-ospathbasename_aspect

  • 🟥 execution_time [+158.624µs; +164.534µs] or [+43.609%; +45.234%]

scenario:span-start

  • 🟥 execution_time [+1.130ms; +1.569ms] or [+8.907%; +12.358%]

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

  • 🟥 execution_time [+232.954ns; +265.121ns] or [+11.953%; +13.604%]

scenario:tracer-small

  • 🟥 execution_time [+41.953µs; +43.390µs] or [+16.783%; +17.358%]

Known flaky benchmarks without significant changes:

  • scenario:errortrackingflasksqli-baseline
  • scenario:flasksimple-iast-get
  • scenario:iastaspects-casefold_aspect
  • scenario:iastaspects-casefold_noaspect
  • scenario:iastaspects-index_aspect
  • scenario:iastaspects-ljust_noaspect
  • scenario:iastaspects-lower_aspect
  • scenario:iastaspects-replace_aspect
  • scenario:iastaspects-rstrip_aspect
  • scenario:iastaspects-swapcase_aspect
  • scenario:iastaspects-title_noaspect
  • scenario:iastaspects-translate_noaspect
  • scenario:iastaspects-upper_noaspect
  • scenario:iastaspectssplit-rsplit_aspect
  • scenario:packagespackageforrootmodulemapping-cache_off
  • scenario:packagespackageforrootmodulemapping-cache_on
  • scenario:sethttpmeta-all-enabled
  • scenario:telemetryaddmetric-record-100-metrics

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant