Skip to content

OtelModule: honor otel.instrumentation.runtime-telemetry.enabled - #4050

Open
ARAYN7011 wants to merge 2 commits into
jooby-project:mainfrom
ARAYN7011:fix/otel-runtime-telemetry-toggle
Open

ARAYN7011 wants to merge 2 commits into
jooby-project:mainfrom
ARAYN7011:fix/otel-runtime-telemetry-toggle

Conversation

@ARAYN7011

@ARAYN7011 ARAYN7011 commented Nov 21, 2026 •

Copy link
Copy Markdown

Fixes #4047

OtelModule.install always called RuntimeTelemetry.create(otel), so JVM metrics could not be muted with the standard otel.instrumentation.runtime-telemetry.enabled=false and were duplicated when the OpenTelemetry Java agent is used.

Changes:

  • Runtime telemetry is still on by default, but is skipped when the property is false as a system property, as the OTEL_INSTRUMENTATION_RUNTIME_TELEMETRY_ENABLED env var, or in the otel block of the application config.
  • It is also skipped when the OpenTelemetry Java agent is present, because the agent already registers the JVM metrics. This is what removes the duplicate runtime-telemetry and runtime-telemetry-java8 scopes.

Test plan:

  • New OtelModuleTest tests: default registers, system property disables, config disables, agent present skips, agent absent detected.
  • mvn -pl modules/jooby-opentelemetry -am test -Dtest='Otel*Test' passes.
  • Manual check with the repro from jooby-opentelemetry always creates JVM metrics #4047 (agent 2.34.0, logging exporter). upstream main exports both runtime-telemetry and runtime-telemetry-java8 scopes. This branch exports only the agent's.

AI assistance: prepared with Claude Code (Claude Sonnet 5.5); I reviewed the change and ran the tests.

RuntimeTelemetry was always created, so JVM metrics could not be muted
and duplicated those of the OpenTelemetry Java agent. Skip it when the
standard property is false (system property, env var or otel config).

Fixes jooby-project#4047

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Signed-off-by: ARAYN7011 <[email protected]>
@froque

froque commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

This does not fix the duplication of metrics

@ARAYN7011

Copy link
Copy Markdown
Author

You're right, thanks. The first commit only made the property work. It didn't remove the duplicate, because OtelModule still created its own RuntimeTelemetry next to the agent's.

I pushed f424a49. OtelModule now doesn't register RuntimeTelemetry when the OpenTelemetry Java agent is on the JVM. It detects the agent by looking for io.opentelemetry.javaagent.bootstrap.AgentInitializer, which sits in the bootstrap class loader. The standard otel.instrumentation.runtime-telemetry.enabled=false still works.

I checked it with your repro (agent 2.34.0, logging exporter) and counted the instrumentation scopes that export metrics:

  • upstream main: runtime-telemetry (module) and runtime-telemetry-java8 (agent), so the metrics are duplicated.
  • this branch: only runtime-telemetry-java8.
  • this branch with -Dotel...enabled=false: no JVM metrics.

I added unit tests for the agent-present case and the no-agent case, and Otel*Test passes. I couldn't unit-test detection against a real agent, so that part was only checked by hand with your repro.

…s present

The agent already registers JVM runtime metrics, so installing the module
duplicated every jvm.* metric (refs jooby-project#4047).

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@ARAYN7011

Copy link
Copy Markdown
Author

Correction to my comment above: the commit hadn't been created yet, so the SHA I quoted was the old one. The fix is now pushed as ec7e21b. The rest of the comment stands.

@jknack

jknack commented Nov 25, 2026

Copy link
Copy Markdown
Member

@ARAYN7011 @froque are we good?

@jknack jknack added this to the 4.6.1 milestone Nov 25, 2026
@ARAYN7011

Copy link
Copy Markdown
Author

From my side yes: ec7e21b skips registering RuntimeTelemetry when the OTel Java agent is present, and I confirmed with @froque's repro that each scope exports once. I'd still like @froque to confirm on their setup.

@froque

froque commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

looks good to me

@codecov

codecov Bot commented Nov 25, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 86.66667% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 94.21%. Comparing base (89370b8) to head (ec7e21b).
⚠️ Report is 6 commits behind head on main.

Files with missing lines Patch % Lines
...c/main/java/io/jooby/opentelemetry/OtelModule.java 86.66% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #4050      +/-   ##
============================================
- Coverage     94.22%   94.21%   -0.02%     
- Complexity     6694     6702       +8     
============================================
  Files           432      432              
  Lines         20964    20978      +14     
  Branches       2108     2113       +5     
============================================
+ Hits          19754    19764      +10     
- Misses          757      759       +2     
- Partials        453      455       +2     

☔ 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.

@jknack jknack left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

one comment. It would be good if we can keep coverage metrics

* variable or in the {@code otel} block of the application configuration.
*/
private boolean isRuntimeTelemetryEnabled(Jooby application) {
var value = System.getProperty(RUNTIME_TELEMETRY_ENABLED);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

system env and properties are merged into application configuration, read once from configuration: https://github.com/jooby-project/jooby/blob/main/jooby/src/main/java/io/jooby/Environment.java#L292

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

jooby-opentelemetry always creates JVM metrics

3 participants