From 457ddf70d202e4c30155e319e939fba97b21c589 Mon Sep 17 00:00:00 2001 From: Tim Quinn Date: Tue, 13 Feb 2024 07:12:50 -0600 Subject: [PATCH 1/3] Review comments from earlier PR --- .../telemetry/HelidonTelemetryContainerFilter.java | 4 +++- .../helidon/microprofile/telemetry/TelemetryCdiExtension.java | 4 ---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/microprofile/telemetry/src/main/java/io/helidon/microprofile/telemetry/HelidonTelemetryContainerFilter.java b/microprofile/telemetry/src/main/java/io/helidon/microprofile/telemetry/HelidonTelemetryContainerFilter.java index 7f2b504c11d..844f799d9cf 100644 --- a/microprofile/telemetry/src/main/java/io/helidon/microprofile/telemetry/HelidonTelemetryContainerFilter.java +++ b/microprofile/telemetry/src/main/java/io/helidon/microprofile/telemetry/HelidonTelemetryContainerFilter.java @@ -21,6 +21,8 @@ import java.util.Objects; import io.helidon.common.context.Contexts; +import io.helidon.config.mp.MpConfig; +import io.helidon.tracing.providers.opentelemetry.HelidonOpenTelemetry; import io.opentelemetry.api.OpenTelemetry; import io.opentelemetry.api.baggage.Baggage; @@ -93,7 +95,7 @@ public Iterable keys(ContainerRequestContext containerRequestContext) { HelidonTelemetryContainerFilter(Tracer tracer, OpenTelemetry openTelemetry, org.eclipse.microprofile.config.Config mpConfig) { this.tracer = tracer; this.openTelemetry = openTelemetry; - isAgentPresent = Boolean.getBoolean(TelemetryCdiExtension.OTEL_AGENT_PRESENT); + isAgentPresent = HelidonOpenTelemetry.AgentDetector.isAgentPresent(MpConfig.toHelidonConfig(mpConfig)); mpConfig.getOptionalValue(SPAN_NAME_FULL_URL, Boolean.class).ifPresent(e -> spanNameFullUrl = e); } diff --git a/microprofile/telemetry/src/main/java/io/helidon/microprofile/telemetry/TelemetryCdiExtension.java b/microprofile/telemetry/src/main/java/io/helidon/microprofile/telemetry/TelemetryCdiExtension.java index b7f066d0391..8bf16b07e42 100644 --- a/microprofile/telemetry/src/main/java/io/helidon/microprofile/telemetry/TelemetryCdiExtension.java +++ b/microprofile/telemetry/src/main/java/io/helidon/microprofile/telemetry/TelemetryCdiExtension.java @@ -35,8 +35,6 @@ public class TelemetryCdiExtension implements Extension { private static final System.Logger LOGGER = System.getLogger(TelemetryCdiExtension.class.getName()); - private boolean isAgentPresent; - /** * Add {@code HelidonWithSpan} annotation with interceptor. * @@ -45,8 +43,6 @@ public class TelemetryCdiExtension implements Extension { void before(@Observes BeforeBeanDiscovery discovery) { LOGGER.log(System.Logger.Level.TRACE, () -> "Before Telemetry bean discovery " + discovery); - isAgentPresent = Boolean.getBoolean(OTEL_AGENT_PRESENT); - // Register annotations, interceptors and producers. discovery.addAnnotatedType(HelidonWithSpan.class, HelidonWithSpan.class.getName()); discovery.addAnnotatedType(WithSpanInterceptor.class, WithSpanInterceptor.class.getName()); From b79009d3b3c8e8069ccb45cbb73aaccc9332c5f5 Mon Sep 17 00:00:00 2001 From: Tim Quinn Date: Tue, 13 Feb 2024 07:26:23 -0600 Subject: [PATCH 2/3] One more place to use the AgentDetector --- .../microprofile/telemetry/WithSpanInterceptor.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/microprofile/telemetry/src/main/java/io/helidon/microprofile/telemetry/WithSpanInterceptor.java b/microprofile/telemetry/src/main/java/io/helidon/microprofile/telemetry/WithSpanInterceptor.java index 2888edee038..0e7a0b94182 100644 --- a/microprofile/telemetry/src/main/java/io/helidon/microprofile/telemetry/WithSpanInterceptor.java +++ b/microprofile/telemetry/src/main/java/io/helidon/microprofile/telemetry/WithSpanInterceptor.java @@ -18,6 +18,9 @@ import java.lang.reflect.Method; import java.lang.reflect.Parameter; +import io.helidon.config.Config; +import io.helidon.tracing.providers.opentelemetry.HelidonOpenTelemetry; + import io.opentelemetry.api.trace.Span; import io.opentelemetry.api.trace.SpanBuilder; import io.opentelemetry.api.trace.Tracer; @@ -46,9 +49,9 @@ class WithSpanInterceptor { private final boolean isAgentPresent; @Inject - WithSpanInterceptor(Tracer tracer) { + WithSpanInterceptor(Tracer tracer, Config config) { this.tracer = tracer; - isAgentPresent = Boolean.getBoolean(TelemetryCdiExtension.OTEL_AGENT_PRESENT); + isAgentPresent = HelidonOpenTelemetry.AgentDetector.isAgentPresent(config); } /** From ebccbfad4b03ebb2d1185bc0d0080e89bdc5a754 Mon Sep 17 00:00:00 2001 From: Tim Quinn Date: Tue, 13 Feb 2024 07:43:07 -0600 Subject: [PATCH 3/3] remove duplicate constant declarations --- .../telemetry/TelemetryCdiExtension.java | 5 ----- .../microprofile/telemetry/AgentDetectorTest.java | 8 +++----- .../opentelemetry/HelidonOpenTelemetry.java | 14 +++++++++++--- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/microprofile/telemetry/src/main/java/io/helidon/microprofile/telemetry/TelemetryCdiExtension.java b/microprofile/telemetry/src/main/java/io/helidon/microprofile/telemetry/TelemetryCdiExtension.java index 8bf16b07e42..a087a85bcb2 100644 --- a/microprofile/telemetry/src/main/java/io/helidon/microprofile/telemetry/TelemetryCdiExtension.java +++ b/microprofile/telemetry/src/main/java/io/helidon/microprofile/telemetry/TelemetryCdiExtension.java @@ -28,11 +28,6 @@ */ public class TelemetryCdiExtension implements Extension { - /** - * Property name indicating the presence of the OpenTelemetry Java agent. - */ - static final String OTEL_AGENT_PRESENT = "otel.agent.present"; - private static final System.Logger LOGGER = System.getLogger(TelemetryCdiExtension.class.getName()); /** diff --git a/microprofile/telemetry/src/test/java/io/helidon/microprofile/telemetry/AgentDetectorTest.java b/microprofile/telemetry/src/test/java/io/helidon/microprofile/telemetry/AgentDetectorTest.java index 8905296cc59..be71ad54d0b 100644 --- a/microprofile/telemetry/src/test/java/io/helidon/microprofile/telemetry/AgentDetectorTest.java +++ b/microprofile/telemetry/src/test/java/io/helidon/microprofile/telemetry/AgentDetectorTest.java @@ -36,10 +36,8 @@ @AddExtension(ServerCdiExtension.class) class AgentDetectorTest { - public static final String IO_OPENTELEMETRY_JAVAAGENT = "io.opentelemetry.javaagent"; - @Test - @AddConfig(key = TelemetryCdiExtension.OTEL_AGENT_PRESENT, value = "true") + @AddConfig(key = HelidonOpenTelemetry.OTEL_AGENT_PRESENT_PROPERTY, value = "true") void shouldBeNoOpTelemetry(){ Config config = CDI.current().select(Config.class).get(); boolean present = HelidonOpenTelemetry.AgentDetector.isAgentPresent(config); @@ -47,7 +45,7 @@ void shouldBeNoOpTelemetry(){ } @Test - @AddConfig(key = TelemetryCdiExtension.OTEL_AGENT_PRESENT, value = "false") + @AddConfig(key = HelidonOpenTelemetry.OTEL_AGENT_PRESENT_PROPERTY, value = "false") void shouldNotBeNoOpTelemetry(){ Config config = CDI.current().select(Config.class).get(); boolean present = HelidonOpenTelemetry.AgentDetector.isAgentPresent(config); @@ -56,7 +54,7 @@ void shouldNotBeNoOpTelemetry(){ @Test void checkEnvVariable(){ - System.setProperty(IO_OPENTELEMETRY_JAVAAGENT, "true"); + System.setProperty(HelidonOpenTelemetry.IO_OPENTELEMETRY_JAVAAGENT, "true"); Config config = CDI.current().select(Config.class).get(); boolean present = HelidonOpenTelemetry.AgentDetector.isAgentPresent(config); assertThat(present, is(true)); diff --git a/tracing/providers/opentelemetry/src/main/java/io/helidon/tracing/providers/opentelemetry/HelidonOpenTelemetry.java b/tracing/providers/opentelemetry/src/main/java/io/helidon/tracing/providers/opentelemetry/HelidonOpenTelemetry.java index 8b3d18d7688..b61a833f39d 100644 --- a/tracing/providers/opentelemetry/src/main/java/io/helidon/tracing/providers/opentelemetry/HelidonOpenTelemetry.java +++ b/tracing/providers/opentelemetry/src/main/java/io/helidon/tracing/providers/opentelemetry/HelidonOpenTelemetry.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, 2023 Oracle and/or its affiliates. + * Copyright (c) 2022, 2024 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,9 +32,17 @@ */ public final class HelidonOpenTelemetry { + /** + * OpenTelemetry property for indicating if the Java agent is present. + */ + public static final String OTEL_AGENT_PRESENT_PROPERTY = "otel.agent.present"; + + /** + * OpenTelemetry property for the Java agent. + */ + public static final String IO_OPENTELEMETRY_JAVAAGENT = "io.opentelemetry.javaagent"; + private static final System.Logger LOGGER = System.getLogger(HelidonOpenTelemetry.class.getName()); - private static final String OTEL_AGENT_PRESENT_PROPERTY = "otel.agent.present"; - private static final String IO_OPENTELEMETRY_JAVAAGENT = "io.opentelemetry.javaagent"; private HelidonOpenTelemetry() { } /**