Skip to content

Commit

Permalink
Move experimental methods out of public API
Browse files Browse the repository at this point in the history
  • Loading branch information
trask committed Dec 9, 2024
1 parent 4af0dd5 commit eed12e5
Show file tree
Hide file tree
Showing 23 changed files with 700 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -88,7 +89,11 @@ public ApacheHttpClientTelemetryBuilder setKnownMethods(Set<String> 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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -86,7 +87,11 @@ public JavaHttpClientTelemetryBuilder setKnownMethods(Set<String> 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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -101,7 +102,10 @@ public JettyClientTelemetryBuilder setKnownMethods(Set<String> 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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -101,7 +102,10 @@ public JettyClientTelemetryBuilder setKnownMethods(Set<String> 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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -24,17 +25,22 @@
public final class NettyClientTelemetryBuilder {

private final DefaultHttpClientInstrumenterBuilder<HttpRequestAndChannel, HttpResponse> 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;
}

Expand Down Expand Up @@ -95,13 +101,17 @@ public NettyClientTelemetryBuilder setKnownMethods(Set<String> 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;
}

Expand All @@ -124,6 +134,6 @@ public NettyClientTelemetry build() {
NettyConnectionInstrumentationFlag.DISABLED,
NettyConnectionInstrumentationFlag.DISABLED)
.instrumenter(),
emitExperimentalHttpClientEvents);
emitExperimentalTelemetry);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -99,7 +100,10 @@ public NettyServerTelemetryBuilder setKnownMethods(Set<String> 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) {
Expand Down
Loading

0 comments on commit eed12e5

Please sign in to comment.