jooby-opentelemetry always creates JVM metrics

未關閉 適合新手
#4,047 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

還沒有人認領這個 Issue。

評估

難度
2/5
預估耗時
1-3 小時
新手友好度
77/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
java
領域
observability

研究方向

從 issue 中提到的 modules/jooby-opentelemetry/src/main/java/io/jooby/opentelemetry/OtelModule.java 裡的 RuntimeTelemetry 建立處開始。檢查模組如何初始化執行階段指標,以及如何套用 OpenTelemetry Java agent 設定。確認停用執行階段遙測可以避免 JVM 指標重複,同時在啟用時保留預期的指標。

由索引模型根據 Issue 內容生成。

描述

While trying to debug another problem, I tried to mute Open Telemetry JVM metrics with -Dotel.instrumentation.runtime-telemetry.enabled=false and would not work.

This is due to RuntimeTelemetry always being created in OtelModule:
https://github.com/jooby-project/jooby/blob/89370b82b3f629a2bc67cdb772fbfb7074ebba53/modules/jooby-opentelemetry/src/main/java/io/jooby/opentelemetry/OtelModule.java#L170

If we use the Open Telemetry Java agent it will also create a RuntimeTelemetry by default. Can be disabled with -Dotel.instrumentation.runtime-telemetry.enabled=false.

So the RuntimeTelemetry in OtelModule is duplicating JVM metrics.

//DEPS io.jooby:jooby:4.6.0
//DEPS io.jooby:jooby-jetty:4.6.0
//DEPS io.jooby:jooby-opentelemetry:4.6.0
//DEPS org.slf4j:slf4j-simple:2.0.20

//RUNTIME_OPTIONS -Dotel.metrics.exporter=console
//RUNTIME_OPTIONS -Dotel.metric.export.interval=10000

import static io.jooby.Jooby.runApp;

import io.jooby.opentelemetry.OtelModule;
import io.opentelemetry.api.GlobalOpenTelemetry;

public class Main {
	public static void main(final String[] args) {
		runApp(args, app -> {
			app.install(new OtelModule(GlobalOpenTelemetry.get()));
			app.get("/foo", ctx -> "Welcome to Jooby!");
		});
	}
}
timeout 15s jbang --javaagent=io.opentelemetry.javaagent:opentelemetry-javaagent:2.34.0 Main.java > output.log 2>&1
❯ grep jvm.thread.count output.log
[otel.javaagent 2026-11-19 14:51:00:972 +0000] [PeriodicMetricReader-worker-1] INFO io.opentelemetry.exporter.logging.LoggingMetricExporter - metric: ImmutableMetricData{resource=Resource{schemaUrl=https://opentelemetry.io/schemas/1.40.0, entities=[SdkEntity{type=service.instance, id={service.instance.id="4b57a2fa-a298-4365-bf84-35b25dec61eb"}, description={}, schemaUrl=https://opentelemetry.io/schemas/1.40.0}], attributes={host.arch="amd64", host.name="PM-FRoque", os.description="Linux 6.8.0-149-generic", os.type="linux", os.version="6.8.0-149-generic", process.command_line="/home/froque/.sdkman/candidates/java/27.0.0.0+35-tem/bin/java -Dotel.metrics.exporter=console -Dotel.metric.export.interval=10000 -javaagent:/home/froque/.m2/repository/io/opentelemetry/javaagent/opentelemetry-javaagent/2.34.0/opentelemetry-javaagent-2.34.0.jar Main", process.executable.path="/home/froque/.sdkman/candidates/java/27.0.0.0+35-tem/bin/java", process.pid=590378, process.runtime.description="Eclipse Adoptium OpenJDK 64-Bit Server VM 27+35", process.runtime.name="OpenJDK Runtime Environment", process.runtime.version="27+35", service.instance.id="4b57a2fa-a298-4365-bf84-35b25dec61eb", service.name="unknown_service:java", telemetry.distro.name="opentelemetry-java-instrumentation", telemetry.distro.version="2.34.0", telemetry.sdk.language="java", telemetry.sdk.name="opentelemetry", telemetry.sdk.version="1.68.0"}}, instrumentationScopeInfo=InstrumentationScopeInfo{name=io.opentelemetry.runtime-telemetry, version=2.32.0-alpha, schemaUrl=https://opentelemetry.io/schemas/1.44.0, attributes={}}, name=jvm.thread.count, description=Number of executing platform threads., unit={thread}, type=LONG_SUM, data=ImmutableSumData{points=[ImmutableLongPointData{startEpochNanos=1795099855005791374, epochNanos=1795099860950783646, attributes={jvm.thread.daemon=true, jvm.thread.state="timed_waiting"}, value=5, exemplars=[]}, ImmutableLongPointData{startEpochNanos=1795099855005791374, epochNanos=1795099860950783646, attributes={jvm.thread.daemon=true, jvm.thread.state="runnable"}, value=4, exemplars=[]}, ImmutableLongPointData{startEpochNanos=1795099855005791374, epochNanos=1795099860950783646, attributes={jvm.thread.daemon=false, jvm.thread.state="runnable"}, value=18, exemplars=[]}, ImmutableLongPointData{startEpochNanos=1795099855005791374, epochNanos=1795099860950783646, attributes={jvm.thread.daemon=true, jvm.thread.state="waiting"}, value=2, exemplars=[]}], monotonic=false, aggregationTemporality=CUMULATIVE}}
[otel.javaagent 2026-11-19 14:51:00:975 +0000] [PeriodicMetricReader-worker-1] INFO io.opentelemetry.exporter.logging.LoggingMetricExporter - metric: ImmutableMetricData{resource=Resource{schemaUrl=https://opentelemetry.io/schemas/1.40.0, entities=[SdkEntity{type=service.instance, id={service.instance.id="4b57a2fa-a298-4365-bf84-35b25dec61eb"}, description={}, schemaUrl=https://opentelemetry.io/schemas/1.40.0}], attributes={host.arch="amd64", host.name="PM-FRoque", os.description="Linux 6.8.0-149-generic", os.type="linux", os.version="6.8.0-149-generic", process.command_line="/home/froque/.sdkman/candidates/java/27.0.0.0+35-tem/bin/java -Dotel.metrics.exporter=console -Dotel.metric.export.interval=10000 -javaagent:/home/froque/.m2/repository/io/opentelemetry/javaagent/opentelemetry-javaagent/2.34.0/opentelemetry-javaagent-2.34.0.jar Main", process.executable.path="/home/froque/.sdkman/candidates/java/27.0.0.0+35-tem/bin/java", process.pid=590378, process.runtime.description="Eclipse Adoptium OpenJDK 64-Bit Server VM 27+35", process.runtime.name="OpenJDK Runtime Environment", process.runtime.version="27+35", service.instance.id="4b57a2fa-a298-4365-bf84-35b25dec61eb", service.name="unknown_service:java", telemetry.distro.name="opentelemetry-java-instrumentation", telemetry.distro.version="2.34.0", telemetry.sdk.language="java", telemetry.sdk.name="opentelemetry", telemetry.sdk.version="1.68.0"}}, instrumentationScopeInfo=InstrumentationScopeInfo{name=io.opentelemetry.runtime-telemetry-java8, version=2.34.0-alpha, schemaUrl=https://opentelemetry.io/schemas/1.44.0, attributes={}}, name=jvm.thread.count, description=Number of executing platform threads., unit={thread}, type=LONG_SUM, data=ImmutableSumData{points=[ImmutableLongPointData{startEpochNanos=1795099854568962400, epochNanos=1795099860950783646, attributes={jvm.thread.daemon=true, jvm.thread.state="timed_waiting"}, value=5, exemplars=[]}, ImmutableLongPointData{startEpochNanos=1795099854568962400, epochNanos=1795099860950783646, attributes={jvm.thread.daemon=true, jvm.thread.state="runnable"}, value=4, exemplars=[]}, ImmutableLongPointData{startEpochNanos=1795099854568962400, epochNanos=1795099860950783646, attributes={jvm.thread.daemon=false, jvm.thread.state="runnable"}, value=18, exemplars=[]}, ImmutableLongPointData{startEpochNanos=1795099854568962400, epochNanos=1795099860950783646, attributes={jvm.thread.daemon=true, jvm.thread.state="waiting"}, value=2, exemplars=[]}], monotonic=false, aggregationTemporality=CUMULATIVE}}

Shows metrics:

  • io.opentelemetry.runtime-telemetry, version=2.32.0-alpha
  • io.opentelemetry.runtime-telemetry-java8, version=2.34.0-alpha

Running again with //RUNTIME_OPTIONS -Dotel.instrumentation.runtime-telemetry.enabled=false added:

❯ grep jvm.thread.count output.log
[otel.javaagent 2026-11-19 14:53:06:739 +0000] [PeriodicMetricReader-worker-1] INFO io.opentelemetry.exporter.logging.LoggingMetricExporter - metric: ImmutableMetricData{resource=Resource{schemaUrl=https://opentelemetry.io/schemas/1.40.0, entities=[SdkEntity{type=service.instance, id={service.instance.id="d6d47999-9643-4ee5-8b83-3a870fd8ff83"}, description={}, schemaUrl=https://opentelemetry.io/schemas/1.40.0}], attributes={host.arch="amd64", host.name="PM-FRoque", os.description="Linux 6.8.0-149-generic", os.type="linux", os.version="6.8.0-149-generic", process.command_line="/home/froque/.sdkman/candidates/java/27.0.0.0+35-tem/bin/java -Dotel.metrics.exporter=console -Dotel.metric.export.interval=10000 -Dotel.instrumentation.runtime-telemetry.enabled=false -javaagent:/home/froque/.m2/repository/io/opentelemetry/javaagent/opentelemetry-javaagent/2.34.0/opentelemetry-javaagent-2.34.0.jar Main", process.executable.path="/home/froque/.sdkman/candidates/java/27.0.0.0+35-tem/bin/java", process.pid=590824, process.runtime.description="Eclipse Adoptium OpenJDK 64-Bit Server VM 27+35", process.runtime.name="OpenJDK Runtime Environment", process.runtime.version="27+35", service.instance.id="d6d47999-9643-4ee5-8b83-3a870fd8ff83", service.name="unknown_service:java", telemetry.distro.name="opentelemetry-java-instrumentation", telemetry.distro.version="2.34.0", telemetry.sdk.language="java", telemetry.sdk.name="opentelemetry", telemetry.sdk.version="1.68.0"}}, instrumentationScopeInfo=InstrumentationScopeInfo{name=io.opentelemetry.runtime-telemetry, version=2.32.0-alpha, schemaUrl=https://opentelemetry.io/schemas/1.44.0, attributes={}}, name=jvm.thread.count, description=Number of executing platform threads., unit={thread}, type=LONG_SUM, data=ImmutableSumData{points=[ImmutableLongPointData{startEpochNanos=1795099980681695902, epochNanos=1795099986715243233, attributes={jvm.thread.daemon=true, jvm.thread.state="timed_waiting"}, value=5, exemplars=[]}, ImmutableLongPointData{startEpochNanos=1795099980681695902, epochNanos=1795099986715243233, attributes={jvm.thread.daemon=true, jvm.thread.state="runnable"}, value=4, exemplars=[]}, ImmutableLongPointData{startEpochNanos=1795099980681695902, epochNanos=1795099986715243233, attributes={jvm.thread.daemon=false, jvm.thread.state="runnable"}, value=18, exemplars=[]}, ImmutableLongPointData{startEpochNanos=1795099980681695902, epochNanos=1795099986715243233, attributes={jvm.thread.daemon=true, jvm.thread.state="waiting"}, value=2, exemplars=[]}], monotonic=false, aggregationTemporality=CUMULATIVE}}

Only shows metric:

  • io.opentelemetry.runtime-telemetry, version=2.32.0-alpha

I did not expected duplicate JVM metrics with the Open Telemtry Java agent and expected to be able to disable JVM metrics.

主要語言
Java
星號
1.8k
分支
205
平均合併
1 天 3 小時
30 天內合併 PR
15

環境準備

  • 提供 Dockerfile 或 Docker Compose 檔案
  • 沒有 Pull Request 範本
  • 沒有貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

jooby-project/jooby 的其他 Issue

查看 jooby-project/jooby 的全部 Issue

相似的 Issue

更多 Java Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。