Expose only minimal entrypoint for Armeria library instrumentation.
MODIFY
instrumentation/armeria-1.3/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/armeria/v1_3/ArmeriaDecorators.java
instrumentation/armeria-1.3/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/armeria/v1_3/ArmeriaDecorators.java
@@ -7,17 +7,19 @@ package io.opentelemetry.javaagent.instrumentation.armeria.v1_3;
import com.linecorp.armeria.client.HttpClient;
import com.linecorp.armeria.server.HttpService;
-import io.opentelemetry.instrumentation.armeria.v1_3.client.OpenTelemetryClient;
-import io.opentelemetry.instrumentation.armeria.v1_3.server.OpenTelemetryService;
+import io.opentelemetry.api.GlobalOpenTelemetry;
+import io.opentelemetry.instrumentation.armeria.v1_3.ArmeriaTracing;
import java.util.function.Function;
// Holds singleton references to decorators to match against during suppression.
// https://github.com/open-telemetry/opentelemetry-java-instrumentation/issues/903
public final class ArmeriaDecorators {
+ private static final ArmeriaTracing TRACING = ArmeriaTracing.create(GlobalOpenTelemetry.get());
+
public static final Function<? super HttpClient, ? extends HttpClient> CLIENT_DECORATOR =
- OpenTelemetryClient.newDecorator();
+ TRACING.newClientDecorator();
public static final Function<? super HttpService, ? extends HttpService> SERVER_DECORATOR =
- OpenTelemetryService.newDecorator();
+ TRACING.newServiceDecorator();
}

RENAME
instrumentation/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/client/ArmeriaClientTracer.java
instrumentation/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/ArmeriaClientTracer.java
* SPDX-License-Identifier: Apache-2.0
*/
-package io.opentelemetry.instrumentation.armeria.v1_3.client;
+package io.opentelemetry.instrumentation.armeria.v1_3;
import com.linecorp.armeria.client.ClientRequestContext;
import com.linecorp.armeria.client.UnprocessedRequestException;
import com.linecorp.armeria.common.HttpRequest;
import com.linecorp.armeria.common.SessionProtocol;
import com.linecorp.armeria.common.logging.RequestLog;
-import io.opentelemetry.api.trace.Tracer;
+import io.opentelemetry.api.OpenTelemetry;
import io.opentelemetry.context.propagation.TextMapSetter;
import io.opentelemetry.instrumentation.api.tracer.HttpClientTracer;
import java.net.URI;
import java.net.URISyntaxException;
import org.checkerframework.checker.nullness.qual.Nullable;
-public class ArmeriaClientTracer
+final class ArmeriaClientTracer
extends HttpClientTracer<ClientRequestContext, ClientRequestContext, RequestLog> {
- ArmeriaClientTracer() {}
-
- ArmeriaClientTracer(Tracer tracer) {
- super(tracer);
+ ArmeriaClientTracer(OpenTelemetry openTelemetry) {
+ super(openTelemetry);
}
@Override

RENAME
instrumentation/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/server/ArmeriaServerTracer.java
instrumentation/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/ArmeriaServerTracer.java
* SPDX-License-Identifier: Apache-2.0
*/
-package io.opentelemetry.instrumentation.armeria.v1_3.server;
+package io.opentelemetry.instrumentation.armeria.v1_3;
import com.linecorp.armeria.common.HttpRequest;
import com.linecorp.armeria.common.SessionProtocol;
import com.linecorp.armeria.common.logging.RequestLog;
import com.linecorp.armeria.server.ServiceRequestContext;
import io.netty.util.AsciiString;
-import io.opentelemetry.api.trace.Tracer;
+import io.opentelemetry.api.OpenTelemetry;
import io.opentelemetry.context.Context;
import io.opentelemetry.context.propagation.TextMapGetter;
import io.opentelemetry.instrumentation.api.tracer.HttpServerTracer;
@@ -19,13 +19,11 @@ import java.net.SocketAddress;
import java.util.stream.Collectors;
import org.checkerframework.checker.nullness.qual.Nullable;
-public class ArmeriaServerTracer
+final class ArmeriaServerTracer
extends HttpServerTracer<HttpRequest, RequestLog, ServiceRequestContext, Void> {
- ArmeriaServerTracer() {}
-
- ArmeriaServerTracer(Tracer tracer) {
- super(tracer);
+ ArmeriaServerTracer(OpenTelemetry openTelemetry) {
+ super(openTelemetry);
}
@Override

ADD
instrumentation/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/ArmeriaTracing.java
+/*
+ * Copyright The OpenTelemetry Authors
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+package io.opentelemetry.instrumentation.armeria.v1_3;
+
+import com.linecorp.armeria.client.HttpClient;
+import com.linecorp.armeria.server.HttpService;
+import io.opentelemetry.api.OpenTelemetry;
+import java.util.function.Function;
+
+/** Entrypoint for tracing Armeria services or clients. */
+public final class ArmeriaTracing {
+
+ /** Returns a new {@link ArmeriaTracing} configured with the given {@link OpenTelemetry}. */
+ public static ArmeriaTracing create(OpenTelemetry openTelemetry) {
+ return new ArmeriaTracing(openTelemetry);
+ }
+
+ private final ArmeriaClientTracer clientTracer;
+ private final ArmeriaServerTracer serverTracer;
+
+ private ArmeriaTracing(OpenTelemetry openTelemetry) {
+ clientTracer = new ArmeriaClientTracer(openTelemetry);
+ serverTracer = new ArmeriaServerTracer(openTelemetry);
+ }
+
+ /**
+ * Returns a new {@link HttpClient} decorator for use with methods like {@link
+ * com.linecorp.armeria.client.ClientBuilder#decorator(Function)}.
+ */
+ public Function<? super HttpClient, ? extends HttpClient> newClientDecorator() {
+ return client -> new OpenTelemetryClient(client, clientTracer);
+ }
+
+ /**
+ * Returns a new {@link HttpService} decorator for use with methods like {@link
+ * HttpService#decorate(Function)}.
+ */
+ public Function<? super HttpService, ? extends HttpService> newServiceDecorator() {
+ return service -> new OpenTelemetryService(service, serverTracer);
+ }
+}

RENAME
instrumentation/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/client/OpenTelemetryClient.java
instrumentation/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/OpenTelemetryClient.java
* SPDX-License-Identifier: Apache-2.0
*/
-package io.opentelemetry.instrumentation.armeria.v1_3.client;
+package io.opentelemetry.instrumentation.armeria.v1_3;
import com.linecorp.armeria.client.ClientRequestContext;
import com.linecorp.armeria.client.HttpClient;
@@ -12,37 +12,17 @@ import com.linecorp.armeria.common.HttpRequest;
import com.linecorp.armeria.common.HttpResponse;
import com.linecorp.armeria.common.logging.RequestLogProperty;
import io.opentelemetry.api.trace.Span;
-import io.opentelemetry.api.trace.Tracer;
import io.opentelemetry.context.Context;
import io.opentelemetry.context.Scope;
import io.opentelemetry.instrumentation.api.tracer.utils.NetPeerUtils;
import java.util.concurrent.TimeUnit;
-import java.util.function.Function;
/** Decorates an {@link HttpClient} to trace outbound {@link HttpResponse}s. */
-public class OpenTelemetryClient extends SimpleDecoratingHttpClient {
-
- /** Creates a new tracing {@link HttpClient} decorator using the default {@link Tracer}. */
- public static OpenTelemetryClient.Decorator newDecorator() {
- return new Decorator(new ArmeriaClientTracer());
- }
-
- /** Creates a new tracing {@link HttpClient} decorator using the specified {@link Tracer}. */
- public static OpenTelemetryClient.Decorator newDecorator(Tracer tracer) {
- return new Decorator(new ArmeriaClientTracer(tracer));
- }
-
- /**
- * Creates a new tracing {@link HttpClient} decorator using the specified {@link
- * ArmeriaClientTracer}.
- */
- public static OpenTelemetryClient.Decorator newDecorator(ArmeriaClientTracer clientTracer) {
- return new Decorator(clientTracer);
- }
+final class OpenTelemetryClient extends SimpleDecoratingHttpClient {
private final ArmeriaClientTracer clientTracer;
- private OpenTelemetryClient(HttpClient delegate, ArmeriaClientTracer clientTracer) {
+ OpenTelemetryClient(HttpClient delegate, ArmeriaClientTracer clientTracer) {
super(delegate);
this.clientTracer = clientTracer;
}
@@ -77,18 +57,4 @@ public class OpenTelemetryClient extends SimpleDecoratingHttpClient {
return unwrap().execute(ctx, req);
}
}
-
- private static class Decorator implements Function<HttpClient, OpenTelemetryClient> {
-
- private final ArmeriaClientTracer clientTracer;
-
- private Decorator(ArmeriaClientTracer clientTracer) {
- this.clientTracer = clientTracer;
- }
-
- @Override
- public OpenTelemetryClient apply(HttpClient httpClient) {
- return new OpenTelemetryClient(httpClient, clientTracer);
- }
- }
}

RENAME
instrumentation/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/server/OpenTelemetryService.java
instrumentation/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/OpenTelemetryService.java
* SPDX-License-Identifier: Apache-2.0
*/
-package io.opentelemetry.instrumentation.armeria.v1_3.server;
+package io.opentelemetry.instrumentation.armeria.v1_3;
import com.linecorp.armeria.common.HttpRequest;
import com.linecorp.armeria.common.HttpResponse;
@@ -13,37 +13,16 @@ import com.linecorp.armeria.server.HttpService;
import com.linecorp.armeria.server.ServiceRequestContext;
import com.linecorp.armeria.server.SimpleDecoratingHttpService;
import io.opentelemetry.api.trace.Span;
-import io.opentelemetry.api.trace.Tracer;
import io.opentelemetry.context.Context;
import io.opentelemetry.context.Scope;
import java.util.concurrent.TimeUnit;
-import java.util.function.Function;
/** Decorates an {@link HttpService} to trace inbound {@link HttpRequest}s. */
-public class OpenTelemetryService extends SimpleDecoratingHttpService {
-
- /** Creates a new tracing {@link HttpService} decorator using the default {@link Tracer}. */
- public static Function<? super HttpService, OpenTelemetryService> newDecorator() {
- return newDecorator(new ArmeriaServerTracer());
- }
-
- /** Creates a new tracing {@link HttpService} decorator using the specified {@link Tracer}. */
- public static Function<? super HttpService, OpenTelemetryService> newDecorator(Tracer tracer) {
- return newDecorator(new ArmeriaServerTracer(tracer));
- }
-
- /**
- * Creates a new tracing {@link HttpService} decorator using the specified {@link
- * ArmeriaServerTracer}.
- */
- public static Function<? super HttpService, OpenTelemetryService> newDecorator(
- ArmeriaServerTracer serverTracer) {
- return new Decorator(serverTracer);
- }
+final class OpenTelemetryService extends SimpleDecoratingHttpService {
private final ArmeriaServerTracer serverTracer;
- private OpenTelemetryService(HttpService delegate, ArmeriaServerTracer serverTracer) {
+ OpenTelemetryService(HttpService delegate, ArmeriaServerTracer serverTracer) {
super(delegate);
this.serverTracer = serverTracer;
}
@@ -83,18 +62,4 @@ public class OpenTelemetryService extends SimpleDecoratingHttpService {
return unwrap().serve(ctx, req);
}
}
-
- private static class Decorator implements Function<HttpService, OpenTelemetryService> {
-
- private final ArmeriaServerTracer serverTracer;
-
- private Decorator(ArmeriaServerTracer serverTracer) {
- this.serverTracer = serverTracer;
- }
-
- @Override
- public OpenTelemetryService apply(HttpService httpService) {
- return new OpenTelemetryService(httpService, serverTracer);
- }
- }
}

MODIFY
instrumentation/armeria-1.3/library/src/test/groovy/io/opentelemetry/instrumentation/armeria/v1_3/ArmeriaHttpClientTest.groovy
instrumentation/armeria-1.3/library/src/test/groovy/io/opentelemetry/instrumentation/armeria/v1_3/ArmeriaHttpClientTest.groovy
package io.opentelemetry.instrumentation.armeria.v1_3
import com.linecorp.armeria.client.WebClientBuilder
-import io.opentelemetry.instrumentation.armeria.v1_3.client.OpenTelemetryClient
import io.opentelemetry.instrumentation.test.LibraryTestTrait
class ArmeriaHttpClientTest extends AbstractArmeriaHttpClientTest implements LibraryTestTrait {
@Override
WebClientBuilder configureClient(WebClientBuilder clientBuilder) {
- return clientBuilder.decorator(OpenTelemetryClient.newDecorator())
+ return clientBuilder.decorator(ArmeriaTracing.create(getOpenTelemetry()).newClientDecorator())
}
}

MODIFY
instrumentation/armeria-1.3/library/src/test/groovy/io/opentelemetry/instrumentation/armeria/v1_3/ArmeriaHttpServerTest.groovy
instrumentation/armeria-1.3/library/src/test/groovy/io/opentelemetry/instrumentation/armeria/v1_3/ArmeriaHttpServerTest.groovy
package io.opentelemetry.instrumentation.armeria.v1_3
import com.linecorp.armeria.server.ServerBuilder
-import io.opentelemetry.instrumentation.armeria.v1_3.server.OpenTelemetryService
import io.opentelemetry.instrumentation.test.LibraryTestTrait
class ArmeriaHttpServerTest extends AbstractArmeriaHttpServerTest implements LibraryTestTrait{
@Override
ServerBuilder configureServer(ServerBuilder sb) {
- return sb.decorator(OpenTelemetryService.newDecorator())
+ return sb.decorator(ArmeriaTracing.create(getOpenTelemetry()).newServiceDecorator())
}
}

MODIFY
testing-common/src/main/groovy/io/opentelemetry/instrumentation/test/LibraryTestTrait.groovy
testing-common/src/main/groovy/io/opentelemetry/instrumentation/test/LibraryTestTrait.groovy
package io.opentelemetry.instrumentation.test
-
+import io.opentelemetry.api.OpenTelemetry
import io.opentelemetry.instrumentation.testing.LibraryTestRunner
/**
* A trait which initializes instrumentation library tests, including a test span exporter. All
@@ -18,4 +18,8 @@ trait LibraryTestTrait {
LibraryTestRunner testRunner() {
RUNNER
}
+
+ OpenTelemetry getOpenTelemetry() {
+ RUNNER.openTelemetrySdk
+ }
}

Expose only minimal entrypoint for Armeria library instrumentation. (#2463)