Skip to content

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

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

ARAYN7011 wants to merge 4 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.

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

@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

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.22%. Comparing base (9c1d0ee) to head (9ee91c4).

Additional details and impacted files
@@            Coverage Diff            @@
##               main    #4050   +/-   ##
=========================================
  Coverage     94.21%   94.22%           
- Complexity     6694     6702    +8     
=========================================
  Files           432      432           
  Lines         20966    20976   +10     
  Branches       2109     2113    +4     
=========================================
+ Hits          19753    19764   +11     
+ Misses          761      759    -2     
- Partials        452      453    +1     

☔ 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

ARAYN7011 and others added 3 commits November 26, 2026 11:49
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 <noreply@anthropic.com>
Signed-off-by: ARAYN7011 <88572149+ARAYN7011@users.noreply.github.com>
…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 <noreply@anthropic.com>
@ARAYN7011
ARAYN7011 force-pushed the fix/otel-runtime-telemetry-toggle branch from ec7e21b to 56276d1 Compare November 26, 2026 06:20
@ARAYN7011

Copy link
Copy Markdown
Author

Thanks @jknack. Done in 56276d1: OtelModule now reads otel.instrumentation.runtime-telemetry.enabled only from the application config (system properties and env vars are already merged there), so the separate System.getProperty/getenv lookups are gone. For coverage, the tests now cover each branch of the check: disabled in config, enabled in config, setting absent, and the Java agent skip. OtelModuleTest passes (15 tests).

@ARAYN7011

Copy link
Copy Markdown
Author

Pushed 9ee91c4 to address the codecov/patch gap: the return true branch of the Java agent detection was never hit (no agent on the test classpath). The class lookup is now a small isClassPresent(String) helper, covered for both a present and a missing class. OtelModuleTest: 16 pass.

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