From 39a1604dd20e506b9d1e9bac1a5d40463417e5b2 Mon Sep 17 00:00:00 2001 From: Lauri Tulmin Date: Sun, 3 Oct 2021 21:05:26 +0300 Subject: [PATCH] Convert liberty dispatcher instrumentation to instrumenter api (#4256) * Convert liberty dispatcher instrumentation to instrumenter api * nullable * Add comment Co-authored-by: Trask Stalnaker --- .../internal/channel/HttpDispatcherLink.java | 4 + .../dispatcher/LibertyConnectionWrapper.java | 32 ----- ...ertyDispatcherHttpAttributesExtractor.java | 101 +++++++++++++++ .../LibertyDispatcherLinkInstrumentation.java | 29 ++--- ...bertyDispatcherNetAttributesExtractor.java | 49 ++++++++ .../LibertyDispatcherRequestGetter.java | 23 ++++ .../LibertyDispatcherSingletons.java | 55 +++++++++ .../dispatcher/LibertyDispatcherTracer.java | 115 ------------------ ...equestWrapper.java => LibertyRequest.java} | 29 ++++- ...ponseWrapper.java => LibertyResponse.java} | 4 +- 10 files changed, 274 insertions(+), 167 deletions(-) delete mode 100644 instrumentation/liberty/liberty-dispatcher/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/liberty/dispatcher/LibertyConnectionWrapper.java create mode 100644 instrumentation/liberty/liberty-dispatcher/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/liberty/dispatcher/LibertyDispatcherHttpAttributesExtractor.java create mode 100644 instrumentation/liberty/liberty-dispatcher/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/liberty/dispatcher/LibertyDispatcherNetAttributesExtractor.java create mode 100644 instrumentation/liberty/liberty-dispatcher/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/liberty/dispatcher/LibertyDispatcherRequestGetter.java create mode 100644 instrumentation/liberty/liberty-dispatcher/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/liberty/dispatcher/LibertyDispatcherSingletons.java delete mode 100644 instrumentation/liberty/liberty-dispatcher/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/liberty/dispatcher/LibertyDispatcherTracer.java rename instrumentation/liberty/liberty-dispatcher/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/liberty/dispatcher/{LibertyRequestWrapper.java => LibertyRequest.java} (72%) rename instrumentation/liberty/liberty-dispatcher/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/liberty/dispatcher/{LibertyResponseWrapper.java => LibertyResponse.java} (78%) diff --git a/instrumentation/liberty/compile-stub/src/main/java/com/ibm/ws/http/dispatcher/internal/channel/HttpDispatcherLink.java b/instrumentation/liberty/compile-stub/src/main/java/com/ibm/ws/http/dispatcher/internal/channel/HttpDispatcherLink.java index c8cd3b15f270..449d7d590164 100644 --- a/instrumentation/liberty/compile-stub/src/main/java/com/ibm/ws/http/dispatcher/internal/channel/HttpDispatcherLink.java +++ b/instrumentation/liberty/compile-stub/src/main/java/com/ibm/ws/http/dispatcher/internal/channel/HttpDispatcherLink.java @@ -16,6 +16,10 @@ public String getRemoteHostAddress() { throw new UnsupportedOperationException(); } + public String getRemoteHostName(boolean canonical) { + throw new UnsupportedOperationException(); + } + public String getRequestedHost() { throw new UnsupportedOperationException(); } diff --git a/instrumentation/liberty/liberty-dispatcher/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/liberty/dispatcher/LibertyConnectionWrapper.java b/instrumentation/liberty/liberty-dispatcher/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/liberty/dispatcher/LibertyConnectionWrapper.java deleted file mode 100644 index 4141a28b5f46..000000000000 --- a/instrumentation/liberty/liberty-dispatcher/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/liberty/dispatcher/LibertyConnectionWrapper.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.javaagent.instrumentation.liberty.dispatcher; - -import com.ibm.ws.http.dispatcher.internal.channel.HttpDispatcherLink; -import com.ibm.wsspi.http.channel.HttpRequestMessage; - -public class LibertyConnectionWrapper { - private final HttpDispatcherLink httpDispatcherLink; - private final HttpRequestMessage httpRequestMessage; - - public LibertyConnectionWrapper( - HttpDispatcherLink httpDispatcherLink, HttpRequestMessage httpRequestMessage) { - this.httpDispatcherLink = httpDispatcherLink; - this.httpRequestMessage = httpRequestMessage; - } - - public int peerPort() { - return httpDispatcherLink.getRemotePort(); - } - - public String peerHostIp() { - return httpDispatcherLink.getRemoteHostAddress(); - } - - public String getProtocol() { - return httpRequestMessage.getVersion(); - } -} diff --git a/instrumentation/liberty/liberty-dispatcher/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/liberty/dispatcher/LibertyDispatcherHttpAttributesExtractor.java b/instrumentation/liberty/liberty-dispatcher/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/liberty/dispatcher/LibertyDispatcherHttpAttributesExtractor.java new file mode 100644 index 000000000000..ccb41f08abac --- /dev/null +++ b/instrumentation/liberty/liberty-dispatcher/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/liberty/dispatcher/LibertyDispatcherHttpAttributesExtractor.java @@ -0,0 +1,101 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.javaagent.instrumentation.liberty.dispatcher; + +import io.opentelemetry.instrumentation.api.instrumenter.http.HttpServerAttributesExtractor; +import org.checkerframework.checker.nullness.qual.Nullable; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class LibertyDispatcherHttpAttributesExtractor + extends HttpServerAttributesExtractor { + private static final Logger logger = + LoggerFactory.getLogger(LibertyDispatcherHttpAttributesExtractor.class); + + @Override + protected @Nullable String method(LibertyRequest libertyRequest) { + return libertyRequest.getMethod(); + } + + @Override + protected @Nullable String userAgent(LibertyRequest libertyRequest) { + return libertyRequest.getHeaderValue("User-Agent"); + } + + @Override + protected @Nullable Long requestContentLength( + LibertyRequest libertyRequest, @Nullable LibertyResponse libertyResponse) { + return null; + } + + @Override + protected @Nullable Long requestContentLengthUncompressed( + LibertyRequest libertyRequest, @Nullable LibertyResponse libertyResponse) { + return null; + } + + @Override + protected @Nullable String flavor( + LibertyRequest libertyRequest, @Nullable LibertyResponse libertyResponse) { + String flavor = libertyRequest.getProtocol(); + if (flavor != null) { + // remove HTTP/ prefix to comply with semantic conventions + if (flavor.startsWith("HTTP/")) { + flavor = flavor.substring("HTTP/".length()); + } + } + return flavor; + } + + @Override + protected @Nullable Integer statusCode( + LibertyRequest libertyRequest, LibertyResponse libertyResponse) { + return libertyResponse.getStatus(); + } + + @Override + protected @Nullable Long responseContentLength( + LibertyRequest libertyRequest, LibertyResponse libertyResponse) { + return null; + } + + @Override + protected @Nullable Long responseContentLengthUncompressed( + LibertyRequest libertyRequest, LibertyResponse libertyResponse) { + return null; + } + + @Override + protected @Nullable String target(LibertyRequest libertyRequest) { + String requestUri = libertyRequest.getRequestUri(); + String queryString = libertyRequest.getQueryString(); + if (queryString != null && !queryString.isEmpty()) { + return requestUri + "?" + queryString; + } + return requestUri; + } + + @Override + protected String host(LibertyRequest libertyRequest) { + return libertyRequest.getServerName() + ":" + libertyRequest.getServerPort(); + } + + @Override + protected @Nullable String scheme(LibertyRequest libertyRequest) { + return libertyRequest.getScheme(); + } + + @Override + protected @Nullable String route(LibertyRequest libertyRequest) { + return null; + } + + @Override + protected @Nullable String serverName( + LibertyRequest libertyRequest, @Nullable LibertyResponse libertyResponse) { + return null; + } +} diff --git a/instrumentation/liberty/liberty-dispatcher/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/liberty/dispatcher/LibertyDispatcherLinkInstrumentation.java b/instrumentation/liberty/liberty-dispatcher/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/liberty/dispatcher/LibertyDispatcherLinkInstrumentation.java index 5c597355e72b..acf7d195372c 100644 --- a/instrumentation/liberty/liberty-dispatcher/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/liberty/dispatcher/LibertyDispatcherLinkInstrumentation.java +++ b/instrumentation/liberty/liberty-dispatcher/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/liberty/dispatcher/LibertyDispatcherLinkInstrumentation.java @@ -5,7 +5,7 @@ package io.opentelemetry.javaagent.instrumentation.liberty.dispatcher; -import static io.opentelemetry.javaagent.instrumentation.liberty.dispatcher.LibertyDispatcherTracer.tracer; +import static io.opentelemetry.javaagent.instrumentation.liberty.dispatcher.LibertyDispatcherSingletons.instrumenter; import static net.bytebuddy.matcher.ElementMatchers.named; import static net.bytebuddy.matcher.ElementMatchers.takesArgument; @@ -16,6 +16,7 @@ import io.opentelemetry.context.Scope; import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer; +import io.opentelemetry.javaagent.instrumentation.api.Java8BytecodeBridge; import net.bytebuddy.asm.Advice; import net.bytebuddy.description.type.TypeDescription; import net.bytebuddy.matcher.ElementMatcher; @@ -53,16 +54,15 @@ public static class SendResponseAdvice { public static void onEnter( @Advice.This HttpDispatcherLink httpDispatcherLink, @Advice.FieldValue("isc") HttpInboundServiceContextImpl isc, + @Advice.Local("otelRequest") LibertyRequest request, @Advice.Local("otelContext") Context context, @Advice.Local("otelScope") Scope scope) { - LibertyRequestWrapper requestWrapper = - new LibertyRequestWrapper(httpDispatcherLink, isc.getRequest()); - LibertyConnectionWrapper connectionWrapper = - new LibertyConnectionWrapper(httpDispatcherLink, isc.getRequest()); - context = - tracer() - .startSpan( - requestWrapper, connectionWrapper, null, "HTTP " + requestWrapper.getMethod()); + Context parentContext = Java8BytecodeBridge.currentContext(); + request = new LibertyRequest(httpDispatcherLink, isc.getRequest()); + if (!instrumenter().shouldStart(parentContext, request)) { + return; + } + context = instrumenter().start(parentContext, request); scope = context.makeCurrent(); } @@ -71,6 +71,7 @@ public static void stopSpan( @Advice.Thrown Throwable throwable, @Advice.Argument(value = 0) StatusCodes statusCode, @Advice.Argument(value = 2) Exception failure, + @Advice.Local("otelRequest") LibertyRequest request, @Advice.Local("otelContext") Context context, @Advice.Local("otelScope") Scope scope) { if (scope == null) { @@ -78,15 +79,11 @@ public static void stopSpan( } scope.close(); - LibertyResponseWrapper responseWrapper = new LibertyResponseWrapper(statusCode); + LibertyResponse response = new LibertyResponse(statusCode); + request.setCompleted(); Throwable t = failure != null ? failure : throwable; - if (t != null) { - tracer().endExceptionally(context, t, responseWrapper); - return; - } - - tracer().end(context, responseWrapper); + instrumenter().end(context, request, response, t); } } } diff --git a/instrumentation/liberty/liberty-dispatcher/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/liberty/dispatcher/LibertyDispatcherNetAttributesExtractor.java b/instrumentation/liberty/liberty-dispatcher/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/liberty/dispatcher/LibertyDispatcherNetAttributesExtractor.java new file mode 100644 index 000000000000..a92444eabe39 --- /dev/null +++ b/instrumentation/liberty/liberty-dispatcher/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/liberty/dispatcher/LibertyDispatcherNetAttributesExtractor.java @@ -0,0 +1,49 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.javaagent.instrumentation.liberty.dispatcher; + +import io.opentelemetry.instrumentation.api.instrumenter.net.NetAttributesExtractor; +import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; +import org.checkerframework.checker.nullness.qual.Nullable; + +public class LibertyDispatcherNetAttributesExtractor + extends NetAttributesExtractor { + + @Override + public String transport(LibertyRequest libertyRequest) { + return SemanticAttributes.NetTransportValues.IP_TCP; + } + + @Override + public @Nullable String peerName( + LibertyRequest libertyRequest, @Nullable LibertyResponse libertyResponse) { + // condition limits calling peerName to onStart because in onEnd it may throw a NPE + if (!libertyRequest.isCompleted()) { + return libertyRequest.peerName(); + } + return null; + } + + @Override + public @Nullable Integer peerPort( + LibertyRequest libertyRequest, @Nullable LibertyResponse libertyResponse) { + // condition limits calling getServerPort to onStart because in onEnd it may throw a NPE + if (!libertyRequest.isCompleted()) { + return libertyRequest.getServerPort(); + } + return null; + } + + @Override + public @Nullable String peerIp( + LibertyRequest libertyRequest, @Nullable LibertyResponse libertyResponse) { + // condition limits calling peerIp to onStart because in onEnd it may throw a NPE + if (!libertyRequest.isCompleted()) { + return libertyRequest.peerIp(); + } + return null; + } +} diff --git a/instrumentation/liberty/liberty-dispatcher/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/liberty/dispatcher/LibertyDispatcherRequestGetter.java b/instrumentation/liberty/liberty-dispatcher/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/liberty/dispatcher/LibertyDispatcherRequestGetter.java new file mode 100644 index 000000000000..9e2e801c46f5 --- /dev/null +++ b/instrumentation/liberty/liberty-dispatcher/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/liberty/dispatcher/LibertyDispatcherRequestGetter.java @@ -0,0 +1,23 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.javaagent.instrumentation.liberty.dispatcher; + +import io.opentelemetry.context.propagation.TextMapGetter; + +public class LibertyDispatcherRequestGetter implements TextMapGetter { + + public static final LibertyDispatcherRequestGetter GETTER = new LibertyDispatcherRequestGetter(); + + @Override + public Iterable keys(LibertyRequest carrier) { + return carrier.getAllHeaderNames(); + } + + @Override + public String get(LibertyRequest carrier, String key) { + return carrier.getHeaderValue(key); + } +} diff --git a/instrumentation/liberty/liberty-dispatcher/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/liberty/dispatcher/LibertyDispatcherSingletons.java b/instrumentation/liberty/liberty-dispatcher/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/liberty/dispatcher/LibertyDispatcherSingletons.java new file mode 100644 index 000000000000..c7925cf3c2f1 --- /dev/null +++ b/instrumentation/liberty/liberty-dispatcher/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/liberty/dispatcher/LibertyDispatcherSingletons.java @@ -0,0 +1,55 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.javaagent.instrumentation.liberty.dispatcher; + +import static io.opentelemetry.instrumentation.api.servlet.ServerSpanNaming.Source.CONTAINER; + +import io.opentelemetry.api.GlobalOpenTelemetry; +import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; +import io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.SpanStatusExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.http.HttpServerAttributesExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.http.HttpServerMetrics; +import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanStatusExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.net.NetAttributesExtractor; +import io.opentelemetry.instrumentation.api.servlet.ServerSpanNaming; +import io.opentelemetry.javaagent.instrumentation.api.instrumenter.PeerServiceAttributesExtractor; + +public final class LibertyDispatcherSingletons { + private static final String INSTRUMENTATION_NAME = "io.opentelemetry.liberty-dispatcher"; + + private static final Instrumenter INSTRUMENTER; + + static { + HttpServerAttributesExtractor httpAttributesExtractor = + new LibertyDispatcherHttpAttributesExtractor(); + SpanNameExtractor spanNameExtractor = + HttpSpanNameExtractor.create(httpAttributesExtractor); + SpanStatusExtractor spanStatusExtractor = + HttpSpanStatusExtractor.create(httpAttributesExtractor); + NetAttributesExtractor netAttributesExtractor = + new LibertyDispatcherNetAttributesExtractor(); + + INSTRUMENTER = + Instrumenter.newBuilder( + GlobalOpenTelemetry.get(), INSTRUMENTATION_NAME, spanNameExtractor) + .setSpanStatusExtractor(spanStatusExtractor) + .addAttributesExtractor(httpAttributesExtractor) + .addAttributesExtractor(netAttributesExtractor) + .addAttributesExtractor(PeerServiceAttributesExtractor.create(netAttributesExtractor)) + .addContextCustomizer( + (context, request, attributes) -> ServerSpanNaming.init(context, CONTAINER)) + .addRequestMetrics(HttpServerMetrics.get()) + .newServerInstrumenter(LibertyDispatcherRequestGetter.GETTER); + } + + public static Instrumenter instrumenter() { + return INSTRUMENTER; + } + + private LibertyDispatcherSingletons() {} +} diff --git a/instrumentation/liberty/liberty-dispatcher/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/liberty/dispatcher/LibertyDispatcherTracer.java b/instrumentation/liberty/liberty-dispatcher/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/liberty/dispatcher/LibertyDispatcherTracer.java deleted file mode 100644 index 9ffe94141d14..000000000000 --- a/instrumentation/liberty/liberty-dispatcher/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/liberty/dispatcher/LibertyDispatcherTracer.java +++ /dev/null @@ -1,115 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.javaagent.instrumentation.liberty.dispatcher; - -import io.opentelemetry.context.Context; -import io.opentelemetry.context.propagation.TextMapGetter; -import io.opentelemetry.instrumentation.api.tracer.HttpServerTracer; -import org.checkerframework.checker.nullness.qual.Nullable; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class LibertyDispatcherTracer - extends HttpServerTracer< - LibertyRequestWrapper, LibertyResponseWrapper, LibertyConnectionWrapper, Void> { - private static final Logger logger = LoggerFactory.getLogger(LibertyDispatcherTracer.class); - private static final LibertyDispatcherTracer TRACER = new LibertyDispatcherTracer(); - - public static LibertyDispatcherTracer tracer() { - return TRACER; - } - - @Override - protected String getInstrumentationName() { - return "io.opentelemetry.liberty-dispatcher"; - } - - @Override - @Nullable - protected Integer peerPort(LibertyConnectionWrapper libertyConnectionWrapper) { - return libertyConnectionWrapper.peerPort(); - } - - @Override - @Nullable - protected String peerHostIp(LibertyConnectionWrapper libertyConnectionWrapper) { - return libertyConnectionWrapper.peerHostIp(); - } - - @Override - protected String flavor( - LibertyConnectionWrapper libertyConnectionWrapper, - LibertyRequestWrapper libertyRequestWrapper) { - return libertyConnectionWrapper.getProtocol(); - } - - private static final TextMapGetter GETTER = - new TextMapGetter() { - - @Override - public Iterable keys(LibertyRequestWrapper carrier) { - return carrier.getAllHeaderNames(); - } - - @Override - public String get(LibertyRequestWrapper carrier, String key) { - return carrier.getHeaderValue(key); - } - }; - - @Override - protected TextMapGetter getGetter() { - return GETTER; - } - - @Override - protected String scheme(LibertyRequestWrapper libertyRequestWrapper) { - return libertyRequestWrapper.getScheme(); - } - - @Override - protected String host(LibertyRequestWrapper libertyRequestWrapper) { - return libertyRequestWrapper.getServerName() + ":" + libertyRequestWrapper.getServerPort(); - } - - @Override - protected String target(LibertyRequestWrapper libertyRequestWrapper) { - String target = libertyRequestWrapper.getRequestUri(); - String queryString = libertyRequestWrapper.getQueryString(); - if (queryString != null) { - target += "?" + queryString; - } - return target; - } - - @Override - protected String method(LibertyRequestWrapper libertyRequestWrapper) { - return libertyRequestWrapper.getMethod(); - } - - @Override - protected @Nullable String requestHeader( - LibertyRequestWrapper libertyRequestWrapper, String name) { - return libertyRequestWrapper.getHeaderValue(name); - } - - @Override - protected int responseStatus(LibertyResponseWrapper libertyResponseWrapper) { - return libertyResponseWrapper.getStatus(); - } - - @Override - @Nullable - public Context getServerContext(Void none) { - return null; - } - - @Override - protected void attachServerContext(Context context, Void none) { - // This advice is only used when server didn't find matching application or got an internal - // error. Nothing that is called within this advice should require access to the span. - } -} diff --git a/instrumentation/liberty/liberty-dispatcher/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/liberty/dispatcher/LibertyRequestWrapper.java b/instrumentation/liberty/liberty-dispatcher/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/liberty/dispatcher/LibertyRequest.java similarity index 72% rename from instrumentation/liberty/liberty-dispatcher/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/liberty/dispatcher/LibertyRequestWrapper.java rename to instrumentation/liberty/liberty-dispatcher/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/liberty/dispatcher/LibertyRequest.java index 2fcc791afdec..549173c7b4e6 100644 --- a/instrumentation/liberty/liberty-dispatcher/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/liberty/dispatcher/LibertyRequestWrapper.java +++ b/instrumentation/liberty/liberty-dispatcher/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/liberty/dispatcher/LibertyRequest.java @@ -10,11 +10,12 @@ import com.ibm.wsspi.http.channel.HttpRequestMessage; import java.util.List; -public class LibertyRequestWrapper { +public class LibertyRequest { private final HttpDispatcherLink httpDispatcherLink; private final HttpRequestMessage httpRequestMessage; + private boolean completed; - public LibertyRequestWrapper( + public LibertyRequest( HttpDispatcherLink httpDispatcherLink, HttpRequestMessage httpRequestMessage) { this.httpDispatcherLink = httpDispatcherLink; this.httpRequestMessage = httpRequestMessage; @@ -52,4 +53,28 @@ public String getHeaderValue(String name) { HeaderField hf = httpRequestMessage.getHeader(name); return hf != null ? hf.asString() : null; } + + public int peerPort() { + return httpDispatcherLink.getRemotePort(); + } + + public String peerIp() { + return httpDispatcherLink.getRemoteHostAddress(); + } + + public String peerName() { + return httpDispatcherLink.getRemoteHostName(false); + } + + public String getProtocol() { + return httpRequestMessage.getVersion(); + } + + public boolean isCompleted() { + return completed; + } + + public void setCompleted() { + completed = true; + } } diff --git a/instrumentation/liberty/liberty-dispatcher/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/liberty/dispatcher/LibertyResponseWrapper.java b/instrumentation/liberty/liberty-dispatcher/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/liberty/dispatcher/LibertyResponse.java similarity index 78% rename from instrumentation/liberty/liberty-dispatcher/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/liberty/dispatcher/LibertyResponseWrapper.java rename to instrumentation/liberty/liberty-dispatcher/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/liberty/dispatcher/LibertyResponse.java index 0950b8f2fc46..8d58d0c61f64 100644 --- a/instrumentation/liberty/liberty-dispatcher/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/liberty/dispatcher/LibertyResponseWrapper.java +++ b/instrumentation/liberty/liberty-dispatcher/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/liberty/dispatcher/LibertyResponse.java @@ -7,10 +7,10 @@ import com.ibm.wsspi.http.channel.values.StatusCodes; -public class LibertyResponseWrapper { +public class LibertyResponse { private final StatusCodes code; - public LibertyResponseWrapper(StatusCodes code) { + public LibertyResponse(StatusCodes code) { this.code = code; }