Skip to content

Flush OpenTelemetry metrics by closing the MeterProvider - #12909

Open
PerfectSlayer wants to merge 2 commits into
masterfrom
bbujon/metric-flush
Open

PerfectSlayer wants to merge 2 commits into
masterfrom
bbujon/metric-flush

Conversation

@PerfectSlayer

@PerfectSlayer PerfectSlayer commented Oct 16, 2026 •

Copy link
Copy Markdown
Collaborator

What Does This Do

Replaces the DatadogMeterProvider.shutdown() API added by #12317 with the standard java.io.Closeable interface. The MeterProvider returned by GlobalOpenTelemetry now implements Closeable, like the OpenTelemetry SDK SdkMeterProvider:

MeterProvider meterProvider = GlobalOpenTelemetry.get().getMeterProvider();
if (meterProvider instanceof Closeable) {
  ((Closeable) meterProvider).close();
}

close() performs a final export of the recorded metrics, then shuts down the OTLP metrics exporter. It waits up to 10 seconds for the final export, like SdkMeterProvider.close(). Repeated calls wait for the same final export, which runs only once. It does nothing when the OTLP metrics exporter is not running.

Motivation

  • No new public API: Expose OpenTelemetry metrics shutdown through MeterProvider #12317 is not released yet (milestone 1.68.0). Removing its dd-trace-api types now means they never ship and never need a deprecation cycle.
  • Standard interface: applications only use the OpenTelemetry API and java.io.Closeable, following the SDK convention where SdkMeterProvider is Closeable. They need no dd-trace-api dependency, and the instanceof check skips the no-op provider when the agent is not attached.
  • No tracer changes: the shim reaches the OTLP metrics service through the bootstrap OtelMetricRegistry it already shares with dd-trace-core. The service registers its shutdown action when it starts, so TracerAPI needs no OpenTelemetry metrics lifecycle method.

Additional Notes

🤖 Generated with Claude Code

@PerfectSlayer PerfectSlayer added type: feature Enhancements and improvements comp: metrics Metrics inst: opentelemetry OpenTelemetry instrumentation tag: ai generated Largely based on code generated by an AI or LLM labels Oct 16, 2026
@PerfectSlayer
PerfectSlayer marked this pull request as ready for review October 16, 2026 12:19
@PerfectSlayer
PerfectSlayer requested review from a team as code owners October 16, 2026 12:19
@PerfectSlayer
PerfectSlayer requested review from ValentinZakharov, amarziali and mhlidd and removed request for a team October 16, 2026 12:19
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 16, 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 ⚠️ Failed 2026-10-16T12:25:03.747902Z 42a87ce Draft marked ready
🔒 Security Review ⚠️ Failed 2026-10-16T12:21:02.884780Z 42a87ce 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.

@datadog-prod-us1-6 datadog-prod-us1-6 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.

Bits Code Review: PASS

More details

The registry callback and shared latch preserve a single final export with bounded waiting for repeated close calls. The documented shutdown-hook scheduler limitation remains.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit 42a87ce

@datadog-prod-us1-6

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

Copy link
Copy Markdown

🎯 Code Coverage (details)
• Patch Coverage: 0.00%
• Overall Coverage: 59.77% (-0.04%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 5d7dbd6 | Docs | Give us feedback!

@dd-octo-sts

dd-octo-sts Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

🟢 Java Benchmark SLOs — All performance SLOs passed

Suite Status
Startup 🟢 pass

SLO thresholds are defined here based on automatically generated metrics. A warning is raised when results are within 5% of the threshold.

PR vs. master results
Scenario Candidate master Δ (95% CI of mean)
startup:insecure-bank:iast:Agent 13.95 s 13.92 s [-0.4%; +0.9%] (no difference)
startup:insecure-bank:tracing:Agent 12.89 s 12.93 s [-0.8%; +0.3%] (no difference)
startup:petclinic:appsec:Agent 17.63 s 16.87 s [+0.4%; +8.7%] (maybe worse)
startup:petclinic:iast:Agent 17.38 s 17.55 s [-1.9%; -0.0%] (maybe better)
startup:petclinic:profiling:Agent 16.89 s 17.39 s [-7.3%; +1.6%] (no difference)
startup:petclinic:sca:Agent 17.72 s 17.50 s [+0.3%; +2.2%] (maybe worse)
startup:petclinic:tracing:Agent 16.63 s 16.32 s [-2.4%; +6.2%] (no difference)

Commit: 5d7dbd6d · CI Pipeline · Benchmarking Platform UI


Load and DaCapo benchmarks can be triggered manually in the GitLab pipeline. Results will appear in the Benchmarking Platform UI after completion.

Remove the exporter shutdown guards production can no longer hit, as
the shutdown action is only registered once the exporter has started.
Document the exporter shutdown action held by the registry, share the
blocking sender test setup, and test the registration on start.

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

comp: metrics Metrics inst: opentelemetry OpenTelemetry instrumentation tag: ai generated Largely based on code generated by an AI or LLM type: feature Enhancements and improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant