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 <noreply@anthropic.com>
Signed-off-by: ARAYN7011 <88572149+ARAYN7011@users.noreply.github.com>
@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 <noreply@anthropic.com>
@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.

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

jooby-opentelemetry always creates JVM metrics

2 participants