From eed12e580584f506562e51efb0c704f987216a0d Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Sun, 8 Dec 2024 17:13:13 -0800 Subject: [PATCH 1/5] Move experimental methods out of public API --- .../ApacheHttpClientTelemetryBuilder.java | 5 ++ .../v4_3/internal/Experimental.java | 55 ++++++++++++ .../JavaHttpClientTelemetryBuilder.java | 5 ++ .../httpclient/internal/Experimental.java | 55 ++++++++++++ .../v12_0/JettyClientTelemetryBuilder.java | 4 + .../v12_0/internal/Experimental.java | 55 ++++++++++++ .../v9_2/JettyClientTelemetryBuilder.java | 4 + .../v9_2/internal/Experimental.java | 55 ++++++++++++ .../v4_1/NettyClientTelemetryBuilder.java | 26 ++++-- .../v4_1/NettyServerTelemetryBuilder.java | 4 + .../netty/v4_1/internal/Experimental.java | 86 +++++++++++++++++++ .../okhttp/v3_0/OkHttpTelemetryBuilder.java | 4 + .../okhttp/v3_0/internal/Experimental.java | 55 ++++++++++++ .../restlet/v1_1/RestletTelemetryBuilder.java | 4 + .../restlet/v1_1/internal/Experimental.java | 55 ++++++++++++ .../restlet/v2_0/RestletTelemetryBuilder.java | 4 + .../restlet/v2_0/internal/Experimental.java | 55 ++++++++++++ .../web/v3_1/SpringWebTelemetryBuilder.java | 4 + .../web/v3_1/internal/Experimental.java | 55 ++++++++++++ .../v5_3/SpringWebMvcTelemetryBuilder.java | 4 + .../webmvc/v5_3/internal/Experimental.java | 55 ++++++++++++ .../v6_0/SpringWebMvcTelemetryBuilder.java | 4 + .../webmvc/v6_0/internal/Experimental.java | 55 ++++++++++++ 23 files changed, 700 insertions(+), 8 deletions(-) create mode 100644 instrumentation/apache-httpclient/apache-httpclient-4.3/library/src/main/java/io/opentelemetry/instrumentation/apachehttpclient/v4_3/internal/Experimental.java create mode 100644 instrumentation/java-http-client/library/src/main/java/io/opentelemetry/instrumentation/httpclient/internal/Experimental.java create mode 100644 instrumentation/jetty-httpclient/jetty-httpclient-12.0/library/src/main/java/io/opentelemetry/instrumentation/jetty/httpclient/v12_0/internal/Experimental.java create mode 100644 instrumentation/jetty-httpclient/jetty-httpclient-9.2/library/src/main/java/io/opentelemetry/instrumentation/jetty/httpclient/v9_2/internal/Experimental.java create mode 100644 instrumentation/netty/netty-4.1/library/src/main/java/io/opentelemetry/instrumentation/netty/v4_1/internal/Experimental.java create mode 100644 instrumentation/okhttp/okhttp-3.0/library/src/main/java/io/opentelemetry/instrumentation/okhttp/v3_0/internal/Experimental.java create mode 100644 instrumentation/restlet/restlet-1.1/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_1/internal/Experimental.java create mode 100644 instrumentation/restlet/restlet-2.0/library/src/main/java/io/opentelemetry/instrumentation/restlet/v2_0/internal/Experimental.java create mode 100644 instrumentation/spring/spring-web/spring-web-3.1/library/src/main/java/io/opentelemetry/instrumentation/spring/web/v3_1/internal/Experimental.java create mode 100644 instrumentation/spring/spring-webmvc/spring-webmvc-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v5_3/internal/Experimental.java create mode 100644 instrumentation/spring/spring-webmvc/spring-webmvc-6.0/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v6_0/internal/Experimental.java diff --git a/instrumentation/apache-httpclient/apache-httpclient-4.3/library/src/main/java/io/opentelemetry/instrumentation/apachehttpclient/v4_3/ApacheHttpClientTelemetryBuilder.java b/instrumentation/apache-httpclient/apache-httpclient-4.3/library/src/main/java/io/opentelemetry/instrumentation/apachehttpclient/v4_3/ApacheHttpClientTelemetryBuilder.java index 1d0d497317b9..69ca172280c7 100644 --- a/instrumentation/apache-httpclient/apache-httpclient-4.3/library/src/main/java/io/opentelemetry/instrumentation/apachehttpclient/v4_3/ApacheHttpClientTelemetryBuilder.java +++ b/instrumentation/apache-httpclient/apache-httpclient-4.3/library/src/main/java/io/opentelemetry/instrumentation/apachehttpclient/v4_3/ApacheHttpClientTelemetryBuilder.java @@ -7,6 +7,7 @@ import com.google.errorprone.annotations.CanIgnoreReturnValue; import io.opentelemetry.api.OpenTelemetry; +import io.opentelemetry.instrumentation.apachehttpclient.v4_3.internal.Experimental; import io.opentelemetry.instrumentation.api.incubator.builder.internal.DefaultHttpClientInstrumenterBuilder; import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor; @@ -88,7 +89,11 @@ public ApacheHttpClientTelemetryBuilder setKnownMethods(Set knownMethods * * @param emitExperimentalHttpClientMetrics {@code true} if the experimental HTTP client metrics * are to be emitted. + * @deprecated Use {@link + * Experimental#setEmitExperimentalTelemetry(ApacheHttpClientTelemetryBuilder, boolean)} + * instead. */ + @Deprecated @CanIgnoreReturnValue public ApacheHttpClientTelemetryBuilder setEmitExperimentalHttpClientMetrics( boolean emitExperimentalHttpClientMetrics) { diff --git a/instrumentation/apache-httpclient/apache-httpclient-4.3/library/src/main/java/io/opentelemetry/instrumentation/apachehttpclient/v4_3/internal/Experimental.java b/instrumentation/apache-httpclient/apache-httpclient-4.3/library/src/main/java/io/opentelemetry/instrumentation/apachehttpclient/v4_3/internal/Experimental.java new file mode 100644 index 000000000000..3e25db918680 --- /dev/null +++ b/instrumentation/apache-httpclient/apache-httpclient-4.3/library/src/main/java/io/opentelemetry/instrumentation/apachehttpclient/v4_3/internal/Experimental.java @@ -0,0 +1,55 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.apachehttpclient.v4_3.internal; + +import static java.util.logging.Level.FINE; + +import io.opentelemetry.instrumentation.apachehttpclient.v4_3.ApacheHttpClientTelemetryBuilder; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.logging.Logger; +import javax.annotation.Nullable; + +/** + * This class is internal and is hence not for public use. Its APIs are unstable and can change at + * any time. + */ +// TODO (trask) update the above javadoc similar to +// https://github.com/open-telemetry/opentelemetry-java/pull/6886 +public class Experimental { + + private static final Logger logger = Logger.getLogger(Experimental.class.getName()); + + @Nullable + private static final Method emitExperimentalTelemetryMethod = + getEmitExperimentalTelemetryMethod(); + + public void setEmitExperimentalTelemetry( + ApacheHttpClientTelemetryBuilder builder, boolean emitExperimentalTelemetry) { + + if (emitExperimentalTelemetryMethod != null) { + try { + emitExperimentalTelemetryMethod.invoke(builder, emitExperimentalTelemetry); + } catch (IllegalAccessException | InvocationTargetException e) { + logger.log(FINE, e.getMessage(), e); + } + } + } + + @Nullable + private static Method getEmitExperimentalTelemetryMethod() { + try { + Method method = + ApacheHttpClientTelemetryBuilder.class.getDeclaredMethod( + "setEmitExperimentalHttpClientMetrics", boolean.class); + method.setAccessible(true); + return method; + } catch (NoSuchMethodException e) { + logger.log(FINE, e.getMessage(), e); + return null; + } + } +} diff --git a/instrumentation/java-http-client/library/src/main/java/io/opentelemetry/instrumentation/httpclient/JavaHttpClientTelemetryBuilder.java b/instrumentation/java-http-client/library/src/main/java/io/opentelemetry/instrumentation/httpclient/JavaHttpClientTelemetryBuilder.java index ae2040ffcc96..898439786d77 100644 --- a/instrumentation/java-http-client/library/src/main/java/io/opentelemetry/instrumentation/httpclient/JavaHttpClientTelemetryBuilder.java +++ b/instrumentation/java-http-client/library/src/main/java/io/opentelemetry/instrumentation/httpclient/JavaHttpClientTelemetryBuilder.java @@ -11,6 +11,7 @@ import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor; import io.opentelemetry.instrumentation.api.semconv.http.HttpClientAttributesExtractorBuilder; +import io.opentelemetry.instrumentation.httpclient.internal.Experimental; import io.opentelemetry.instrumentation.httpclient.internal.HttpHeadersSetter; import io.opentelemetry.instrumentation.httpclient.internal.JavaHttpClientInstrumenterBuilderFactory; import java.net.http.HttpRequest; @@ -86,7 +87,11 @@ public JavaHttpClientTelemetryBuilder setKnownMethods(Set knownMethods) * * @param emitExperimentalHttpClientMetrics {@code true} if the experimental HTTP client metrics * are to be emitted. + * @deprecated Use {@link + * Experimental#setEmitExperimentalTelemetry(JavaHttpClientTelemetryBuilder, boolean)} + * instead. */ + @Deprecated @CanIgnoreReturnValue public JavaHttpClientTelemetryBuilder setEmitExperimentalHttpClientMetrics( boolean emitExperimentalHttpClientMetrics) { diff --git a/instrumentation/java-http-client/library/src/main/java/io/opentelemetry/instrumentation/httpclient/internal/Experimental.java b/instrumentation/java-http-client/library/src/main/java/io/opentelemetry/instrumentation/httpclient/internal/Experimental.java new file mode 100644 index 000000000000..f3763e8af500 --- /dev/null +++ b/instrumentation/java-http-client/library/src/main/java/io/opentelemetry/instrumentation/httpclient/internal/Experimental.java @@ -0,0 +1,55 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.httpclient.internal; + +import static java.util.logging.Level.FINE; + +import io.opentelemetry.instrumentation.httpclient.JavaHttpClientTelemetryBuilder; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.logging.Logger; +import javax.annotation.Nullable; + +/** + * This class is internal and is hence not for public use. Its APIs are unstable and can change at + * any time. + */ +// TODO (trask) update the above javadoc similar to +// https://github.com/open-telemetry/opentelemetry-java/pull/6886 +public class Experimental { + + private static final Logger logger = Logger.getLogger(Experimental.class.getName()); + + @Nullable + private static final Method emitExperimentalTelemetryMethod = + getEmitExperimentalTelemetryMethod(); + + public void setEmitExperimentalTelemetry( + JavaHttpClientTelemetryBuilder builder, boolean emitExperimentalTelemetry) { + + if (emitExperimentalTelemetryMethod != null) { + try { + emitExperimentalTelemetryMethod.invoke(builder, emitExperimentalTelemetry); + } catch (IllegalAccessException | InvocationTargetException e) { + logger.log(FINE, e.getMessage(), e); + } + } + } + + @Nullable + private static Method getEmitExperimentalTelemetryMethod() { + try { + Method method = + JavaHttpClientTelemetryBuilder.class.getDeclaredMethod( + "setEmitExperimentalHttpClientMetrics", boolean.class); + method.setAccessible(true); + return method; + } catch (NoSuchMethodException e) { + logger.log(FINE, e.getMessage(), e); + return null; + } + } +} diff --git a/instrumentation/jetty-httpclient/jetty-httpclient-12.0/library/src/main/java/io/opentelemetry/instrumentation/jetty/httpclient/v12_0/JettyClientTelemetryBuilder.java b/instrumentation/jetty-httpclient/jetty-httpclient-12.0/library/src/main/java/io/opentelemetry/instrumentation/jetty/httpclient/v12_0/JettyClientTelemetryBuilder.java index ec5c8b379d50..3590441d3791 100644 --- a/instrumentation/jetty-httpclient/jetty-httpclient-12.0/library/src/main/java/io/opentelemetry/instrumentation/jetty/httpclient/v12_0/JettyClientTelemetryBuilder.java +++ b/instrumentation/jetty-httpclient/jetty-httpclient-12.0/library/src/main/java/io/opentelemetry/instrumentation/jetty/httpclient/v12_0/JettyClientTelemetryBuilder.java @@ -11,6 +11,7 @@ import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor; import io.opentelemetry.instrumentation.api.semconv.http.HttpClientAttributesExtractorBuilder; +import io.opentelemetry.instrumentation.jetty.httpclient.v12_0.internal.Experimental; import io.opentelemetry.instrumentation.jetty.httpclient.v12_0.internal.JettyHttpClientInstrumenterBuilderFactory; import java.util.List; import java.util.Set; @@ -101,7 +102,10 @@ public JettyClientTelemetryBuilder setKnownMethods(Set knownMethods) { * * @param emitExperimentalHttpClientMetrics {@code true} if the experimental HTTP client metrics * are to be emitted. + * @deprecated Use {@link Experimental#setEmitExperimentalTelemetry(JettyClientTelemetryBuilder, + * boolean)} instead. */ + @Deprecated @CanIgnoreReturnValue public JettyClientTelemetryBuilder setEmitExperimentalHttpClientMetrics( boolean emitExperimentalHttpClientMetrics) { diff --git a/instrumentation/jetty-httpclient/jetty-httpclient-12.0/library/src/main/java/io/opentelemetry/instrumentation/jetty/httpclient/v12_0/internal/Experimental.java b/instrumentation/jetty-httpclient/jetty-httpclient-12.0/library/src/main/java/io/opentelemetry/instrumentation/jetty/httpclient/v12_0/internal/Experimental.java new file mode 100644 index 000000000000..2fba34f47d6a --- /dev/null +++ b/instrumentation/jetty-httpclient/jetty-httpclient-12.0/library/src/main/java/io/opentelemetry/instrumentation/jetty/httpclient/v12_0/internal/Experimental.java @@ -0,0 +1,55 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.jetty.httpclient.v12_0.internal; + +import static java.util.logging.Level.FINE; + +import io.opentelemetry.instrumentation.jetty.httpclient.v12_0.JettyClientTelemetryBuilder; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.logging.Logger; +import javax.annotation.Nullable; + +/** + * This class is internal and is hence not for public use. Its APIs are unstable and can change at + * any time. + */ +// TODO (trask) update the above javadoc similar to +// https://github.com/open-telemetry/opentelemetry-java/pull/6886 +public class Experimental { + + private static final Logger logger = Logger.getLogger(Experimental.class.getName()); + + @Nullable + private static final Method emitExperimentalTelemetryMethod = + getEmitExperimentalTelemetryMethod(); + + public void setEmitExperimentalTelemetry( + JettyClientTelemetryBuilder builder, boolean emitExperimentalTelemetry) { + + if (emitExperimentalTelemetryMethod != null) { + try { + emitExperimentalTelemetryMethod.invoke(builder, emitExperimentalTelemetry); + } catch (IllegalAccessException | InvocationTargetException e) { + logger.log(FINE, e.getMessage(), e); + } + } + } + + @Nullable + private static Method getEmitExperimentalTelemetryMethod() { + try { + Method method = + JettyClientTelemetryBuilder.class.getDeclaredMethod( + "setEmitExperimentalHttpClientMetrics", boolean.class); + method.setAccessible(true); + return method; + } catch (NoSuchMethodException e) { + logger.log(FINE, e.getMessage(), e); + return null; + } + } +} diff --git a/instrumentation/jetty-httpclient/jetty-httpclient-9.2/library/src/main/java/io/opentelemetry/instrumentation/jetty/httpclient/v9_2/JettyClientTelemetryBuilder.java b/instrumentation/jetty-httpclient/jetty-httpclient-9.2/library/src/main/java/io/opentelemetry/instrumentation/jetty/httpclient/v9_2/JettyClientTelemetryBuilder.java index a976fe7a2f30..dde3a23e67d8 100644 --- a/instrumentation/jetty-httpclient/jetty-httpclient-9.2/library/src/main/java/io/opentelemetry/instrumentation/jetty/httpclient/v9_2/JettyClientTelemetryBuilder.java +++ b/instrumentation/jetty-httpclient/jetty-httpclient-9.2/library/src/main/java/io/opentelemetry/instrumentation/jetty/httpclient/v9_2/JettyClientTelemetryBuilder.java @@ -11,6 +11,7 @@ import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor; import io.opentelemetry.instrumentation.api.semconv.http.HttpClientAttributesExtractorBuilder; +import io.opentelemetry.instrumentation.jetty.httpclient.v9_2.internal.Experimental; import io.opentelemetry.instrumentation.jetty.httpclient.v9_2.internal.JettyHttpClientInstrumenterBuilderFactory; import java.util.List; import java.util.Set; @@ -101,7 +102,10 @@ public JettyClientTelemetryBuilder setKnownMethods(Set knownMethods) { * * @param emitExperimentalHttpClientMetrics {@code true} if the experimental HTTP client metrics * are to be emitted. + * @deprecated Use {@link Experimental#setEmitExperimentalTelemetry(JettyClientTelemetryBuilder, + * boolean)} instead. */ + @Deprecated @CanIgnoreReturnValue public JettyClientTelemetryBuilder setEmitExperimentalHttpClientMetrics( boolean emitExperimentalHttpClientMetrics) { diff --git a/instrumentation/jetty-httpclient/jetty-httpclient-9.2/library/src/main/java/io/opentelemetry/instrumentation/jetty/httpclient/v9_2/internal/Experimental.java b/instrumentation/jetty-httpclient/jetty-httpclient-9.2/library/src/main/java/io/opentelemetry/instrumentation/jetty/httpclient/v9_2/internal/Experimental.java new file mode 100644 index 000000000000..dbe83f1d11d8 --- /dev/null +++ b/instrumentation/jetty-httpclient/jetty-httpclient-9.2/library/src/main/java/io/opentelemetry/instrumentation/jetty/httpclient/v9_2/internal/Experimental.java @@ -0,0 +1,55 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.jetty.httpclient.v9_2.internal; + +import static java.util.logging.Level.FINE; + +import io.opentelemetry.instrumentation.jetty.httpclient.v9_2.JettyClientTelemetryBuilder; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.logging.Logger; +import javax.annotation.Nullable; + +/** + * This class is internal and is hence not for public use. Its APIs are unstable and can change at + * any time. + */ +// TODO (trask) update the above javadoc similar to +// https://github.com/open-telemetry/opentelemetry-java/pull/6886 +public class Experimental { + + private static final Logger logger = Logger.getLogger(Experimental.class.getName()); + + @Nullable + private static final Method emitExperimentalTelemetryMethod = + getEmitExperimentalTelemetryMethod(); + + public void setEmitExperimentalTelemetry( + JettyClientTelemetryBuilder builder, boolean emitExperimentalTelemetry) { + + if (emitExperimentalTelemetryMethod != null) { + try { + emitExperimentalTelemetryMethod.invoke(builder, emitExperimentalTelemetry); + } catch (IllegalAccessException | InvocationTargetException e) { + logger.log(FINE, e.getMessage(), e); + } + } + } + + @Nullable + private static Method getEmitExperimentalTelemetryMethod() { + try { + Method method = + JettyClientTelemetryBuilder.class.getDeclaredMethod( + "setEmitExperimentalHttpClientMetrics", boolean.class); + method.setAccessible(true); + return method; + } catch (NoSuchMethodException e) { + logger.log(FINE, e.getMessage(), e); + return null; + } + } +} diff --git a/instrumentation/netty/netty-4.1/library/src/main/java/io/opentelemetry/instrumentation/netty/v4_1/NettyClientTelemetryBuilder.java b/instrumentation/netty/netty-4.1/library/src/main/java/io/opentelemetry/instrumentation/netty/v4_1/NettyClientTelemetryBuilder.java index a7e3b8d61bb3..012775aa1c75 100644 --- a/instrumentation/netty/netty-4.1/library/src/main/java/io/opentelemetry/instrumentation/netty/v4_1/NettyClientTelemetryBuilder.java +++ b/instrumentation/netty/netty-4.1/library/src/main/java/io/opentelemetry/instrumentation/netty/v4_1/NettyClientTelemetryBuilder.java @@ -16,6 +16,7 @@ import io.opentelemetry.instrumentation.netty.v4.common.internal.client.NettyClientInstrumenterBuilderFactory; import io.opentelemetry.instrumentation.netty.v4.common.internal.client.NettyClientInstrumenterFactory; import io.opentelemetry.instrumentation.netty.v4.common.internal.client.NettyConnectionInstrumentationFlag; +import io.opentelemetry.instrumentation.netty.v4_1.internal.Experimental; import java.util.List; import java.util.Set; import java.util.function.Function; @@ -24,17 +25,22 @@ public final class NettyClientTelemetryBuilder { private final DefaultHttpClientInstrumenterBuilder builder; - private boolean emitExperimentalHttpClientEvents = false; + private boolean emitExperimentalTelemetry = false; NettyClientTelemetryBuilder(OpenTelemetry openTelemetry) { builder = NettyClientInstrumenterBuilderFactory.create("io.opentelemetry.netty-4.1", openTelemetry); } + /** + * @deprecated Use {@link Experimental#setEmitExperimentalTelemetry(NettyClientTelemetryBuilder, + * boolean)} instead. + */ + @Deprecated @CanIgnoreReturnValue public NettyClientTelemetryBuilder setEmitExperimentalHttpClientEvents( - boolean emitExperimentalHttpClientEvents) { - this.emitExperimentalHttpClientEvents = emitExperimentalHttpClientEvents; + boolean emitExperimentalTelemetry) { + this.emitExperimentalTelemetry = emitExperimentalTelemetry; return this; } @@ -95,13 +101,17 @@ public NettyClientTelemetryBuilder setKnownMethods(Set knownMethods) { /** * Configures the instrumentation to emit experimental HTTP client metrics. * - * @param emitExperimentalHttpClientMetrics {@code true} if the experimental HTTP client metrics - * are to be emitted. + * @param emitExperimentalTelemetry {@code true} if the experimental HTTP client metrics are to be + * emitted. + * @deprecated Use {@link Experimental#setEmitExperimentalTelemetry(NettyClientTelemetryBuilder, + * boolean)} instead. */ + @Deprecated @CanIgnoreReturnValue public NettyClientTelemetryBuilder setEmitExperimentalHttpClientMetrics( - boolean emitExperimentalHttpClientMetrics) { - builder.setEmitExperimentalHttpClientMetrics(emitExperimentalHttpClientMetrics); + boolean emitExperimentalTelemetry) { + builder.setEmitExperimentalHttpClientMetrics(emitExperimentalTelemetry); + this.emitExperimentalTelemetry = emitExperimentalTelemetry; return this; } @@ -124,6 +134,6 @@ public NettyClientTelemetry build() { NettyConnectionInstrumentationFlag.DISABLED, NettyConnectionInstrumentationFlag.DISABLED) .instrumenter(), - emitExperimentalHttpClientEvents); + emitExperimentalTelemetry); } } diff --git a/instrumentation/netty/netty-4.1/library/src/main/java/io/opentelemetry/instrumentation/netty/v4_1/NettyServerTelemetryBuilder.java b/instrumentation/netty/netty-4.1/library/src/main/java/io/opentelemetry/instrumentation/netty/v4_1/NettyServerTelemetryBuilder.java index 874bcb586bed..6437a540b106 100644 --- a/instrumentation/netty/netty-4.1/library/src/main/java/io/opentelemetry/instrumentation/netty/v4_1/NettyServerTelemetryBuilder.java +++ b/instrumentation/netty/netty-4.1/library/src/main/java/io/opentelemetry/instrumentation/netty/v4_1/NettyServerTelemetryBuilder.java @@ -13,6 +13,7 @@ import io.opentelemetry.instrumentation.netty.v4.common.HttpRequestAndChannel; import io.opentelemetry.instrumentation.netty.v4.common.internal.server.HttpRequestHeadersGetter; import io.opentelemetry.instrumentation.netty.v4.common.internal.server.NettyHttpServerAttributesGetter; +import io.opentelemetry.instrumentation.netty.v4_1.internal.Experimental; import io.opentelemetry.instrumentation.netty.v4_1.internal.ProtocolEventHandler; import io.opentelemetry.instrumentation.netty.v4_1.internal.server.NettyServerInstrumenterBuilderUtil; import java.util.List; @@ -99,7 +100,10 @@ public NettyServerTelemetryBuilder setKnownMethods(Set knownMethods) { * * @param emitExperimentalHttpServerMetrics {@code true} if the experimental HTTP server metrics * are to be emitted. + * @deprecated Use {@link Experimental#setEmitExperimentalTelemetry(NettyServerTelemetryBuilder, + * boolean)} instead. */ + @Deprecated @CanIgnoreReturnValue public NettyServerTelemetryBuilder setEmitExperimentalHttpServerMetrics( boolean emitExperimentalHttpServerMetrics) { diff --git a/instrumentation/netty/netty-4.1/library/src/main/java/io/opentelemetry/instrumentation/netty/v4_1/internal/Experimental.java b/instrumentation/netty/netty-4.1/library/src/main/java/io/opentelemetry/instrumentation/netty/v4_1/internal/Experimental.java new file mode 100644 index 000000000000..08d4fc12417d --- /dev/null +++ b/instrumentation/netty/netty-4.1/library/src/main/java/io/opentelemetry/instrumentation/netty/v4_1/internal/Experimental.java @@ -0,0 +1,86 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.netty.v4_1.internal; + +import static java.util.logging.Level.FINE; + +import io.opentelemetry.instrumentation.netty.v4_1.NettyClientTelemetryBuilder; +import io.opentelemetry.instrumentation.netty.v4_1.NettyServerTelemetryBuilder; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.logging.Logger; +import javax.annotation.Nullable; + +/** + * This class is internal and is hence not for public use. Its APIs are unstable and can change at + * any time. + */ +// TODO (trask) update the above javadoc similar to +// https://github.com/open-telemetry/opentelemetry-java/pull/6886 +public class Experimental { + + private static final Logger logger = Logger.getLogger(Experimental.class.getName()); + + @Nullable + private static final Method emitExperimentalClientTelemetryMethod = + getEmitExperimentalClientTelemetryMethod(); + + @Nullable + private static final Method emitExperimentalServerTelemetryMethod = + getEmitExperimentalServerTelemetryMethod(); + + public void setEmitExperimentalTelemetry( + NettyClientTelemetryBuilder builder, boolean emitExperimentalTelemetry) { + + if (emitExperimentalClientTelemetryMethod != null) { + try { + emitExperimentalClientTelemetryMethod.invoke(builder, emitExperimentalTelemetry); + } catch (IllegalAccessException | InvocationTargetException e) { + logger.log(FINE, e.getMessage(), e); + } + } + } + + public void setEmitExperimentalTelemetry( + NettyServerTelemetryBuilder builder, boolean emitExperimentalTelemetry) { + + if (emitExperimentalServerTelemetryMethod != null) { + try { + emitExperimentalServerTelemetryMethod.invoke(builder, emitExperimentalTelemetry); + } catch (IllegalAccessException | InvocationTargetException e) { + logger.log(FINE, e.getMessage(), e); + } + } + } + + @Nullable + private static Method getEmitExperimentalClientTelemetryMethod() { + try { + Method method = + NettyClientTelemetryBuilder.class.getDeclaredMethod( + "setEmitExperimentalHttpClientMetrics", boolean.class); + method.setAccessible(true); + return method; + } catch (NoSuchMethodException e) { + logger.log(FINE, e.getMessage(), e); + return null; + } + } + + @Nullable + private static Method getEmitExperimentalServerTelemetryMethod() { + try { + Method method = + NettyServerTelemetryBuilder.class.getDeclaredMethod( + "setEmitExperimentalHttpServerMetrics", boolean.class); + method.setAccessible(true); + return method; + } catch (NoSuchMethodException e) { + logger.log(FINE, e.getMessage(), e); + return null; + } + } +} diff --git a/instrumentation/okhttp/okhttp-3.0/library/src/main/java/io/opentelemetry/instrumentation/okhttp/v3_0/OkHttpTelemetryBuilder.java b/instrumentation/okhttp/okhttp-3.0/library/src/main/java/io/opentelemetry/instrumentation/okhttp/v3_0/OkHttpTelemetryBuilder.java index 3595aaa91a20..48a97f84c956 100644 --- a/instrumentation/okhttp/okhttp-3.0/library/src/main/java/io/opentelemetry/instrumentation/okhttp/v3_0/OkHttpTelemetryBuilder.java +++ b/instrumentation/okhttp/okhttp-3.0/library/src/main/java/io/opentelemetry/instrumentation/okhttp/v3_0/OkHttpTelemetryBuilder.java @@ -11,6 +11,7 @@ import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor; import io.opentelemetry.instrumentation.api.semconv.http.HttpClientAttributesExtractorBuilder; +import io.opentelemetry.instrumentation.okhttp.v3_0.internal.Experimental; import io.opentelemetry.instrumentation.okhttp.v3_0.internal.OkHttpClientInstrumenterBuilderFactory; import java.util.List; import java.util.Set; @@ -86,7 +87,10 @@ public OkHttpTelemetryBuilder setKnownMethods(Set knownMethods) { * * @param emitExperimentalHttpClientMetrics {@code true} if the experimental HTTP client metrics * are to be emitted. + * @deprecated Use {@link Experimental#setEmitExperimentalTelemetry(OkHttpTelemetryBuilder, + * boolean)} instead. */ + @Deprecated @CanIgnoreReturnValue public OkHttpTelemetryBuilder setEmitExperimentalHttpClientMetrics( boolean emitExperimentalHttpClientMetrics) { diff --git a/instrumentation/okhttp/okhttp-3.0/library/src/main/java/io/opentelemetry/instrumentation/okhttp/v3_0/internal/Experimental.java b/instrumentation/okhttp/okhttp-3.0/library/src/main/java/io/opentelemetry/instrumentation/okhttp/v3_0/internal/Experimental.java new file mode 100644 index 000000000000..aaea920b4e9e --- /dev/null +++ b/instrumentation/okhttp/okhttp-3.0/library/src/main/java/io/opentelemetry/instrumentation/okhttp/v3_0/internal/Experimental.java @@ -0,0 +1,55 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.okhttp.v3_0.internal; + +import static java.util.logging.Level.FINE; + +import io.opentelemetry.instrumentation.okhttp.v3_0.OkHttpTelemetryBuilder; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.logging.Logger; +import javax.annotation.Nullable; + +/** + * This class is internal and is hence not for public use. Its APIs are unstable and can change at + * any time. + */ +// TODO (trask) update the above javadoc similar to +// https://github.com/open-telemetry/opentelemetry-java/pull/6886 +public class Experimental { + + private static final Logger logger = Logger.getLogger(Experimental.class.getName()); + + @Nullable + private static final Method emitExperimentalTelemetryMethod = + getEmitExperimentalTelemetryMethod(); + + public void setEmitExperimentalTelemetry( + OkHttpTelemetryBuilder builder, boolean emitExperimentalTelemetry) { + + if (emitExperimentalTelemetryMethod != null) { + try { + emitExperimentalTelemetryMethod.invoke(builder, emitExperimentalTelemetry); + } catch (IllegalAccessException | InvocationTargetException e) { + logger.log(FINE, e.getMessage(), e); + } + } + } + + @Nullable + private static Method getEmitExperimentalTelemetryMethod() { + try { + Method method = + OkHttpTelemetryBuilder.class.getDeclaredMethod( + "setEmitExperimentalHttpClientMetrics", boolean.class); + method.setAccessible(true); + return method; + } catch (NoSuchMethodException e) { + logger.log(FINE, e.getMessage(), e); + return null; + } + } +} diff --git a/instrumentation/restlet/restlet-1.1/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_1/RestletTelemetryBuilder.java b/instrumentation/restlet/restlet-1.1/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_1/RestletTelemetryBuilder.java index 3ff61af4a73f..b7e40595ea9e 100644 --- a/instrumentation/restlet/restlet-1.1/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_1/RestletTelemetryBuilder.java +++ b/instrumentation/restlet/restlet-1.1/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_1/RestletTelemetryBuilder.java @@ -11,6 +11,7 @@ import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor; import io.opentelemetry.instrumentation.api.semconv.http.HttpServerAttributesExtractorBuilder; +import io.opentelemetry.instrumentation.restlet.v1_1.internal.Experimental; import io.opentelemetry.instrumentation.restlet.v1_1.internal.RestletTelemetryBuilderFactory; import java.util.List; import java.util.Set; @@ -84,7 +85,10 @@ public RestletTelemetryBuilder setKnownMethods(Set knownMethods) { * * @param emitExperimentalHttpServerMetrics {@code true} if the experimental HTTP server metrics * are to be emitted. + * @deprecated Use {@link Experimental#setEmitExperimentalTelemetry(RestletTelemetryBuilder, + * boolean)} instead. */ + @Deprecated @CanIgnoreReturnValue public RestletTelemetryBuilder setEmitExperimentalHttpServerMetrics( boolean emitExperimentalHttpServerMetrics) { diff --git a/instrumentation/restlet/restlet-1.1/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_1/internal/Experimental.java b/instrumentation/restlet/restlet-1.1/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_1/internal/Experimental.java new file mode 100644 index 000000000000..b044c1d8c7fc --- /dev/null +++ b/instrumentation/restlet/restlet-1.1/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_1/internal/Experimental.java @@ -0,0 +1,55 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.restlet.v1_1.internal; + +import static java.util.logging.Level.FINE; + +import io.opentelemetry.instrumentation.restlet.v1_1.RestletTelemetryBuilder; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.logging.Logger; +import javax.annotation.Nullable; + +/** + * This class is internal and is hence not for public use. Its APIs are unstable and can change at + * any time. + */ +// TODO (trask) update the above javadoc similar to +// https://github.com/open-telemetry/opentelemetry-java/pull/6886 +public class Experimental { + + private static final Logger logger = Logger.getLogger(Experimental.class.getName()); + + @Nullable + private static final Method emitExperimentalTelemetryMethod = + getEmitExperimentalTelemetryMethod(); + + public void setEmitExperimentalTelemetry( + RestletTelemetryBuilder builder, boolean emitExperimentalTelemetry) { + + if (emitExperimentalTelemetryMethod != null) { + try { + emitExperimentalTelemetryMethod.invoke(builder, emitExperimentalTelemetry); + } catch (IllegalAccessException | InvocationTargetException e) { + logger.log(FINE, e.getMessage(), e); + } + } + } + + @Nullable + private static Method getEmitExperimentalTelemetryMethod() { + try { + Method method = + RestletTelemetryBuilder.class.getDeclaredMethod( + "setEmitExperimentalHttpServerMetrics", boolean.class); + method.setAccessible(true); + return method; + } catch (NoSuchMethodException e) { + logger.log(FINE, e.getMessage(), e); + return null; + } + } +} diff --git a/instrumentation/restlet/restlet-2.0/library/src/main/java/io/opentelemetry/instrumentation/restlet/v2_0/RestletTelemetryBuilder.java b/instrumentation/restlet/restlet-2.0/library/src/main/java/io/opentelemetry/instrumentation/restlet/v2_0/RestletTelemetryBuilder.java index a933f52cdea4..e705e875b4fc 100644 --- a/instrumentation/restlet/restlet-2.0/library/src/main/java/io/opentelemetry/instrumentation/restlet/v2_0/RestletTelemetryBuilder.java +++ b/instrumentation/restlet/restlet-2.0/library/src/main/java/io/opentelemetry/instrumentation/restlet/v2_0/RestletTelemetryBuilder.java @@ -11,6 +11,7 @@ import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor; import io.opentelemetry.instrumentation.api.semconv.http.HttpServerAttributesExtractorBuilder; +import io.opentelemetry.instrumentation.restlet.v2_0.internal.Experimental; import io.opentelemetry.instrumentation.restlet.v2_0.internal.RestletTelemetryBuilderFactory; import java.util.List; import java.util.Set; @@ -84,7 +85,10 @@ public RestletTelemetryBuilder setKnownMethods(Set knownMethods) { * * @param emitExperimentalHttpServerMetrics {@code true} if the experimental HTTP server metrics * are to be emitted. + * @deprecated Use {@link Experimental#setEmitExperimentalTelemetry(RestletTelemetryBuilder, + * boolean)} instead. */ + @Deprecated @CanIgnoreReturnValue public RestletTelemetryBuilder setEmitExperimentalHttpServerMetrics( boolean emitExperimentalHttpServerMetrics) { diff --git a/instrumentation/restlet/restlet-2.0/library/src/main/java/io/opentelemetry/instrumentation/restlet/v2_0/internal/Experimental.java b/instrumentation/restlet/restlet-2.0/library/src/main/java/io/opentelemetry/instrumentation/restlet/v2_0/internal/Experimental.java new file mode 100644 index 000000000000..b95c021bf651 --- /dev/null +++ b/instrumentation/restlet/restlet-2.0/library/src/main/java/io/opentelemetry/instrumentation/restlet/v2_0/internal/Experimental.java @@ -0,0 +1,55 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.restlet.v2_0.internal; + +import static java.util.logging.Level.FINE; + +import io.opentelemetry.instrumentation.restlet.v2_0.RestletTelemetryBuilder; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.logging.Logger; +import javax.annotation.Nullable; + +/** + * This class is internal and is hence not for public use. Its APIs are unstable and can change at + * any time. + */ +// TODO (trask) update the above javadoc similar to +// https://github.com/open-telemetry/opentelemetry-java/pull/6886 +public class Experimental { + + private static final Logger logger = Logger.getLogger(Experimental.class.getName()); + + @Nullable + private static final Method emitExperimentalTelemetryMethod = + getEmitExperimentalTelemetryMethod(); + + public void setEmitExperimentalTelemetry( + RestletTelemetryBuilder builder, boolean emitExperimentalTelemetry) { + + if (emitExperimentalTelemetryMethod != null) { + try { + emitExperimentalTelemetryMethod.invoke(builder, emitExperimentalTelemetry); + } catch (IllegalAccessException | InvocationTargetException e) { + logger.log(FINE, e.getMessage(), e); + } + } + } + + @Nullable + private static Method getEmitExperimentalTelemetryMethod() { + try { + Method method = + RestletTelemetryBuilder.class.getDeclaredMethod( + "setEmitExperimentalHttpServerMetrics", boolean.class); + method.setAccessible(true); + return method; + } catch (NoSuchMethodException e) { + logger.log(FINE, e.getMessage(), e); + return null; + } + } +} diff --git a/instrumentation/spring/spring-web/spring-web-3.1/library/src/main/java/io/opentelemetry/instrumentation/spring/web/v3_1/SpringWebTelemetryBuilder.java b/instrumentation/spring/spring-web/spring-web-3.1/library/src/main/java/io/opentelemetry/instrumentation/spring/web/v3_1/SpringWebTelemetryBuilder.java index 86771bfa3313..8c0b2176699c 100644 --- a/instrumentation/spring/spring-web/spring-web-3.1/library/src/main/java/io/opentelemetry/instrumentation/spring/web/v3_1/SpringWebTelemetryBuilder.java +++ b/instrumentation/spring/spring-web/spring-web-3.1/library/src/main/java/io/opentelemetry/instrumentation/spring/web/v3_1/SpringWebTelemetryBuilder.java @@ -11,6 +11,7 @@ import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor; import io.opentelemetry.instrumentation.api.semconv.http.HttpClientAttributesExtractorBuilder; +import io.opentelemetry.instrumentation.spring.web.v3_1.internal.Experimental; import io.opentelemetry.instrumentation.spring.web.v3_1.internal.WebTelemetryUtil; import java.util.List; import java.util.Set; @@ -108,7 +109,10 @@ public SpringWebTelemetryBuilder setKnownMethods(Set knownMethods) { * * @param emitExperimentalHttpClientMetrics {@code true} if the experimental HTTP client metrics * are to be emitted. + * @deprecated Use {@link Experimental#setEmitExperimentalTelemetry(SpringWebTelemetryBuilder, + * boolean)} instead. */ + @Deprecated @CanIgnoreReturnValue public SpringWebTelemetryBuilder setEmitExperimentalHttpClientMetrics( boolean emitExperimentalHttpClientMetrics) { diff --git a/instrumentation/spring/spring-web/spring-web-3.1/library/src/main/java/io/opentelemetry/instrumentation/spring/web/v3_1/internal/Experimental.java b/instrumentation/spring/spring-web/spring-web-3.1/library/src/main/java/io/opentelemetry/instrumentation/spring/web/v3_1/internal/Experimental.java new file mode 100644 index 000000000000..1a6fc69b00dc --- /dev/null +++ b/instrumentation/spring/spring-web/spring-web-3.1/library/src/main/java/io/opentelemetry/instrumentation/spring/web/v3_1/internal/Experimental.java @@ -0,0 +1,55 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.spring.web.v3_1.internal; + +import static java.util.logging.Level.FINE; + +import io.opentelemetry.instrumentation.spring.web.v3_1.SpringWebTelemetryBuilder; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.logging.Logger; +import javax.annotation.Nullable; + +/** + * This class is internal and is hence not for public use. Its APIs are unstable and can change at + * any time. + */ +// TODO (trask) update the above javadoc similar to +// https://github.com/open-telemetry/opentelemetry-java/pull/6886 +public class Experimental { + + private static final Logger logger = Logger.getLogger(Experimental.class.getName()); + + @Nullable + private static final Method emitExperimentalTelemetryMethod = + getEmitExperimentalTelemetryMethod(); + + public void setEmitExperimentalTelemetry( + SpringWebTelemetryBuilder builder, boolean emitExperimentalTelemetry) { + + if (emitExperimentalTelemetryMethod != null) { + try { + emitExperimentalTelemetryMethod.invoke(builder, emitExperimentalTelemetry); + } catch (IllegalAccessException | InvocationTargetException e) { + logger.log(FINE, e.getMessage(), e); + } + } + } + + @Nullable + private static Method getEmitExperimentalTelemetryMethod() { + try { + Method method = + SpringWebTelemetryBuilder.class.getDeclaredMethod( + "setEmitExperimentalHttpClientMetrics", boolean.class); + method.setAccessible(true); + return method; + } catch (NoSuchMethodException e) { + logger.log(FINE, e.getMessage(), e); + return null; + } + } +} diff --git a/instrumentation/spring/spring-webmvc/spring-webmvc-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v5_3/SpringWebMvcTelemetryBuilder.java b/instrumentation/spring/spring-webmvc/spring-webmvc-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v5_3/SpringWebMvcTelemetryBuilder.java index 0c31ace56234..ed5b58a38819 100644 --- a/instrumentation/spring/spring-webmvc/spring-webmvc-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v5_3/SpringWebMvcTelemetryBuilder.java +++ b/instrumentation/spring/spring-webmvc/spring-webmvc-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v5_3/SpringWebMvcTelemetryBuilder.java @@ -11,6 +11,7 @@ import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor; import io.opentelemetry.instrumentation.api.semconv.http.HttpServerAttributesExtractorBuilder; +import io.opentelemetry.instrumentation.spring.webmvc.v5_3.internal.Experimental; import io.opentelemetry.instrumentation.spring.webmvc.v5_3.internal.SpringMvcBuilderUtil; import java.util.List; import java.util.Set; @@ -107,7 +108,10 @@ public SpringWebMvcTelemetryBuilder setKnownMethods(Set knownMethods) { * * @param emitExperimentalHttpServerMetrics {@code true} if the experimental HTTP server metrics * are to be emitted. + * @deprecated Use {@link Experimental#setEmitExperimentalTelemetry(SpringWebMvcTelemetryBuilder, + * boolean)} instead. */ + @Deprecated @CanIgnoreReturnValue public SpringWebMvcTelemetryBuilder setEmitExperimentalHttpServerMetrics( boolean emitExperimentalHttpServerMetrics) { diff --git a/instrumentation/spring/spring-webmvc/spring-webmvc-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v5_3/internal/Experimental.java b/instrumentation/spring/spring-webmvc/spring-webmvc-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v5_3/internal/Experimental.java new file mode 100644 index 000000000000..a8c6d348cc0f --- /dev/null +++ b/instrumentation/spring/spring-webmvc/spring-webmvc-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v5_3/internal/Experimental.java @@ -0,0 +1,55 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.spring.webmvc.v5_3.internal; + +import static java.util.logging.Level.FINE; + +import io.opentelemetry.instrumentation.spring.webmvc.v5_3.SpringWebMvcTelemetryBuilder; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.logging.Logger; +import javax.annotation.Nullable; + +/** + * This class is internal and is hence not for public use. Its APIs are unstable and can change at + * any time. + */ +// TODO (trask) update the above javadoc similar to +// https://github.com/open-telemetry/opentelemetry-java/pull/6886 +public class Experimental { + + private static final Logger logger = Logger.getLogger(Experimental.class.getName()); + + @Nullable + private static final Method emitExperimentalTelemetryMethod = + getEmitExperimentalTelemetryMethod(); + + public void setEmitExperimentalTelemetry( + SpringWebMvcTelemetryBuilder builder, boolean emitExperimentalTelemetry) { + + if (emitExperimentalTelemetryMethod != null) { + try { + emitExperimentalTelemetryMethod.invoke(builder, emitExperimentalTelemetry); + } catch (IllegalAccessException | InvocationTargetException e) { + logger.log(FINE, e.getMessage(), e); + } + } + } + + @Nullable + private static Method getEmitExperimentalTelemetryMethod() { + try { + Method method = + SpringWebMvcTelemetryBuilder.class.getDeclaredMethod( + "setEmitExperimentalHttpServerMetrics", boolean.class); + method.setAccessible(true); + return method; + } catch (NoSuchMethodException e) { + logger.log(FINE, e.getMessage(), e); + return null; + } + } +} diff --git a/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v6_0/SpringWebMvcTelemetryBuilder.java b/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v6_0/SpringWebMvcTelemetryBuilder.java index 1c34c847a3b2..fbd5a988c01d 100644 --- a/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v6_0/SpringWebMvcTelemetryBuilder.java +++ b/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v6_0/SpringWebMvcTelemetryBuilder.java @@ -11,6 +11,7 @@ import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor; import io.opentelemetry.instrumentation.api.semconv.http.HttpServerAttributesExtractorBuilder; +import io.opentelemetry.instrumentation.spring.webmvc.v6_0.internal.Experimental; import io.opentelemetry.instrumentation.spring.webmvc.v6_0.internal.SpringMvcBuilderUtil; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; @@ -106,7 +107,10 @@ public SpringWebMvcTelemetryBuilder setKnownMethods(Set knownMethods) { * * @param emitExperimentalHttpServerMetrics {@code true} if the experimental HTTP server metrics * are to be emitted. + * @deprecated Use {@link Experimental#setEmitExperimentalTelemetry(SpringWebMvcTelemetryBuilder, + * boolean)} instead. */ + @Deprecated @CanIgnoreReturnValue public SpringWebMvcTelemetryBuilder setEmitExperimentalHttpServerMetrics( boolean emitExperimentalHttpServerMetrics) { diff --git a/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v6_0/internal/Experimental.java b/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v6_0/internal/Experimental.java new file mode 100644 index 000000000000..d4e32be80b99 --- /dev/null +++ b/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v6_0/internal/Experimental.java @@ -0,0 +1,55 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.spring.webmvc.v6_0.internal; + +import static java.util.logging.Level.FINE; + +import io.opentelemetry.instrumentation.spring.webmvc.v6_0.SpringWebMvcTelemetryBuilder; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.logging.Logger; +import javax.annotation.Nullable; + +/** + * This class is internal and is hence not for public use. Its APIs are unstable and can change at + * any time. + */ +// TODO (trask) update the above javadoc similar to +// https://github.com/open-telemetry/opentelemetry-java/pull/6886 +public class Experimental { + + private static final Logger logger = Logger.getLogger(Experimental.class.getName()); + + @Nullable + private static final Method emitExperimentalTelemetryMethod = + getEmitExperimentalTelemetryMethod(); + + public void setEmitExperimentalTelemetry( + SpringWebMvcTelemetryBuilder builder, boolean emitExperimentalTelemetry) { + + if (emitExperimentalTelemetryMethod != null) { + try { + emitExperimentalTelemetryMethod.invoke(builder, emitExperimentalTelemetry); + } catch (IllegalAccessException | InvocationTargetException e) { + logger.log(FINE, e.getMessage(), e); + } + } + } + + @Nullable + private static Method getEmitExperimentalTelemetryMethod() { + try { + Method method = + SpringWebMvcTelemetryBuilder.class.getDeclaredMethod( + "setEmitExperimentalHttpServerMetrics", boolean.class); + method.setAccessible(true); + return method; + } catch (NoSuchMethodException e) { + logger.log(FINE, e.getMessage(), e); + return null; + } + } +} From 9cc335ec9d1c7a7539192346f5ff18525001d0ca Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Mon, 9 Dec 2024 14:16:44 -0800 Subject: [PATCH 2/5] Fix javadoc todo --- .../apachehttpclient/v4_3/internal/Experimental.java | 7 +++---- .../instrumentation/httpclient/internal/Experimental.java | 7 +++---- .../jetty/httpclient/v12_0/internal/Experimental.java | 7 +++---- .../jetty/httpclient/v9_2/internal/Experimental.java | 7 +++---- .../instrumentation/netty/v4_1/internal/Experimental.java | 7 +++---- .../instrumentation/okhttp/v3_0/internal/Experimental.java | 7 +++---- .../restlet/v1_1/internal/Experimental.java | 7 +++---- .../restlet/v2_0/internal/Experimental.java | 7 +++---- .../spring/web/v3_1/internal/Experimental.java | 7 +++---- .../spring/webmvc/v5_3/internal/Experimental.java | 7 +++---- .../spring/webmvc/v6_0/internal/Experimental.java | 7 +++---- 11 files changed, 33 insertions(+), 44 deletions(-) diff --git a/instrumentation/apache-httpclient/apache-httpclient-4.3/library/src/main/java/io/opentelemetry/instrumentation/apachehttpclient/v4_3/internal/Experimental.java b/instrumentation/apache-httpclient/apache-httpclient-4.3/library/src/main/java/io/opentelemetry/instrumentation/apachehttpclient/v4_3/internal/Experimental.java index 3e25db918680..44fda8c106dc 100644 --- a/instrumentation/apache-httpclient/apache-httpclient-4.3/library/src/main/java/io/opentelemetry/instrumentation/apachehttpclient/v4_3/internal/Experimental.java +++ b/instrumentation/apache-httpclient/apache-httpclient-4.3/library/src/main/java/io/opentelemetry/instrumentation/apachehttpclient/v4_3/internal/Experimental.java @@ -14,11 +14,10 @@ import javax.annotation.Nullable; /** - * This class is internal and is hence not for public use. Its APIs are unstable and can change at - * any time. + * This class is internal and experimental. Its APIs are unstable and can change at any time. Its + * APIs (or a version of them) may be promoted to the public stable API in the future, but no + * guarantees are made. */ -// TODO (trask) update the above javadoc similar to -// https://github.com/open-telemetry/opentelemetry-java/pull/6886 public class Experimental { private static final Logger logger = Logger.getLogger(Experimental.class.getName()); diff --git a/instrumentation/java-http-client/library/src/main/java/io/opentelemetry/instrumentation/httpclient/internal/Experimental.java b/instrumentation/java-http-client/library/src/main/java/io/opentelemetry/instrumentation/httpclient/internal/Experimental.java index f3763e8af500..8eb8516d35e9 100644 --- a/instrumentation/java-http-client/library/src/main/java/io/opentelemetry/instrumentation/httpclient/internal/Experimental.java +++ b/instrumentation/java-http-client/library/src/main/java/io/opentelemetry/instrumentation/httpclient/internal/Experimental.java @@ -14,11 +14,10 @@ import javax.annotation.Nullable; /** - * This class is internal and is hence not for public use. Its APIs are unstable and can change at - * any time. + * This class is internal and experimental. Its APIs are unstable and can change at any time. Its + * APIs (or a version of them) may be promoted to the public stable API in the future, but no + * guarantees are made. */ -// TODO (trask) update the above javadoc similar to -// https://github.com/open-telemetry/opentelemetry-java/pull/6886 public class Experimental { private static final Logger logger = Logger.getLogger(Experimental.class.getName()); diff --git a/instrumentation/jetty-httpclient/jetty-httpclient-12.0/library/src/main/java/io/opentelemetry/instrumentation/jetty/httpclient/v12_0/internal/Experimental.java b/instrumentation/jetty-httpclient/jetty-httpclient-12.0/library/src/main/java/io/opentelemetry/instrumentation/jetty/httpclient/v12_0/internal/Experimental.java index 2fba34f47d6a..401afc9bfd05 100644 --- a/instrumentation/jetty-httpclient/jetty-httpclient-12.0/library/src/main/java/io/opentelemetry/instrumentation/jetty/httpclient/v12_0/internal/Experimental.java +++ b/instrumentation/jetty-httpclient/jetty-httpclient-12.0/library/src/main/java/io/opentelemetry/instrumentation/jetty/httpclient/v12_0/internal/Experimental.java @@ -14,11 +14,10 @@ import javax.annotation.Nullable; /** - * This class is internal and is hence not for public use. Its APIs are unstable and can change at - * any time. + * This class is internal and experimental. Its APIs are unstable and can change at any time. Its + * APIs (or a version of them) may be promoted to the public stable API in the future, but no + * guarantees are made. */ -// TODO (trask) update the above javadoc similar to -// https://github.com/open-telemetry/opentelemetry-java/pull/6886 public class Experimental { private static final Logger logger = Logger.getLogger(Experimental.class.getName()); diff --git a/instrumentation/jetty-httpclient/jetty-httpclient-9.2/library/src/main/java/io/opentelemetry/instrumentation/jetty/httpclient/v9_2/internal/Experimental.java b/instrumentation/jetty-httpclient/jetty-httpclient-9.2/library/src/main/java/io/opentelemetry/instrumentation/jetty/httpclient/v9_2/internal/Experimental.java index dbe83f1d11d8..0a5e5db3166c 100644 --- a/instrumentation/jetty-httpclient/jetty-httpclient-9.2/library/src/main/java/io/opentelemetry/instrumentation/jetty/httpclient/v9_2/internal/Experimental.java +++ b/instrumentation/jetty-httpclient/jetty-httpclient-9.2/library/src/main/java/io/opentelemetry/instrumentation/jetty/httpclient/v9_2/internal/Experimental.java @@ -14,11 +14,10 @@ import javax.annotation.Nullable; /** - * This class is internal and is hence not for public use. Its APIs are unstable and can change at - * any time. + * This class is internal and experimental. Its APIs are unstable and can change at any time. Its + * APIs (or a version of them) may be promoted to the public stable API in the future, but no + * guarantees are made. */ -// TODO (trask) update the above javadoc similar to -// https://github.com/open-telemetry/opentelemetry-java/pull/6886 public class Experimental { private static final Logger logger = Logger.getLogger(Experimental.class.getName()); diff --git a/instrumentation/netty/netty-4.1/library/src/main/java/io/opentelemetry/instrumentation/netty/v4_1/internal/Experimental.java b/instrumentation/netty/netty-4.1/library/src/main/java/io/opentelemetry/instrumentation/netty/v4_1/internal/Experimental.java index 08d4fc12417d..a92e890a752d 100644 --- a/instrumentation/netty/netty-4.1/library/src/main/java/io/opentelemetry/instrumentation/netty/v4_1/internal/Experimental.java +++ b/instrumentation/netty/netty-4.1/library/src/main/java/io/opentelemetry/instrumentation/netty/v4_1/internal/Experimental.java @@ -15,11 +15,10 @@ import javax.annotation.Nullable; /** - * This class is internal and is hence not for public use. Its APIs are unstable and can change at - * any time. + * This class is internal and experimental. Its APIs are unstable and can change at any time. Its + * APIs (or a version of them) may be promoted to the public stable API in the future, but no + * guarantees are made. */ -// TODO (trask) update the above javadoc similar to -// https://github.com/open-telemetry/opentelemetry-java/pull/6886 public class Experimental { private static final Logger logger = Logger.getLogger(Experimental.class.getName()); diff --git a/instrumentation/okhttp/okhttp-3.0/library/src/main/java/io/opentelemetry/instrumentation/okhttp/v3_0/internal/Experimental.java b/instrumentation/okhttp/okhttp-3.0/library/src/main/java/io/opentelemetry/instrumentation/okhttp/v3_0/internal/Experimental.java index aaea920b4e9e..97c99b9baac1 100644 --- a/instrumentation/okhttp/okhttp-3.0/library/src/main/java/io/opentelemetry/instrumentation/okhttp/v3_0/internal/Experimental.java +++ b/instrumentation/okhttp/okhttp-3.0/library/src/main/java/io/opentelemetry/instrumentation/okhttp/v3_0/internal/Experimental.java @@ -14,11 +14,10 @@ import javax.annotation.Nullable; /** - * This class is internal and is hence not for public use. Its APIs are unstable and can change at - * any time. + * This class is internal and experimental. Its APIs are unstable and can change at any time. Its + * APIs (or a version of them) may be promoted to the public stable API in the future, but no + * guarantees are made. */ -// TODO (trask) update the above javadoc similar to -// https://github.com/open-telemetry/opentelemetry-java/pull/6886 public class Experimental { private static final Logger logger = Logger.getLogger(Experimental.class.getName()); diff --git a/instrumentation/restlet/restlet-1.1/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_1/internal/Experimental.java b/instrumentation/restlet/restlet-1.1/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_1/internal/Experimental.java index b044c1d8c7fc..30558c835ce1 100644 --- a/instrumentation/restlet/restlet-1.1/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_1/internal/Experimental.java +++ b/instrumentation/restlet/restlet-1.1/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_1/internal/Experimental.java @@ -14,11 +14,10 @@ import javax.annotation.Nullable; /** - * This class is internal and is hence not for public use. Its APIs are unstable and can change at - * any time. + * This class is internal and experimental. Its APIs are unstable and can change at any time. Its + * APIs (or a version of them) may be promoted to the public stable API in the future, but no + * guarantees are made. */ -// TODO (trask) update the above javadoc similar to -// https://github.com/open-telemetry/opentelemetry-java/pull/6886 public class Experimental { private static final Logger logger = Logger.getLogger(Experimental.class.getName()); diff --git a/instrumentation/restlet/restlet-2.0/library/src/main/java/io/opentelemetry/instrumentation/restlet/v2_0/internal/Experimental.java b/instrumentation/restlet/restlet-2.0/library/src/main/java/io/opentelemetry/instrumentation/restlet/v2_0/internal/Experimental.java index b95c021bf651..80445408e328 100644 --- a/instrumentation/restlet/restlet-2.0/library/src/main/java/io/opentelemetry/instrumentation/restlet/v2_0/internal/Experimental.java +++ b/instrumentation/restlet/restlet-2.0/library/src/main/java/io/opentelemetry/instrumentation/restlet/v2_0/internal/Experimental.java @@ -14,11 +14,10 @@ import javax.annotation.Nullable; /** - * This class is internal and is hence not for public use. Its APIs are unstable and can change at - * any time. + * This class is internal and experimental. Its APIs are unstable and can change at any time. Its + * APIs (or a version of them) may be promoted to the public stable API in the future, but no + * guarantees are made. */ -// TODO (trask) update the above javadoc similar to -// https://github.com/open-telemetry/opentelemetry-java/pull/6886 public class Experimental { private static final Logger logger = Logger.getLogger(Experimental.class.getName()); diff --git a/instrumentation/spring/spring-web/spring-web-3.1/library/src/main/java/io/opentelemetry/instrumentation/spring/web/v3_1/internal/Experimental.java b/instrumentation/spring/spring-web/spring-web-3.1/library/src/main/java/io/opentelemetry/instrumentation/spring/web/v3_1/internal/Experimental.java index 1a6fc69b00dc..5b365ba81747 100644 --- a/instrumentation/spring/spring-web/spring-web-3.1/library/src/main/java/io/opentelemetry/instrumentation/spring/web/v3_1/internal/Experimental.java +++ b/instrumentation/spring/spring-web/spring-web-3.1/library/src/main/java/io/opentelemetry/instrumentation/spring/web/v3_1/internal/Experimental.java @@ -14,11 +14,10 @@ import javax.annotation.Nullable; /** - * This class is internal and is hence not for public use. Its APIs are unstable and can change at - * any time. + * This class is internal and experimental. Its APIs are unstable and can change at any time. Its + * APIs (or a version of them) may be promoted to the public stable API in the future, but no + * guarantees are made. */ -// TODO (trask) update the above javadoc similar to -// https://github.com/open-telemetry/opentelemetry-java/pull/6886 public class Experimental { private static final Logger logger = Logger.getLogger(Experimental.class.getName()); diff --git a/instrumentation/spring/spring-webmvc/spring-webmvc-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v5_3/internal/Experimental.java b/instrumentation/spring/spring-webmvc/spring-webmvc-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v5_3/internal/Experimental.java index a8c6d348cc0f..07d67dcbd045 100644 --- a/instrumentation/spring/spring-webmvc/spring-webmvc-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v5_3/internal/Experimental.java +++ b/instrumentation/spring/spring-webmvc/spring-webmvc-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v5_3/internal/Experimental.java @@ -14,11 +14,10 @@ import javax.annotation.Nullable; /** - * This class is internal and is hence not for public use. Its APIs are unstable and can change at - * any time. + * This class is internal and experimental. Its APIs are unstable and can change at any time. Its + * APIs (or a version of them) may be promoted to the public stable API in the future, but no + * guarantees are made. */ -// TODO (trask) update the above javadoc similar to -// https://github.com/open-telemetry/opentelemetry-java/pull/6886 public class Experimental { private static final Logger logger = Logger.getLogger(Experimental.class.getName()); diff --git a/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v6_0/internal/Experimental.java b/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v6_0/internal/Experimental.java index d4e32be80b99..5bf6ea9c2c61 100644 --- a/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v6_0/internal/Experimental.java +++ b/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v6_0/internal/Experimental.java @@ -14,11 +14,10 @@ import javax.annotation.Nullable; /** - * This class is internal and is hence not for public use. Its APIs are unstable and can change at - * any time. + * This class is internal and experimental. Its APIs are unstable and can change at any time. Its + * APIs (or a version of them) may be promoted to the public stable API in the future, but no + * guarantees are made. */ -// TODO (trask) update the above javadoc similar to -// https://github.com/open-telemetry/opentelemetry-java/pull/6886 public class Experimental { private static final Logger logger = Logger.getLogger(Experimental.class.getName()); From 94a0a70f150b166d48961c94a5d0c4b9173e9027 Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Tue, 10 Dec 2024 16:28:31 -0800 Subject: [PATCH 3/5] remove reflection --- .../ApacheHttpClientTelemetryBuilder.java | 5 ++ .../v4_3/internal/Experimental.java | 39 +++-------- .../JavaHttpClientTelemetryBuilder.java | 5 ++ .../httpclient/internal/Experimental.java | 39 +++-------- .../v12_0/JettyClientTelemetryBuilder.java | 5 ++ .../v12_0/internal/Experimental.java | 39 +++-------- .../v9_2/JettyClientTelemetryBuilder.java | 5 ++ .../v9_2/internal/Experimental.java | 39 +++-------- .../v4_1/NettyClientTelemetryBuilder.java | 25 ++++--- .../v4_1/NettyServerTelemetryBuilder.java | 5 ++ .../netty/v4_1/internal/Experimental.java | 68 +++++-------------- .../okhttp/v3_0/OkHttpTelemetryBuilder.java | 5 ++ .../okhttp/v3_0/internal/Experimental.java | 40 +++-------- .../restlet/v1_1/RestletTelemetryBuilder.java | 5 ++ .../restlet/v1_1/internal/Experimental.java | 39 +++-------- .../restlet/v2_0/RestletTelemetryBuilder.java | 5 ++ .../restlet/v2_0/internal/Experimental.java | 39 +++-------- .../web/v3_1/SpringWebTelemetryBuilder.java | 2 + .../web/v3_1/internal/Experimental.java | 39 +++-------- .../v5_3/SpringWebMvcTelemetryBuilder.java | 2 + .../webmvc/v5_3/internal/Experimental.java | 39 +++-------- .../v6_0/SpringWebMvcTelemetryBuilder.java | 2 + .../webmvc/v6_0/internal/Experimental.java | 39 +++-------- 23 files changed, 180 insertions(+), 350 deletions(-) diff --git a/instrumentation/apache-httpclient/apache-httpclient-4.3/library/src/main/java/io/opentelemetry/instrumentation/apachehttpclient/v4_3/ApacheHttpClientTelemetryBuilder.java b/instrumentation/apache-httpclient/apache-httpclient-4.3/library/src/main/java/io/opentelemetry/instrumentation/apachehttpclient/v4_3/ApacheHttpClientTelemetryBuilder.java index 69ca172280c7..1e1f223dbc16 100644 --- a/instrumentation/apache-httpclient/apache-httpclient-4.3/library/src/main/java/io/opentelemetry/instrumentation/apachehttpclient/v4_3/ApacheHttpClientTelemetryBuilder.java +++ b/instrumentation/apache-httpclient/apache-httpclient-4.3/library/src/main/java/io/opentelemetry/instrumentation/apachehttpclient/v4_3/ApacheHttpClientTelemetryBuilder.java @@ -24,6 +24,11 @@ public final class ApacheHttpClientTelemetryBuilder { private final DefaultHttpClientInstrumenterBuilder builder; private final OpenTelemetry openTelemetry; + static { + Experimental.setSetEmitExperimentalTelemetry( + (builder, emit) -> builder.builder.setEmitExperimentalHttpClientMetrics(emit)); + } + ApacheHttpClientTelemetryBuilder(OpenTelemetry openTelemetry) { builder = DefaultHttpClientInstrumenterBuilder.create( diff --git a/instrumentation/apache-httpclient/apache-httpclient-4.3/library/src/main/java/io/opentelemetry/instrumentation/apachehttpclient/v4_3/internal/Experimental.java b/instrumentation/apache-httpclient/apache-httpclient-4.3/library/src/main/java/io/opentelemetry/instrumentation/apachehttpclient/v4_3/internal/Experimental.java index 44fda8c106dc..cf9bdc45372c 100644 --- a/instrumentation/apache-httpclient/apache-httpclient-4.3/library/src/main/java/io/opentelemetry/instrumentation/apachehttpclient/v4_3/internal/Experimental.java +++ b/instrumentation/apache-httpclient/apache-httpclient-4.3/library/src/main/java/io/opentelemetry/instrumentation/apachehttpclient/v4_3/internal/Experimental.java @@ -5,12 +5,8 @@ package io.opentelemetry.instrumentation.apachehttpclient.v4_3.internal; -import static java.util.logging.Level.FINE; - import io.opentelemetry.instrumentation.apachehttpclient.v4_3.ApacheHttpClientTelemetryBuilder; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.logging.Logger; +import java.util.function.BiConsumer; import javax.annotation.Nullable; /** @@ -18,37 +14,22 @@ * APIs (or a version of them) may be promoted to the public stable API in the future, but no * guarantees are made. */ -public class Experimental { - - private static final Logger logger = Logger.getLogger(Experimental.class.getName()); +public final class Experimental { @Nullable - private static final Method emitExperimentalTelemetryMethod = - getEmitExperimentalTelemetryMethod(); + private static BiConsumer setEmitExperimentalTelemetry; public void setEmitExperimentalTelemetry( ApacheHttpClientTelemetryBuilder builder, boolean emitExperimentalTelemetry) { - - if (emitExperimentalTelemetryMethod != null) { - try { - emitExperimentalTelemetryMethod.invoke(builder, emitExperimentalTelemetry); - } catch (IllegalAccessException | InvocationTargetException e) { - logger.log(FINE, e.getMessage(), e); - } + if (setEmitExperimentalTelemetry != null) { + setEmitExperimentalTelemetry.accept(builder, emitExperimentalTelemetry); } } - @Nullable - private static Method getEmitExperimentalTelemetryMethod() { - try { - Method method = - ApacheHttpClientTelemetryBuilder.class.getDeclaredMethod( - "setEmitExperimentalHttpClientMetrics", boolean.class); - method.setAccessible(true); - return method; - } catch (NoSuchMethodException e) { - logger.log(FINE, e.getMessage(), e); - return null; - } + public static void setSetEmitExperimentalTelemetry( + BiConsumer setEmitExperimentalTelemetry) { + Experimental.setEmitExperimentalTelemetry = setEmitExperimentalTelemetry; } + + private Experimental() {} } diff --git a/instrumentation/java-http-client/library/src/main/java/io/opentelemetry/instrumentation/httpclient/JavaHttpClientTelemetryBuilder.java b/instrumentation/java-http-client/library/src/main/java/io/opentelemetry/instrumentation/httpclient/JavaHttpClientTelemetryBuilder.java index 898439786d77..e941fb7cdc9b 100644 --- a/instrumentation/java-http-client/library/src/main/java/io/opentelemetry/instrumentation/httpclient/JavaHttpClientTelemetryBuilder.java +++ b/instrumentation/java-http-client/library/src/main/java/io/opentelemetry/instrumentation/httpclient/JavaHttpClientTelemetryBuilder.java @@ -25,6 +25,11 @@ public final class JavaHttpClientTelemetryBuilder { private final DefaultHttpClientInstrumenterBuilder> builder; private final OpenTelemetry openTelemetry; + static { + Experimental.setSetEmitExperimentalTelemetry( + (builder, emit) -> builder.builder.setEmitExperimentalHttpClientMetrics(emit)); + } + JavaHttpClientTelemetryBuilder(OpenTelemetry openTelemetry) { builder = JavaHttpClientInstrumenterBuilderFactory.create(openTelemetry); this.openTelemetry = openTelemetry; diff --git a/instrumentation/java-http-client/library/src/main/java/io/opentelemetry/instrumentation/httpclient/internal/Experimental.java b/instrumentation/java-http-client/library/src/main/java/io/opentelemetry/instrumentation/httpclient/internal/Experimental.java index 8eb8516d35e9..931fedfa540e 100644 --- a/instrumentation/java-http-client/library/src/main/java/io/opentelemetry/instrumentation/httpclient/internal/Experimental.java +++ b/instrumentation/java-http-client/library/src/main/java/io/opentelemetry/instrumentation/httpclient/internal/Experimental.java @@ -5,12 +5,8 @@ package io.opentelemetry.instrumentation.httpclient.internal; -import static java.util.logging.Level.FINE; - import io.opentelemetry.instrumentation.httpclient.JavaHttpClientTelemetryBuilder; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.logging.Logger; +import java.util.function.BiConsumer; import javax.annotation.Nullable; /** @@ -18,37 +14,22 @@ * APIs (or a version of them) may be promoted to the public stable API in the future, but no * guarantees are made. */ -public class Experimental { - - private static final Logger logger = Logger.getLogger(Experimental.class.getName()); +public final class Experimental { @Nullable - private static final Method emitExperimentalTelemetryMethod = - getEmitExperimentalTelemetryMethod(); + private static BiConsumer setEmitExperimentalTelemetry; public void setEmitExperimentalTelemetry( JavaHttpClientTelemetryBuilder builder, boolean emitExperimentalTelemetry) { - - if (emitExperimentalTelemetryMethod != null) { - try { - emitExperimentalTelemetryMethod.invoke(builder, emitExperimentalTelemetry); - } catch (IllegalAccessException | InvocationTargetException e) { - logger.log(FINE, e.getMessage(), e); - } + if (setEmitExperimentalTelemetry != null) { + setEmitExperimentalTelemetry.accept(builder, emitExperimentalTelemetry); } } - @Nullable - private static Method getEmitExperimentalTelemetryMethod() { - try { - Method method = - JavaHttpClientTelemetryBuilder.class.getDeclaredMethod( - "setEmitExperimentalHttpClientMetrics", boolean.class); - method.setAccessible(true); - return method; - } catch (NoSuchMethodException e) { - logger.log(FINE, e.getMessage(), e); - return null; - } + public static void setSetEmitExperimentalTelemetry( + BiConsumer setEmitExperimentalTelemetry) { + Experimental.setEmitExperimentalTelemetry = setEmitExperimentalTelemetry; } + + private Experimental() {} } diff --git a/instrumentation/jetty-httpclient/jetty-httpclient-12.0/library/src/main/java/io/opentelemetry/instrumentation/jetty/httpclient/v12_0/JettyClientTelemetryBuilder.java b/instrumentation/jetty-httpclient/jetty-httpclient-12.0/library/src/main/java/io/opentelemetry/instrumentation/jetty/httpclient/v12_0/JettyClientTelemetryBuilder.java index 3590441d3791..d9a117ff0509 100644 --- a/instrumentation/jetty-httpclient/jetty-httpclient-12.0/library/src/main/java/io/opentelemetry/instrumentation/jetty/httpclient/v12_0/JettyClientTelemetryBuilder.java +++ b/instrumentation/jetty-httpclient/jetty-httpclient-12.0/library/src/main/java/io/opentelemetry/instrumentation/jetty/httpclient/v12_0/JettyClientTelemetryBuilder.java @@ -27,6 +27,11 @@ public final class JettyClientTelemetryBuilder { private HttpClientTransport httpClientTransport; private SslContextFactory.Client sslContextFactory; + static { + Experimental.setSetEmitExperimentalTelemetry( + (builder, emit) -> builder.builder.setEmitExperimentalHttpClientMetrics(emit)); + } + JettyClientTelemetryBuilder(OpenTelemetry openTelemetry) { builder = JettyHttpClientInstrumenterBuilderFactory.create(openTelemetry); } diff --git a/instrumentation/jetty-httpclient/jetty-httpclient-12.0/library/src/main/java/io/opentelemetry/instrumentation/jetty/httpclient/v12_0/internal/Experimental.java b/instrumentation/jetty-httpclient/jetty-httpclient-12.0/library/src/main/java/io/opentelemetry/instrumentation/jetty/httpclient/v12_0/internal/Experimental.java index 401afc9bfd05..11d4a2ba1ea9 100644 --- a/instrumentation/jetty-httpclient/jetty-httpclient-12.0/library/src/main/java/io/opentelemetry/instrumentation/jetty/httpclient/v12_0/internal/Experimental.java +++ b/instrumentation/jetty-httpclient/jetty-httpclient-12.0/library/src/main/java/io/opentelemetry/instrumentation/jetty/httpclient/v12_0/internal/Experimental.java @@ -5,12 +5,8 @@ package io.opentelemetry.instrumentation.jetty.httpclient.v12_0.internal; -import static java.util.logging.Level.FINE; - import io.opentelemetry.instrumentation.jetty.httpclient.v12_0.JettyClientTelemetryBuilder; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.logging.Logger; +import java.util.function.BiConsumer; import javax.annotation.Nullable; /** @@ -18,37 +14,22 @@ * APIs (or a version of them) may be promoted to the public stable API in the future, but no * guarantees are made. */ -public class Experimental { - - private static final Logger logger = Logger.getLogger(Experimental.class.getName()); +public final class Experimental { @Nullable - private static final Method emitExperimentalTelemetryMethod = - getEmitExperimentalTelemetryMethod(); + private static BiConsumer setEmitExperimentalTelemetry; public void setEmitExperimentalTelemetry( JettyClientTelemetryBuilder builder, boolean emitExperimentalTelemetry) { - - if (emitExperimentalTelemetryMethod != null) { - try { - emitExperimentalTelemetryMethod.invoke(builder, emitExperimentalTelemetry); - } catch (IllegalAccessException | InvocationTargetException e) { - logger.log(FINE, e.getMessage(), e); - } + if (setEmitExperimentalTelemetry != null) { + setEmitExperimentalTelemetry.accept(builder, emitExperimentalTelemetry); } } - @Nullable - private static Method getEmitExperimentalTelemetryMethod() { - try { - Method method = - JettyClientTelemetryBuilder.class.getDeclaredMethod( - "setEmitExperimentalHttpClientMetrics", boolean.class); - method.setAccessible(true); - return method; - } catch (NoSuchMethodException e) { - logger.log(FINE, e.getMessage(), e); - return null; - } + public static void setSetEmitExperimentalTelemetry( + BiConsumer setEmitExperimentalTelemetry) { + Experimental.setEmitExperimentalTelemetry = setEmitExperimentalTelemetry; } + + private Experimental() {} } diff --git a/instrumentation/jetty-httpclient/jetty-httpclient-9.2/library/src/main/java/io/opentelemetry/instrumentation/jetty/httpclient/v9_2/JettyClientTelemetryBuilder.java b/instrumentation/jetty-httpclient/jetty-httpclient-9.2/library/src/main/java/io/opentelemetry/instrumentation/jetty/httpclient/v9_2/JettyClientTelemetryBuilder.java index dde3a23e67d8..fef19214cfd6 100644 --- a/instrumentation/jetty-httpclient/jetty-httpclient-9.2/library/src/main/java/io/opentelemetry/instrumentation/jetty/httpclient/v9_2/JettyClientTelemetryBuilder.java +++ b/instrumentation/jetty-httpclient/jetty-httpclient-9.2/library/src/main/java/io/opentelemetry/instrumentation/jetty/httpclient/v9_2/JettyClientTelemetryBuilder.java @@ -28,6 +28,11 @@ public final class JettyClientTelemetryBuilder { private HttpClientTransport httpClientTransport; private SslContextFactory sslContextFactory; + static { + Experimental.setSetEmitExperimentalTelemetry( + (builder, emit) -> builder.builder.setEmitExperimentalHttpClientMetrics(emit)); + } + JettyClientTelemetryBuilder(OpenTelemetry openTelemetry) { builder = JettyHttpClientInstrumenterBuilderFactory.create(openTelemetry); } diff --git a/instrumentation/jetty-httpclient/jetty-httpclient-9.2/library/src/main/java/io/opentelemetry/instrumentation/jetty/httpclient/v9_2/internal/Experimental.java b/instrumentation/jetty-httpclient/jetty-httpclient-9.2/library/src/main/java/io/opentelemetry/instrumentation/jetty/httpclient/v9_2/internal/Experimental.java index 0a5e5db3166c..ac78337b28dc 100644 --- a/instrumentation/jetty-httpclient/jetty-httpclient-9.2/library/src/main/java/io/opentelemetry/instrumentation/jetty/httpclient/v9_2/internal/Experimental.java +++ b/instrumentation/jetty-httpclient/jetty-httpclient-9.2/library/src/main/java/io/opentelemetry/instrumentation/jetty/httpclient/v9_2/internal/Experimental.java @@ -5,12 +5,8 @@ package io.opentelemetry.instrumentation.jetty.httpclient.v9_2.internal; -import static java.util.logging.Level.FINE; - import io.opentelemetry.instrumentation.jetty.httpclient.v9_2.JettyClientTelemetryBuilder; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.logging.Logger; +import java.util.function.BiConsumer; import javax.annotation.Nullable; /** @@ -18,37 +14,22 @@ * APIs (or a version of them) may be promoted to the public stable API in the future, but no * guarantees are made. */ -public class Experimental { - - private static final Logger logger = Logger.getLogger(Experimental.class.getName()); +public final class Experimental { @Nullable - private static final Method emitExperimentalTelemetryMethod = - getEmitExperimentalTelemetryMethod(); + private static BiConsumer setEmitExperimentalTelemetry; public void setEmitExperimentalTelemetry( JettyClientTelemetryBuilder builder, boolean emitExperimentalTelemetry) { - - if (emitExperimentalTelemetryMethod != null) { - try { - emitExperimentalTelemetryMethod.invoke(builder, emitExperimentalTelemetry); - } catch (IllegalAccessException | InvocationTargetException e) { - logger.log(FINE, e.getMessage(), e); - } + if (setEmitExperimentalTelemetry != null) { + setEmitExperimentalTelemetry.accept(builder, emitExperimentalTelemetry); } } - @Nullable - private static Method getEmitExperimentalTelemetryMethod() { - try { - Method method = - JettyClientTelemetryBuilder.class.getDeclaredMethod( - "setEmitExperimentalHttpClientMetrics", boolean.class); - method.setAccessible(true); - return method; - } catch (NoSuchMethodException e) { - logger.log(FINE, e.getMessage(), e); - return null; - } + public static void setSetEmitExperimentalTelemetry( + BiConsumer setEmitExperimentalTelemetry) { + Experimental.setEmitExperimentalTelemetry = setEmitExperimentalTelemetry; } + + private Experimental() {} } diff --git a/instrumentation/netty/netty-4.1/library/src/main/java/io/opentelemetry/instrumentation/netty/v4_1/NettyClientTelemetryBuilder.java b/instrumentation/netty/netty-4.1/library/src/main/java/io/opentelemetry/instrumentation/netty/v4_1/NettyClientTelemetryBuilder.java index 012775aa1c75..67ba55160bbf 100644 --- a/instrumentation/netty/netty-4.1/library/src/main/java/io/opentelemetry/instrumentation/netty/v4_1/NettyClientTelemetryBuilder.java +++ b/instrumentation/netty/netty-4.1/library/src/main/java/io/opentelemetry/instrumentation/netty/v4_1/NettyClientTelemetryBuilder.java @@ -25,7 +25,15 @@ public final class NettyClientTelemetryBuilder { private final DefaultHttpClientInstrumenterBuilder builder; - private boolean emitExperimentalTelemetry = false; + private boolean emitExperimentalHttpClientEvents = false; + + static { + Experimental.setSetEmitExperimentalClientTelemetry( + (builder, emit) -> { + builder.builder.setEmitExperimentalHttpClientMetrics(emit); + builder.emitExperimentalHttpClientEvents = emit; + }); + } NettyClientTelemetryBuilder(OpenTelemetry openTelemetry) { builder = @@ -39,8 +47,8 @@ public final class NettyClientTelemetryBuilder { @Deprecated @CanIgnoreReturnValue public NettyClientTelemetryBuilder setEmitExperimentalHttpClientEvents( - boolean emitExperimentalTelemetry) { - this.emitExperimentalTelemetry = emitExperimentalTelemetry; + boolean emitExperimentalHttpClientEvents) { + this.emitExperimentalHttpClientEvents = emitExperimentalHttpClientEvents; return this; } @@ -101,17 +109,16 @@ public NettyClientTelemetryBuilder setKnownMethods(Set knownMethods) { /** * Configures the instrumentation to emit experimental HTTP client metrics. * - * @param emitExperimentalTelemetry {@code true} if the experimental HTTP client metrics are to be - * emitted. + * @param emitExperimentalHttpClientMetrics {@code true} if the experimental HTTP client metrics + * are to be emitted. * @deprecated Use {@link Experimental#setEmitExperimentalTelemetry(NettyClientTelemetryBuilder, * boolean)} instead. */ @Deprecated @CanIgnoreReturnValue public NettyClientTelemetryBuilder setEmitExperimentalHttpClientMetrics( - boolean emitExperimentalTelemetry) { - builder.setEmitExperimentalHttpClientMetrics(emitExperimentalTelemetry); - this.emitExperimentalTelemetry = emitExperimentalTelemetry; + boolean emitExperimentalHttpClientMetrics) { + builder.setEmitExperimentalHttpClientMetrics(emitExperimentalHttpClientMetrics); return this; } @@ -134,6 +141,6 @@ public NettyClientTelemetry build() { NettyConnectionInstrumentationFlag.DISABLED, NettyConnectionInstrumentationFlag.DISABLED) .instrumenter(), - emitExperimentalTelemetry); + emitExperimentalHttpClientEvents); } } diff --git a/instrumentation/netty/netty-4.1/library/src/main/java/io/opentelemetry/instrumentation/netty/v4_1/NettyServerTelemetryBuilder.java b/instrumentation/netty/netty-4.1/library/src/main/java/io/opentelemetry/instrumentation/netty/v4_1/NettyServerTelemetryBuilder.java index 6437a540b106..f7ba3b78751d 100644 --- a/instrumentation/netty/netty-4.1/library/src/main/java/io/opentelemetry/instrumentation/netty/v4_1/NettyServerTelemetryBuilder.java +++ b/instrumentation/netty/netty-4.1/library/src/main/java/io/opentelemetry/instrumentation/netty/v4_1/NettyServerTelemetryBuilder.java @@ -29,6 +29,11 @@ public final class NettyServerTelemetryBuilder { static { NettyServerInstrumenterBuilderUtil.setBuilderExtractor( nettyServerTelemetryBuilder -> nettyServerTelemetryBuilder.builder); + Experimental.setSetEmitExperimentalServerTelemetry( + (builder, emit) -> { + builder.builder.setEmitExperimentalHttpServerMetrics(emit); + builder.emitExperimentalHttpServerEvents = emit; + }); } NettyServerTelemetryBuilder(OpenTelemetry openTelemetry) { diff --git a/instrumentation/netty/netty-4.1/library/src/main/java/io/opentelemetry/instrumentation/netty/v4_1/internal/Experimental.java b/instrumentation/netty/netty-4.1/library/src/main/java/io/opentelemetry/instrumentation/netty/v4_1/internal/Experimental.java index a92e890a752d..b045eeac0adf 100644 --- a/instrumentation/netty/netty-4.1/library/src/main/java/io/opentelemetry/instrumentation/netty/v4_1/internal/Experimental.java +++ b/instrumentation/netty/netty-4.1/library/src/main/java/io/opentelemetry/instrumentation/netty/v4_1/internal/Experimental.java @@ -5,13 +5,9 @@ package io.opentelemetry.instrumentation.netty.v4_1.internal; -import static java.util.logging.Level.FINE; - import io.opentelemetry.instrumentation.netty.v4_1.NettyClientTelemetryBuilder; import io.opentelemetry.instrumentation.netty.v4_1.NettyServerTelemetryBuilder; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.logging.Logger; +import java.util.function.BiConsumer; import javax.annotation.Nullable; /** @@ -19,67 +15,39 @@ * APIs (or a version of them) may be promoted to the public stable API in the future, but no * guarantees are made. */ -public class Experimental { - - private static final Logger logger = Logger.getLogger(Experimental.class.getName()); +public final class Experimental { @Nullable - private static final Method emitExperimentalClientTelemetryMethod = - getEmitExperimentalClientTelemetryMethod(); + private static BiConsumer + setEmitExperimentalClientTelemetry; @Nullable - private static final Method emitExperimentalServerTelemetryMethod = - getEmitExperimentalServerTelemetryMethod(); + private static BiConsumer + setEmitExperimentalServerTelemetry; public void setEmitExperimentalTelemetry( NettyClientTelemetryBuilder builder, boolean emitExperimentalTelemetry) { - - if (emitExperimentalClientTelemetryMethod != null) { - try { - emitExperimentalClientTelemetryMethod.invoke(builder, emitExperimentalTelemetry); - } catch (IllegalAccessException | InvocationTargetException e) { - logger.log(FINE, e.getMessage(), e); - } + if (setEmitExperimentalClientTelemetry != null) { + setEmitExperimentalClientTelemetry.accept(builder, emitExperimentalTelemetry); } } public void setEmitExperimentalTelemetry( NettyServerTelemetryBuilder builder, boolean emitExperimentalTelemetry) { - - if (emitExperimentalServerTelemetryMethod != null) { - try { - emitExperimentalServerTelemetryMethod.invoke(builder, emitExperimentalTelemetry); - } catch (IllegalAccessException | InvocationTargetException e) { - logger.log(FINE, e.getMessage(), e); - } + if (setEmitExperimentalServerTelemetry != null) { + setEmitExperimentalServerTelemetry.accept(builder, emitExperimentalTelemetry); } } - @Nullable - private static Method getEmitExperimentalClientTelemetryMethod() { - try { - Method method = - NettyClientTelemetryBuilder.class.getDeclaredMethod( - "setEmitExperimentalHttpClientMetrics", boolean.class); - method.setAccessible(true); - return method; - } catch (NoSuchMethodException e) { - logger.log(FINE, e.getMessage(), e); - return null; - } + public static void setSetEmitExperimentalClientTelemetry( + BiConsumer setEmitExperimentalClientTelemetry) { + Experimental.setEmitExperimentalClientTelemetry = setEmitExperimentalClientTelemetry; } - @Nullable - private static Method getEmitExperimentalServerTelemetryMethod() { - try { - Method method = - NettyServerTelemetryBuilder.class.getDeclaredMethod( - "setEmitExperimentalHttpServerMetrics", boolean.class); - method.setAccessible(true); - return method; - } catch (NoSuchMethodException e) { - logger.log(FINE, e.getMessage(), e); - return null; - } + public static void setSetEmitExperimentalServerTelemetry( + BiConsumer setEmitExperimentalServerTelemetry) { + Experimental.setEmitExperimentalServerTelemetry = setEmitExperimentalServerTelemetry; } + + private Experimental() {} } diff --git a/instrumentation/okhttp/okhttp-3.0/library/src/main/java/io/opentelemetry/instrumentation/okhttp/v3_0/OkHttpTelemetryBuilder.java b/instrumentation/okhttp/okhttp-3.0/library/src/main/java/io/opentelemetry/instrumentation/okhttp/v3_0/OkHttpTelemetryBuilder.java index 48a97f84c956..e0b1b319a867 100644 --- a/instrumentation/okhttp/okhttp-3.0/library/src/main/java/io/opentelemetry/instrumentation/okhttp/v3_0/OkHttpTelemetryBuilder.java +++ b/instrumentation/okhttp/okhttp-3.0/library/src/main/java/io/opentelemetry/instrumentation/okhttp/v3_0/OkHttpTelemetryBuilder.java @@ -25,6 +25,11 @@ public final class OkHttpTelemetryBuilder { private final DefaultHttpClientInstrumenterBuilder builder; private final OpenTelemetry openTelemetry; + static { + Experimental.setSetEmitExperimentalTelemetry( + (builder, emit) -> builder.builder.setEmitExperimentalHttpClientMetrics(emit)); + } + OkHttpTelemetryBuilder(OpenTelemetry openTelemetry) { builder = OkHttpClientInstrumenterBuilderFactory.create(openTelemetry); this.openTelemetry = openTelemetry; diff --git a/instrumentation/okhttp/okhttp-3.0/library/src/main/java/io/opentelemetry/instrumentation/okhttp/v3_0/internal/Experimental.java b/instrumentation/okhttp/okhttp-3.0/library/src/main/java/io/opentelemetry/instrumentation/okhttp/v3_0/internal/Experimental.java index 97c99b9baac1..d448101de4c6 100644 --- a/instrumentation/okhttp/okhttp-3.0/library/src/main/java/io/opentelemetry/instrumentation/okhttp/v3_0/internal/Experimental.java +++ b/instrumentation/okhttp/okhttp-3.0/library/src/main/java/io/opentelemetry/instrumentation/okhttp/v3_0/internal/Experimental.java @@ -5,12 +5,8 @@ package io.opentelemetry.instrumentation.okhttp.v3_0.internal; -import static java.util.logging.Level.FINE; - import io.opentelemetry.instrumentation.okhttp.v3_0.OkHttpTelemetryBuilder; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.logging.Logger; +import java.util.function.BiConsumer; import javax.annotation.Nullable; /** @@ -18,37 +14,21 @@ * APIs (or a version of them) may be promoted to the public stable API in the future, but no * guarantees are made. */ -public class Experimental { - - private static final Logger logger = Logger.getLogger(Experimental.class.getName()); +public final class Experimental { - @Nullable - private static final Method emitExperimentalTelemetryMethod = - getEmitExperimentalTelemetryMethod(); + @Nullable private static BiConsumer setEmitExperimentalTelemetry; public void setEmitExperimentalTelemetry( OkHttpTelemetryBuilder builder, boolean emitExperimentalTelemetry) { - - if (emitExperimentalTelemetryMethod != null) { - try { - emitExperimentalTelemetryMethod.invoke(builder, emitExperimentalTelemetry); - } catch (IllegalAccessException | InvocationTargetException e) { - logger.log(FINE, e.getMessage(), e); - } + if (setEmitExperimentalTelemetry != null) { + setEmitExperimentalTelemetry.accept(builder, emitExperimentalTelemetry); } } - @Nullable - private static Method getEmitExperimentalTelemetryMethod() { - try { - Method method = - OkHttpTelemetryBuilder.class.getDeclaredMethod( - "setEmitExperimentalHttpClientMetrics", boolean.class); - method.setAccessible(true); - return method; - } catch (NoSuchMethodException e) { - logger.log(FINE, e.getMessage(), e); - return null; - } + public static void setSetEmitExperimentalTelemetry( + BiConsumer setEmitExperimentalTelemetry) { + Experimental.setEmitExperimentalTelemetry = setEmitExperimentalTelemetry; } + + private Experimental() {} } diff --git a/instrumentation/restlet/restlet-1.1/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_1/RestletTelemetryBuilder.java b/instrumentation/restlet/restlet-1.1/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_1/RestletTelemetryBuilder.java index b7e40595ea9e..453ab82d3c47 100644 --- a/instrumentation/restlet/restlet-1.1/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_1/RestletTelemetryBuilder.java +++ b/instrumentation/restlet/restlet-1.1/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_1/RestletTelemetryBuilder.java @@ -24,6 +24,11 @@ public final class RestletTelemetryBuilder { private final DefaultHttpServerInstrumenterBuilder builder; + static { + Experimental.setSetEmitExperimentalTelemetry( + (builder, emit) -> builder.builder.setEmitExperimentalHttpServerMetrics(emit)); + } + RestletTelemetryBuilder(OpenTelemetry openTelemetry) { builder = RestletTelemetryBuilderFactory.create(openTelemetry); } diff --git a/instrumentation/restlet/restlet-1.1/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_1/internal/Experimental.java b/instrumentation/restlet/restlet-1.1/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_1/internal/Experimental.java index 30558c835ce1..7a84497f06cf 100644 --- a/instrumentation/restlet/restlet-1.1/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_1/internal/Experimental.java +++ b/instrumentation/restlet/restlet-1.1/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_1/internal/Experimental.java @@ -5,12 +5,8 @@ package io.opentelemetry.instrumentation.restlet.v1_1.internal; -import static java.util.logging.Level.FINE; - import io.opentelemetry.instrumentation.restlet.v1_1.RestletTelemetryBuilder; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.logging.Logger; +import java.util.function.BiConsumer; import javax.annotation.Nullable; /** @@ -18,37 +14,22 @@ * APIs (or a version of them) may be promoted to the public stable API in the future, but no * guarantees are made. */ -public class Experimental { - - private static final Logger logger = Logger.getLogger(Experimental.class.getName()); +public final class Experimental { @Nullable - private static final Method emitExperimentalTelemetryMethod = - getEmitExperimentalTelemetryMethod(); + private static BiConsumer setEmitExperimentalTelemetry; public void setEmitExperimentalTelemetry( RestletTelemetryBuilder builder, boolean emitExperimentalTelemetry) { - - if (emitExperimentalTelemetryMethod != null) { - try { - emitExperimentalTelemetryMethod.invoke(builder, emitExperimentalTelemetry); - } catch (IllegalAccessException | InvocationTargetException e) { - logger.log(FINE, e.getMessage(), e); - } + if (setEmitExperimentalTelemetry != null) { + setEmitExperimentalTelemetry.accept(builder, emitExperimentalTelemetry); } } - @Nullable - private static Method getEmitExperimentalTelemetryMethod() { - try { - Method method = - RestletTelemetryBuilder.class.getDeclaredMethod( - "setEmitExperimentalHttpServerMetrics", boolean.class); - method.setAccessible(true); - return method; - } catch (NoSuchMethodException e) { - logger.log(FINE, e.getMessage(), e); - return null; - } + public static void setSetEmitExperimentalTelemetry( + BiConsumer setEmitExperimentalTelemetry) { + Experimental.setEmitExperimentalTelemetry = setEmitExperimentalTelemetry; } + + private Experimental() {} } diff --git a/instrumentation/restlet/restlet-2.0/library/src/main/java/io/opentelemetry/instrumentation/restlet/v2_0/RestletTelemetryBuilder.java b/instrumentation/restlet/restlet-2.0/library/src/main/java/io/opentelemetry/instrumentation/restlet/v2_0/RestletTelemetryBuilder.java index e705e875b4fc..32a6421d5118 100644 --- a/instrumentation/restlet/restlet-2.0/library/src/main/java/io/opentelemetry/instrumentation/restlet/v2_0/RestletTelemetryBuilder.java +++ b/instrumentation/restlet/restlet-2.0/library/src/main/java/io/opentelemetry/instrumentation/restlet/v2_0/RestletTelemetryBuilder.java @@ -24,6 +24,11 @@ public final class RestletTelemetryBuilder { private final DefaultHttpServerInstrumenterBuilder builder; + static { + Experimental.setSetEmitExperimentalTelemetry( + (builder, emit) -> builder.builder.setEmitExperimentalHttpServerMetrics(emit)); + } + RestletTelemetryBuilder(OpenTelemetry openTelemetry) { builder = RestletTelemetryBuilderFactory.create(openTelemetry); } diff --git a/instrumentation/restlet/restlet-2.0/library/src/main/java/io/opentelemetry/instrumentation/restlet/v2_0/internal/Experimental.java b/instrumentation/restlet/restlet-2.0/library/src/main/java/io/opentelemetry/instrumentation/restlet/v2_0/internal/Experimental.java index 80445408e328..2a1852c3bcc9 100644 --- a/instrumentation/restlet/restlet-2.0/library/src/main/java/io/opentelemetry/instrumentation/restlet/v2_0/internal/Experimental.java +++ b/instrumentation/restlet/restlet-2.0/library/src/main/java/io/opentelemetry/instrumentation/restlet/v2_0/internal/Experimental.java @@ -5,12 +5,8 @@ package io.opentelemetry.instrumentation.restlet.v2_0.internal; -import static java.util.logging.Level.FINE; - import io.opentelemetry.instrumentation.restlet.v2_0.RestletTelemetryBuilder; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.logging.Logger; +import java.util.function.BiConsumer; import javax.annotation.Nullable; /** @@ -18,37 +14,22 @@ * APIs (or a version of them) may be promoted to the public stable API in the future, but no * guarantees are made. */ -public class Experimental { - - private static final Logger logger = Logger.getLogger(Experimental.class.getName()); +public final class Experimental { @Nullable - private static final Method emitExperimentalTelemetryMethod = - getEmitExperimentalTelemetryMethod(); + private static BiConsumer setEmitExperimentalTelemetry; public void setEmitExperimentalTelemetry( RestletTelemetryBuilder builder, boolean emitExperimentalTelemetry) { - - if (emitExperimentalTelemetryMethod != null) { - try { - emitExperimentalTelemetryMethod.invoke(builder, emitExperimentalTelemetry); - } catch (IllegalAccessException | InvocationTargetException e) { - logger.log(FINE, e.getMessage(), e); - } + if (setEmitExperimentalTelemetry != null) { + setEmitExperimentalTelemetry.accept(builder, emitExperimentalTelemetry); } } - @Nullable - private static Method getEmitExperimentalTelemetryMethod() { - try { - Method method = - RestletTelemetryBuilder.class.getDeclaredMethod( - "setEmitExperimentalHttpServerMetrics", boolean.class); - method.setAccessible(true); - return method; - } catch (NoSuchMethodException e) { - logger.log(FINE, e.getMessage(), e); - return null; - } + public static void setSetEmitExperimentalTelemetry( + BiConsumer setEmitExperimentalTelemetry) { + Experimental.setEmitExperimentalTelemetry = setEmitExperimentalTelemetry; } + + private Experimental() {} } diff --git a/instrumentation/spring/spring-web/spring-web-3.1/library/src/main/java/io/opentelemetry/instrumentation/spring/web/v3_1/SpringWebTelemetryBuilder.java b/instrumentation/spring/spring-web/spring-web-3.1/library/src/main/java/io/opentelemetry/instrumentation/spring/web/v3_1/SpringWebTelemetryBuilder.java index 8c0b2176699c..c9cad5f5ed70 100644 --- a/instrumentation/spring/spring-web/spring-web-3.1/library/src/main/java/io/opentelemetry/instrumentation/spring/web/v3_1/SpringWebTelemetryBuilder.java +++ b/instrumentation/spring/spring-web/spring-web-3.1/library/src/main/java/io/opentelemetry/instrumentation/spring/web/v3_1/SpringWebTelemetryBuilder.java @@ -26,6 +26,8 @@ public final class SpringWebTelemetryBuilder { static { WebTelemetryUtil.setBuilderExtractor(SpringWebTelemetryBuilder::getBuilder); + Experimental.setSetEmitExperimentalTelemetry( + (builder, emit) -> builder.builder.setEmitExperimentalHttpClientMetrics(emit)); } SpringWebTelemetryBuilder(OpenTelemetry openTelemetry) { diff --git a/instrumentation/spring/spring-web/spring-web-3.1/library/src/main/java/io/opentelemetry/instrumentation/spring/web/v3_1/internal/Experimental.java b/instrumentation/spring/spring-web/spring-web-3.1/library/src/main/java/io/opentelemetry/instrumentation/spring/web/v3_1/internal/Experimental.java index 5b365ba81747..d97edf5fbd85 100644 --- a/instrumentation/spring/spring-web/spring-web-3.1/library/src/main/java/io/opentelemetry/instrumentation/spring/web/v3_1/internal/Experimental.java +++ b/instrumentation/spring/spring-web/spring-web-3.1/library/src/main/java/io/opentelemetry/instrumentation/spring/web/v3_1/internal/Experimental.java @@ -5,12 +5,8 @@ package io.opentelemetry.instrumentation.spring.web.v3_1.internal; -import static java.util.logging.Level.FINE; - import io.opentelemetry.instrumentation.spring.web.v3_1.SpringWebTelemetryBuilder; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.logging.Logger; +import java.util.function.BiConsumer; import javax.annotation.Nullable; /** @@ -18,37 +14,22 @@ * APIs (or a version of them) may be promoted to the public stable API in the future, but no * guarantees are made. */ -public class Experimental { - - private static final Logger logger = Logger.getLogger(Experimental.class.getName()); +public final class Experimental { @Nullable - private static final Method emitExperimentalTelemetryMethod = - getEmitExperimentalTelemetryMethod(); + private static BiConsumer setEmitExperimentalTelemetry; public void setEmitExperimentalTelemetry( SpringWebTelemetryBuilder builder, boolean emitExperimentalTelemetry) { - - if (emitExperimentalTelemetryMethod != null) { - try { - emitExperimentalTelemetryMethod.invoke(builder, emitExperimentalTelemetry); - } catch (IllegalAccessException | InvocationTargetException e) { - logger.log(FINE, e.getMessage(), e); - } + if (setEmitExperimentalTelemetry != null) { + setEmitExperimentalTelemetry.accept(builder, emitExperimentalTelemetry); } } - @Nullable - private static Method getEmitExperimentalTelemetryMethod() { - try { - Method method = - SpringWebTelemetryBuilder.class.getDeclaredMethod( - "setEmitExperimentalHttpClientMetrics", boolean.class); - method.setAccessible(true); - return method; - } catch (NoSuchMethodException e) { - logger.log(FINE, e.getMessage(), e); - return null; - } + public static void setSetEmitExperimentalTelemetry( + BiConsumer setEmitExperimentalTelemetry) { + Experimental.setEmitExperimentalTelemetry = setEmitExperimentalTelemetry; } + + private Experimental() {} } diff --git a/instrumentation/spring/spring-webmvc/spring-webmvc-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v5_3/SpringWebMvcTelemetryBuilder.java b/instrumentation/spring/spring-webmvc/spring-webmvc-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v5_3/SpringWebMvcTelemetryBuilder.java index cef84ec085e0..b2f6c63785e4 100644 --- a/instrumentation/spring/spring-webmvc/spring-webmvc-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v5_3/SpringWebMvcTelemetryBuilder.java +++ b/instrumentation/spring/spring-webmvc/spring-webmvc-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v5_3/SpringWebMvcTelemetryBuilder.java @@ -29,6 +29,8 @@ public final class SpringWebMvcTelemetryBuilder { static { SpringMvcBuilderUtil.setBuilderExtractor(builder -> builder.builder); + Experimental.setSetEmitExperimentalTelemetry( + (builder, emit) -> builder.builder.setEmitExperimentalHttpServerMetrics(emit)); } SpringWebMvcTelemetryBuilder(OpenTelemetry openTelemetry) { diff --git a/instrumentation/spring/spring-webmvc/spring-webmvc-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v5_3/internal/Experimental.java b/instrumentation/spring/spring-webmvc/spring-webmvc-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v5_3/internal/Experimental.java index 07d67dcbd045..90736534424a 100644 --- a/instrumentation/spring/spring-webmvc/spring-webmvc-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v5_3/internal/Experimental.java +++ b/instrumentation/spring/spring-webmvc/spring-webmvc-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v5_3/internal/Experimental.java @@ -5,12 +5,8 @@ package io.opentelemetry.instrumentation.spring.webmvc.v5_3.internal; -import static java.util.logging.Level.FINE; - import io.opentelemetry.instrumentation.spring.webmvc.v5_3.SpringWebMvcTelemetryBuilder; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.logging.Logger; +import java.util.function.BiConsumer; import javax.annotation.Nullable; /** @@ -18,37 +14,22 @@ * APIs (or a version of them) may be promoted to the public stable API in the future, but no * guarantees are made. */ -public class Experimental { - - private static final Logger logger = Logger.getLogger(Experimental.class.getName()); +public final class Experimental { @Nullable - private static final Method emitExperimentalTelemetryMethod = - getEmitExperimentalTelemetryMethod(); + private static BiConsumer setEmitExperimentalTelemetry; public void setEmitExperimentalTelemetry( SpringWebMvcTelemetryBuilder builder, boolean emitExperimentalTelemetry) { - - if (emitExperimentalTelemetryMethod != null) { - try { - emitExperimentalTelemetryMethod.invoke(builder, emitExperimentalTelemetry); - } catch (IllegalAccessException | InvocationTargetException e) { - logger.log(FINE, e.getMessage(), e); - } + if (setEmitExperimentalTelemetry != null) { + setEmitExperimentalTelemetry.accept(builder, emitExperimentalTelemetry); } } - @Nullable - private static Method getEmitExperimentalTelemetryMethod() { - try { - Method method = - SpringWebMvcTelemetryBuilder.class.getDeclaredMethod( - "setEmitExperimentalHttpServerMetrics", boolean.class); - method.setAccessible(true); - return method; - } catch (NoSuchMethodException e) { - logger.log(FINE, e.getMessage(), e); - return null; - } + public static void setSetEmitExperimentalTelemetry( + BiConsumer setEmitExperimentalTelemetry) { + Experimental.setEmitExperimentalTelemetry = setEmitExperimentalTelemetry; } + + private Experimental() {} } diff --git a/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v6_0/SpringWebMvcTelemetryBuilder.java b/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v6_0/SpringWebMvcTelemetryBuilder.java index 0f4b82cd64c6..bc5df58458f3 100644 --- a/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v6_0/SpringWebMvcTelemetryBuilder.java +++ b/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v6_0/SpringWebMvcTelemetryBuilder.java @@ -28,6 +28,8 @@ public final class SpringWebMvcTelemetryBuilder { static { SpringMvcBuilderUtil.setBuilderExtractor(builder -> builder.builder); + Experimental.setSetEmitExperimentalTelemetry( + (builder, emit) -> builder.builder.setEmitExperimentalHttpServerMetrics(emit)); } SpringWebMvcTelemetryBuilder(OpenTelemetry openTelemetry) { diff --git a/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v6_0/internal/Experimental.java b/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v6_0/internal/Experimental.java index 5bf6ea9c2c61..f5a30685f0f1 100644 --- a/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v6_0/internal/Experimental.java +++ b/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v6_0/internal/Experimental.java @@ -5,12 +5,8 @@ package io.opentelemetry.instrumentation.spring.webmvc.v6_0.internal; -import static java.util.logging.Level.FINE; - import io.opentelemetry.instrumentation.spring.webmvc.v6_0.SpringWebMvcTelemetryBuilder; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.logging.Logger; +import java.util.function.BiConsumer; import javax.annotation.Nullable; /** @@ -18,37 +14,22 @@ * APIs (or a version of them) may be promoted to the public stable API in the future, but no * guarantees are made. */ -public class Experimental { - - private static final Logger logger = Logger.getLogger(Experimental.class.getName()); +public final class Experimental { @Nullable - private static final Method emitExperimentalTelemetryMethod = - getEmitExperimentalTelemetryMethod(); + private static BiConsumer setEmitExperimentalTelemetry; public void setEmitExperimentalTelemetry( SpringWebMvcTelemetryBuilder builder, boolean emitExperimentalTelemetry) { - - if (emitExperimentalTelemetryMethod != null) { - try { - emitExperimentalTelemetryMethod.invoke(builder, emitExperimentalTelemetry); - } catch (IllegalAccessException | InvocationTargetException e) { - logger.log(FINE, e.getMessage(), e); - } + if (setEmitExperimentalTelemetry != null) { + setEmitExperimentalTelemetry.accept(builder, emitExperimentalTelemetry); } } - @Nullable - private static Method getEmitExperimentalTelemetryMethod() { - try { - Method method = - SpringWebMvcTelemetryBuilder.class.getDeclaredMethod( - "setEmitExperimentalHttpServerMetrics", boolean.class); - method.setAccessible(true); - return method; - } catch (NoSuchMethodException e) { - logger.log(FINE, e.getMessage(), e); - return null; - } + public static void setSetEmitExperimentalTelemetry( + BiConsumer setEmitExperimentalTelemetry) { + Experimental.setEmitExperimentalTelemetry = setEmitExperimentalTelemetry; } + + private Experimental() {} } From 923cab925fd61a56ccba82e132489380651264c6 Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Tue, 10 Dec 2024 19:44:39 -0800 Subject: [PATCH 4/5] volatile --- .../apachehttpclient/v4_3/internal/Experimental.java | 3 ++- .../instrumentation/httpclient/internal/Experimental.java | 3 ++- .../jetty/httpclient/v12_0/internal/Experimental.java | 3 ++- .../jetty/httpclient/v9_2/internal/Experimental.java | 3 ++- .../instrumentation/netty/v4_1/internal/Experimental.java | 4 ++-- .../instrumentation/okhttp/v3_0/internal/Experimental.java | 3 ++- .../instrumentation/restlet/v1_1/internal/Experimental.java | 2 +- .../instrumentation/restlet/v2_0/internal/Experimental.java | 2 +- .../spring/web/v3_1/internal/Experimental.java | 3 ++- .../spring/webmvc/v5_3/internal/Experimental.java | 3 ++- .../spring/webmvc/v6_0/internal/Experimental.java | 3 ++- 11 files changed, 20 insertions(+), 12 deletions(-) diff --git a/instrumentation/apache-httpclient/apache-httpclient-4.3/library/src/main/java/io/opentelemetry/instrumentation/apachehttpclient/v4_3/internal/Experimental.java b/instrumentation/apache-httpclient/apache-httpclient-4.3/library/src/main/java/io/opentelemetry/instrumentation/apachehttpclient/v4_3/internal/Experimental.java index cf9bdc45372c..360f244fa15a 100644 --- a/instrumentation/apache-httpclient/apache-httpclient-4.3/library/src/main/java/io/opentelemetry/instrumentation/apachehttpclient/v4_3/internal/Experimental.java +++ b/instrumentation/apache-httpclient/apache-httpclient-4.3/library/src/main/java/io/opentelemetry/instrumentation/apachehttpclient/v4_3/internal/Experimental.java @@ -17,7 +17,8 @@ public final class Experimental { @Nullable - private static BiConsumer setEmitExperimentalTelemetry; + private static volatile BiConsumer + setEmitExperimentalTelemetry; public void setEmitExperimentalTelemetry( ApacheHttpClientTelemetryBuilder builder, boolean emitExperimentalTelemetry) { diff --git a/instrumentation/java-http-client/library/src/main/java/io/opentelemetry/instrumentation/httpclient/internal/Experimental.java b/instrumentation/java-http-client/library/src/main/java/io/opentelemetry/instrumentation/httpclient/internal/Experimental.java index 931fedfa540e..37e8b87d1bc4 100644 --- a/instrumentation/java-http-client/library/src/main/java/io/opentelemetry/instrumentation/httpclient/internal/Experimental.java +++ b/instrumentation/java-http-client/library/src/main/java/io/opentelemetry/instrumentation/httpclient/internal/Experimental.java @@ -17,7 +17,8 @@ public final class Experimental { @Nullable - private static BiConsumer setEmitExperimentalTelemetry; + private static volatile BiConsumer + setEmitExperimentalTelemetry; public void setEmitExperimentalTelemetry( JavaHttpClientTelemetryBuilder builder, boolean emitExperimentalTelemetry) { diff --git a/instrumentation/jetty-httpclient/jetty-httpclient-12.0/library/src/main/java/io/opentelemetry/instrumentation/jetty/httpclient/v12_0/internal/Experimental.java b/instrumentation/jetty-httpclient/jetty-httpclient-12.0/library/src/main/java/io/opentelemetry/instrumentation/jetty/httpclient/v12_0/internal/Experimental.java index 11d4a2ba1ea9..7fa8a13e5ae8 100644 --- a/instrumentation/jetty-httpclient/jetty-httpclient-12.0/library/src/main/java/io/opentelemetry/instrumentation/jetty/httpclient/v12_0/internal/Experimental.java +++ b/instrumentation/jetty-httpclient/jetty-httpclient-12.0/library/src/main/java/io/opentelemetry/instrumentation/jetty/httpclient/v12_0/internal/Experimental.java @@ -17,7 +17,8 @@ public final class Experimental { @Nullable - private static BiConsumer setEmitExperimentalTelemetry; + private static volatile BiConsumer + setEmitExperimentalTelemetry; public void setEmitExperimentalTelemetry( JettyClientTelemetryBuilder builder, boolean emitExperimentalTelemetry) { diff --git a/instrumentation/jetty-httpclient/jetty-httpclient-9.2/library/src/main/java/io/opentelemetry/instrumentation/jetty/httpclient/v9_2/internal/Experimental.java b/instrumentation/jetty-httpclient/jetty-httpclient-9.2/library/src/main/java/io/opentelemetry/instrumentation/jetty/httpclient/v9_2/internal/Experimental.java index ac78337b28dc..63a211a24599 100644 --- a/instrumentation/jetty-httpclient/jetty-httpclient-9.2/library/src/main/java/io/opentelemetry/instrumentation/jetty/httpclient/v9_2/internal/Experimental.java +++ b/instrumentation/jetty-httpclient/jetty-httpclient-9.2/library/src/main/java/io/opentelemetry/instrumentation/jetty/httpclient/v9_2/internal/Experimental.java @@ -17,7 +17,8 @@ public final class Experimental { @Nullable - private static BiConsumer setEmitExperimentalTelemetry; + private static volatile BiConsumer + setEmitExperimentalTelemetry; public void setEmitExperimentalTelemetry( JettyClientTelemetryBuilder builder, boolean emitExperimentalTelemetry) { diff --git a/instrumentation/netty/netty-4.1/library/src/main/java/io/opentelemetry/instrumentation/netty/v4_1/internal/Experimental.java b/instrumentation/netty/netty-4.1/library/src/main/java/io/opentelemetry/instrumentation/netty/v4_1/internal/Experimental.java index b045eeac0adf..123ae850676c 100644 --- a/instrumentation/netty/netty-4.1/library/src/main/java/io/opentelemetry/instrumentation/netty/v4_1/internal/Experimental.java +++ b/instrumentation/netty/netty-4.1/library/src/main/java/io/opentelemetry/instrumentation/netty/v4_1/internal/Experimental.java @@ -18,11 +18,11 @@ public final class Experimental { @Nullable - private static BiConsumer + private static volatile BiConsumer setEmitExperimentalClientTelemetry; @Nullable - private static BiConsumer + private static volatile BiConsumer setEmitExperimentalServerTelemetry; public void setEmitExperimentalTelemetry( diff --git a/instrumentation/okhttp/okhttp-3.0/library/src/main/java/io/opentelemetry/instrumentation/okhttp/v3_0/internal/Experimental.java b/instrumentation/okhttp/okhttp-3.0/library/src/main/java/io/opentelemetry/instrumentation/okhttp/v3_0/internal/Experimental.java index d448101de4c6..4ddda5281d6c 100644 --- a/instrumentation/okhttp/okhttp-3.0/library/src/main/java/io/opentelemetry/instrumentation/okhttp/v3_0/internal/Experimental.java +++ b/instrumentation/okhttp/okhttp-3.0/library/src/main/java/io/opentelemetry/instrumentation/okhttp/v3_0/internal/Experimental.java @@ -16,7 +16,8 @@ */ public final class Experimental { - @Nullable private static BiConsumer setEmitExperimentalTelemetry; + @Nullable + private static volatile BiConsumer setEmitExperimentalTelemetry; public void setEmitExperimentalTelemetry( OkHttpTelemetryBuilder builder, boolean emitExperimentalTelemetry) { diff --git a/instrumentation/restlet/restlet-1.1/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_1/internal/Experimental.java b/instrumentation/restlet/restlet-1.1/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_1/internal/Experimental.java index 7a84497f06cf..3eb2a6397eed 100644 --- a/instrumentation/restlet/restlet-1.1/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_1/internal/Experimental.java +++ b/instrumentation/restlet/restlet-1.1/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_1/internal/Experimental.java @@ -17,7 +17,7 @@ public final class Experimental { @Nullable - private static BiConsumer setEmitExperimentalTelemetry; + private static volatile BiConsumer setEmitExperimentalTelemetry; public void setEmitExperimentalTelemetry( RestletTelemetryBuilder builder, boolean emitExperimentalTelemetry) { diff --git a/instrumentation/restlet/restlet-2.0/library/src/main/java/io/opentelemetry/instrumentation/restlet/v2_0/internal/Experimental.java b/instrumentation/restlet/restlet-2.0/library/src/main/java/io/opentelemetry/instrumentation/restlet/v2_0/internal/Experimental.java index 2a1852c3bcc9..d9571f2e2f32 100644 --- a/instrumentation/restlet/restlet-2.0/library/src/main/java/io/opentelemetry/instrumentation/restlet/v2_0/internal/Experimental.java +++ b/instrumentation/restlet/restlet-2.0/library/src/main/java/io/opentelemetry/instrumentation/restlet/v2_0/internal/Experimental.java @@ -17,7 +17,7 @@ public final class Experimental { @Nullable - private static BiConsumer setEmitExperimentalTelemetry; + private static volatile BiConsumer setEmitExperimentalTelemetry; public void setEmitExperimentalTelemetry( RestletTelemetryBuilder builder, boolean emitExperimentalTelemetry) { diff --git a/instrumentation/spring/spring-web/spring-web-3.1/library/src/main/java/io/opentelemetry/instrumentation/spring/web/v3_1/internal/Experimental.java b/instrumentation/spring/spring-web/spring-web-3.1/library/src/main/java/io/opentelemetry/instrumentation/spring/web/v3_1/internal/Experimental.java index d97edf5fbd85..9924cac8c26a 100644 --- a/instrumentation/spring/spring-web/spring-web-3.1/library/src/main/java/io/opentelemetry/instrumentation/spring/web/v3_1/internal/Experimental.java +++ b/instrumentation/spring/spring-web/spring-web-3.1/library/src/main/java/io/opentelemetry/instrumentation/spring/web/v3_1/internal/Experimental.java @@ -17,7 +17,8 @@ public final class Experimental { @Nullable - private static BiConsumer setEmitExperimentalTelemetry; + private static volatile BiConsumer + setEmitExperimentalTelemetry; public void setEmitExperimentalTelemetry( SpringWebTelemetryBuilder builder, boolean emitExperimentalTelemetry) { diff --git a/instrumentation/spring/spring-webmvc/spring-webmvc-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v5_3/internal/Experimental.java b/instrumentation/spring/spring-webmvc/spring-webmvc-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v5_3/internal/Experimental.java index 90736534424a..3197123c98b9 100644 --- a/instrumentation/spring/spring-webmvc/spring-webmvc-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v5_3/internal/Experimental.java +++ b/instrumentation/spring/spring-webmvc/spring-webmvc-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v5_3/internal/Experimental.java @@ -17,7 +17,8 @@ public final class Experimental { @Nullable - private static BiConsumer setEmitExperimentalTelemetry; + private static volatile BiConsumer + setEmitExperimentalTelemetry; public void setEmitExperimentalTelemetry( SpringWebMvcTelemetryBuilder builder, boolean emitExperimentalTelemetry) { diff --git a/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v6_0/internal/Experimental.java b/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v6_0/internal/Experimental.java index f5a30685f0f1..917a2b4519e6 100644 --- a/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v6_0/internal/Experimental.java +++ b/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v6_0/internal/Experimental.java @@ -17,7 +17,8 @@ public final class Experimental { @Nullable - private static BiConsumer setEmitExperimentalTelemetry; + private static volatile BiConsumer + setEmitExperimentalTelemetry; public void setEmitExperimentalTelemetry( SpringWebMvcTelemetryBuilder builder, boolean emitExperimentalTelemetry) { From 9ba23d61158213a78eb9594d5eaad486ce166555 Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Tue, 10 Dec 2024 20:28:49 -0800 Subject: [PATCH 5/5] static --- .../apachehttpclient/v4_3/internal/Experimental.java | 2 +- .../instrumentation/httpclient/internal/Experimental.java | 2 +- .../jetty/httpclient/v12_0/internal/Experimental.java | 2 +- .../jetty/httpclient/v9_2/internal/Experimental.java | 2 +- .../instrumentation/netty/v4_1/internal/Experimental.java | 4 ++-- .../instrumentation/okhttp/v3_0/internal/Experimental.java | 2 +- .../instrumentation/restlet/v1_1/internal/Experimental.java | 2 +- .../instrumentation/restlet/v2_0/internal/Experimental.java | 2 +- .../spring/web/v3_1/internal/Experimental.java | 2 +- .../spring/webmvc/v5_3/internal/Experimental.java | 2 +- .../spring/webmvc/v6_0/internal/Experimental.java | 2 +- 11 files changed, 12 insertions(+), 12 deletions(-) diff --git a/instrumentation/apache-httpclient/apache-httpclient-4.3/library/src/main/java/io/opentelemetry/instrumentation/apachehttpclient/v4_3/internal/Experimental.java b/instrumentation/apache-httpclient/apache-httpclient-4.3/library/src/main/java/io/opentelemetry/instrumentation/apachehttpclient/v4_3/internal/Experimental.java index 360f244fa15a..7a0016593f44 100644 --- a/instrumentation/apache-httpclient/apache-httpclient-4.3/library/src/main/java/io/opentelemetry/instrumentation/apachehttpclient/v4_3/internal/Experimental.java +++ b/instrumentation/apache-httpclient/apache-httpclient-4.3/library/src/main/java/io/opentelemetry/instrumentation/apachehttpclient/v4_3/internal/Experimental.java @@ -20,7 +20,7 @@ public final class Experimental { private static volatile BiConsumer setEmitExperimentalTelemetry; - public void setEmitExperimentalTelemetry( + public static void setEmitExperimentalTelemetry( ApacheHttpClientTelemetryBuilder builder, boolean emitExperimentalTelemetry) { if (setEmitExperimentalTelemetry != null) { setEmitExperimentalTelemetry.accept(builder, emitExperimentalTelemetry); diff --git a/instrumentation/java-http-client/library/src/main/java/io/opentelemetry/instrumentation/httpclient/internal/Experimental.java b/instrumentation/java-http-client/library/src/main/java/io/opentelemetry/instrumentation/httpclient/internal/Experimental.java index 37e8b87d1bc4..182b8d4c80e7 100644 --- a/instrumentation/java-http-client/library/src/main/java/io/opentelemetry/instrumentation/httpclient/internal/Experimental.java +++ b/instrumentation/java-http-client/library/src/main/java/io/opentelemetry/instrumentation/httpclient/internal/Experimental.java @@ -20,7 +20,7 @@ public final class Experimental { private static volatile BiConsumer setEmitExperimentalTelemetry; - public void setEmitExperimentalTelemetry( + public static void setEmitExperimentalTelemetry( JavaHttpClientTelemetryBuilder builder, boolean emitExperimentalTelemetry) { if (setEmitExperimentalTelemetry != null) { setEmitExperimentalTelemetry.accept(builder, emitExperimentalTelemetry); diff --git a/instrumentation/jetty-httpclient/jetty-httpclient-12.0/library/src/main/java/io/opentelemetry/instrumentation/jetty/httpclient/v12_0/internal/Experimental.java b/instrumentation/jetty-httpclient/jetty-httpclient-12.0/library/src/main/java/io/opentelemetry/instrumentation/jetty/httpclient/v12_0/internal/Experimental.java index 7fa8a13e5ae8..fc5424f929bd 100644 --- a/instrumentation/jetty-httpclient/jetty-httpclient-12.0/library/src/main/java/io/opentelemetry/instrumentation/jetty/httpclient/v12_0/internal/Experimental.java +++ b/instrumentation/jetty-httpclient/jetty-httpclient-12.0/library/src/main/java/io/opentelemetry/instrumentation/jetty/httpclient/v12_0/internal/Experimental.java @@ -20,7 +20,7 @@ public final class Experimental { private static volatile BiConsumer setEmitExperimentalTelemetry; - public void setEmitExperimentalTelemetry( + public static void setEmitExperimentalTelemetry( JettyClientTelemetryBuilder builder, boolean emitExperimentalTelemetry) { if (setEmitExperimentalTelemetry != null) { setEmitExperimentalTelemetry.accept(builder, emitExperimentalTelemetry); diff --git a/instrumentation/jetty-httpclient/jetty-httpclient-9.2/library/src/main/java/io/opentelemetry/instrumentation/jetty/httpclient/v9_2/internal/Experimental.java b/instrumentation/jetty-httpclient/jetty-httpclient-9.2/library/src/main/java/io/opentelemetry/instrumentation/jetty/httpclient/v9_2/internal/Experimental.java index 63a211a24599..86b0a5d97081 100644 --- a/instrumentation/jetty-httpclient/jetty-httpclient-9.2/library/src/main/java/io/opentelemetry/instrumentation/jetty/httpclient/v9_2/internal/Experimental.java +++ b/instrumentation/jetty-httpclient/jetty-httpclient-9.2/library/src/main/java/io/opentelemetry/instrumentation/jetty/httpclient/v9_2/internal/Experimental.java @@ -20,7 +20,7 @@ public final class Experimental { private static volatile BiConsumer setEmitExperimentalTelemetry; - public void setEmitExperimentalTelemetry( + public static void setEmitExperimentalTelemetry( JettyClientTelemetryBuilder builder, boolean emitExperimentalTelemetry) { if (setEmitExperimentalTelemetry != null) { setEmitExperimentalTelemetry.accept(builder, emitExperimentalTelemetry); diff --git a/instrumentation/netty/netty-4.1/library/src/main/java/io/opentelemetry/instrumentation/netty/v4_1/internal/Experimental.java b/instrumentation/netty/netty-4.1/library/src/main/java/io/opentelemetry/instrumentation/netty/v4_1/internal/Experimental.java index 123ae850676c..d6b2c6c39207 100644 --- a/instrumentation/netty/netty-4.1/library/src/main/java/io/opentelemetry/instrumentation/netty/v4_1/internal/Experimental.java +++ b/instrumentation/netty/netty-4.1/library/src/main/java/io/opentelemetry/instrumentation/netty/v4_1/internal/Experimental.java @@ -25,14 +25,14 @@ public final class Experimental { private static volatile BiConsumer setEmitExperimentalServerTelemetry; - public void setEmitExperimentalTelemetry( + public static void setEmitExperimentalTelemetry( NettyClientTelemetryBuilder builder, boolean emitExperimentalTelemetry) { if (setEmitExperimentalClientTelemetry != null) { setEmitExperimentalClientTelemetry.accept(builder, emitExperimentalTelemetry); } } - public void setEmitExperimentalTelemetry( + public static void setEmitExperimentalTelemetry( NettyServerTelemetryBuilder builder, boolean emitExperimentalTelemetry) { if (setEmitExperimentalServerTelemetry != null) { setEmitExperimentalServerTelemetry.accept(builder, emitExperimentalTelemetry); diff --git a/instrumentation/okhttp/okhttp-3.0/library/src/main/java/io/opentelemetry/instrumentation/okhttp/v3_0/internal/Experimental.java b/instrumentation/okhttp/okhttp-3.0/library/src/main/java/io/opentelemetry/instrumentation/okhttp/v3_0/internal/Experimental.java index 4ddda5281d6c..6762b56ec112 100644 --- a/instrumentation/okhttp/okhttp-3.0/library/src/main/java/io/opentelemetry/instrumentation/okhttp/v3_0/internal/Experimental.java +++ b/instrumentation/okhttp/okhttp-3.0/library/src/main/java/io/opentelemetry/instrumentation/okhttp/v3_0/internal/Experimental.java @@ -19,7 +19,7 @@ public final class Experimental { @Nullable private static volatile BiConsumer setEmitExperimentalTelemetry; - public void setEmitExperimentalTelemetry( + public static void setEmitExperimentalTelemetry( OkHttpTelemetryBuilder builder, boolean emitExperimentalTelemetry) { if (setEmitExperimentalTelemetry != null) { setEmitExperimentalTelemetry.accept(builder, emitExperimentalTelemetry); diff --git a/instrumentation/restlet/restlet-1.1/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_1/internal/Experimental.java b/instrumentation/restlet/restlet-1.1/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_1/internal/Experimental.java index 3eb2a6397eed..da576c6df9b5 100644 --- a/instrumentation/restlet/restlet-1.1/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_1/internal/Experimental.java +++ b/instrumentation/restlet/restlet-1.1/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_1/internal/Experimental.java @@ -19,7 +19,7 @@ public final class Experimental { @Nullable private static volatile BiConsumer setEmitExperimentalTelemetry; - public void setEmitExperimentalTelemetry( + public static void setEmitExperimentalTelemetry( RestletTelemetryBuilder builder, boolean emitExperimentalTelemetry) { if (setEmitExperimentalTelemetry != null) { setEmitExperimentalTelemetry.accept(builder, emitExperimentalTelemetry); diff --git a/instrumentation/restlet/restlet-2.0/library/src/main/java/io/opentelemetry/instrumentation/restlet/v2_0/internal/Experimental.java b/instrumentation/restlet/restlet-2.0/library/src/main/java/io/opentelemetry/instrumentation/restlet/v2_0/internal/Experimental.java index d9571f2e2f32..36a1e95b7e78 100644 --- a/instrumentation/restlet/restlet-2.0/library/src/main/java/io/opentelemetry/instrumentation/restlet/v2_0/internal/Experimental.java +++ b/instrumentation/restlet/restlet-2.0/library/src/main/java/io/opentelemetry/instrumentation/restlet/v2_0/internal/Experimental.java @@ -19,7 +19,7 @@ public final class Experimental { @Nullable private static volatile BiConsumer setEmitExperimentalTelemetry; - public void setEmitExperimentalTelemetry( + public static void setEmitExperimentalTelemetry( RestletTelemetryBuilder builder, boolean emitExperimentalTelemetry) { if (setEmitExperimentalTelemetry != null) { setEmitExperimentalTelemetry.accept(builder, emitExperimentalTelemetry); diff --git a/instrumentation/spring/spring-web/spring-web-3.1/library/src/main/java/io/opentelemetry/instrumentation/spring/web/v3_1/internal/Experimental.java b/instrumentation/spring/spring-web/spring-web-3.1/library/src/main/java/io/opentelemetry/instrumentation/spring/web/v3_1/internal/Experimental.java index 9924cac8c26a..a336b1011e28 100644 --- a/instrumentation/spring/spring-web/spring-web-3.1/library/src/main/java/io/opentelemetry/instrumentation/spring/web/v3_1/internal/Experimental.java +++ b/instrumentation/spring/spring-web/spring-web-3.1/library/src/main/java/io/opentelemetry/instrumentation/spring/web/v3_1/internal/Experimental.java @@ -20,7 +20,7 @@ public final class Experimental { private static volatile BiConsumer setEmitExperimentalTelemetry; - public void setEmitExperimentalTelemetry( + public static void setEmitExperimentalTelemetry( SpringWebTelemetryBuilder builder, boolean emitExperimentalTelemetry) { if (setEmitExperimentalTelemetry != null) { setEmitExperimentalTelemetry.accept(builder, emitExperimentalTelemetry); diff --git a/instrumentation/spring/spring-webmvc/spring-webmvc-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v5_3/internal/Experimental.java b/instrumentation/spring/spring-webmvc/spring-webmvc-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v5_3/internal/Experimental.java index 3197123c98b9..89852cf60065 100644 --- a/instrumentation/spring/spring-webmvc/spring-webmvc-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v5_3/internal/Experimental.java +++ b/instrumentation/spring/spring-webmvc/spring-webmvc-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v5_3/internal/Experimental.java @@ -20,7 +20,7 @@ public final class Experimental { private static volatile BiConsumer setEmitExperimentalTelemetry; - public void setEmitExperimentalTelemetry( + public static void setEmitExperimentalTelemetry( SpringWebMvcTelemetryBuilder builder, boolean emitExperimentalTelemetry) { if (setEmitExperimentalTelemetry != null) { setEmitExperimentalTelemetry.accept(builder, emitExperimentalTelemetry); diff --git a/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v6_0/internal/Experimental.java b/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v6_0/internal/Experimental.java index 917a2b4519e6..6c580539634c 100644 --- a/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v6_0/internal/Experimental.java +++ b/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v6_0/internal/Experimental.java @@ -20,7 +20,7 @@ public final class Experimental { private static volatile BiConsumer setEmitExperimentalTelemetry; - public void setEmitExperimentalTelemetry( + public static void setEmitExperimentalTelemetry( SpringWebMvcTelemetryBuilder builder, boolean emitExperimentalTelemetry) { if (setEmitExperimentalTelemetry != null) { setEmitExperimentalTelemetry.accept(builder, emitExperimentalTelemetry);