Split peer connection details different generic argument
This commit is contained in:
parent
bf05984208
commit
b343fe4551
|
@ -4,18 +4,21 @@ import datadog.trace.api.Config;
|
||||||
import datadog.trace.api.DDSpanTypes;
|
import datadog.trace.api.DDSpanTypes;
|
||||||
import io.opentracing.Span;
|
import io.opentracing.Span;
|
||||||
import io.opentracing.tag.Tags;
|
import io.opentracing.tag.Tags;
|
||||||
|
import java.net.URI;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
public abstract class HttpServerDecorator<REQUEST, RESPONSE> extends ServerDecorator {
|
@Slf4j
|
||||||
|
public abstract class HttpServerDecorator<REQUEST, CONNECTION, RESPONSE> extends ServerDecorator {
|
||||||
|
|
||||||
protected abstract String method(REQUEST request);
|
protected abstract String method(REQUEST request);
|
||||||
|
|
||||||
protected abstract String url(REQUEST request);
|
protected abstract URI url(REQUEST request);
|
||||||
|
|
||||||
protected abstract String peerHostname(REQUEST request);
|
protected abstract String peerHostname(CONNECTION connection);
|
||||||
|
|
||||||
protected abstract String peerHostIP(REQUEST request);
|
protected abstract String peerHostIP(CONNECTION connection);
|
||||||
|
|
||||||
protected abstract Integer peerPort(REQUEST request);
|
protected abstract Integer peerPort(CONNECTION connection);
|
||||||
|
|
||||||
protected abstract Integer status(RESPONSE response);
|
protected abstract Integer status(RESPONSE response);
|
||||||
|
|
||||||
|
@ -33,9 +36,37 @@ public abstract class HttpServerDecorator<REQUEST, RESPONSE> extends ServerDecor
|
||||||
assert span != null;
|
assert span != null;
|
||||||
if (request != null) {
|
if (request != null) {
|
||||||
Tags.HTTP_METHOD.set(span, method(request));
|
Tags.HTTP_METHOD.set(span, method(request));
|
||||||
Tags.HTTP_URL.set(span, url(request));
|
|
||||||
Tags.PEER_HOSTNAME.set(span, peerHostname(request));
|
try {
|
||||||
final String ip = peerHostIP(request);
|
final URI url = url(request);
|
||||||
|
final StringBuilder urlNoParams = new StringBuilder(url.getScheme());
|
||||||
|
urlNoParams.append("://");
|
||||||
|
urlNoParams.append(url.getHost());
|
||||||
|
if (url.getPort() > 0 && url.getPort() != 80 && url.getPort() != 443) {
|
||||||
|
urlNoParams.append(":");
|
||||||
|
urlNoParams.append(url.getPort());
|
||||||
|
}
|
||||||
|
final String path = url.getPath();
|
||||||
|
if (path.isEmpty()) {
|
||||||
|
urlNoParams.append("/");
|
||||||
|
} else {
|
||||||
|
urlNoParams.append(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
Tags.HTTP_URL.set(span, urlNoParams.toString());
|
||||||
|
} catch (final Exception e) {
|
||||||
|
log.debug("Error tagging url", e);
|
||||||
|
}
|
||||||
|
// TODO set resource name from URL.
|
||||||
|
}
|
||||||
|
return span;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Span onConnection(final Span span, final CONNECTION connection) {
|
||||||
|
assert span != null;
|
||||||
|
if (connection != null) {
|
||||||
|
Tags.PEER_HOSTNAME.set(span, peerHostname(connection));
|
||||||
|
final String ip = peerHostIP(connection);
|
||||||
if (ip != null) {
|
if (ip != null) {
|
||||||
if (ip.contains(":")) {
|
if (ip.contains(":")) {
|
||||||
Tags.PEER_HOST_IPV6.set(span, ip);
|
Tags.PEER_HOST_IPV6.set(span, ip);
|
||||||
|
@ -43,8 +74,7 @@ public abstract class HttpServerDecorator<REQUEST, RESPONSE> extends ServerDecor
|
||||||
Tags.PEER_HOST_IPV4.set(span, ip);
|
Tags.PEER_HOST_IPV4.set(span, ip);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Tags.PEER_PORT.set(span, peerPort(request));
|
Tags.PEER_PORT.set(span, peerPort(connection));
|
||||||
// TODO set resource name from URL.
|
|
||||||
}
|
}
|
||||||
return span;
|
return span;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
package datadog.trace.agent.decorator
|
package datadog.trace.agent.decorator
|
||||||
|
|
||||||
|
import static datadog.trace.agent.test.utils.TraceUtils.withConfigOverride
|
||||||
|
|
||||||
import datadog.trace.api.Config
|
import datadog.trace.api.Config
|
||||||
import io.opentracing.Span
|
import io.opentracing.Span
|
||||||
import io.opentracing.tag.Tags
|
import io.opentracing.tag.Tags
|
||||||
|
|
||||||
import static datadog.trace.agent.test.utils.TraceUtils.withConfigOverride
|
|
||||||
|
|
||||||
class HttpServerDecoratorTest extends ServerDecoratorTest {
|
class HttpServerDecoratorTest extends ServerDecoratorTest {
|
||||||
|
|
||||||
def span = Mock(Span)
|
def span = Mock(Span)
|
||||||
|
@ -20,7 +20,29 @@ class HttpServerDecoratorTest extends ServerDecoratorTest {
|
||||||
then:
|
then:
|
||||||
if (req) {
|
if (req) {
|
||||||
1 * span.setTag(Tags.HTTP_METHOD.key, "test-method")
|
1 * span.setTag(Tags.HTTP_METHOD.key, "test-method")
|
||||||
1 * span.setTag(Tags.HTTP_URL.key, "test-url")
|
1 * span.setTag(Tags.HTTP_URL.key, url)
|
||||||
|
}
|
||||||
|
0 * _
|
||||||
|
|
||||||
|
where:
|
||||||
|
req | url
|
||||||
|
null | _
|
||||||
|
[method: "test-method", url: URI.create("http://test-url?some=query")] | "http://test-url/"
|
||||||
|
[method: "test-method", url: URI.create("http://a:80/")] | "http://a/"
|
||||||
|
[method: "test-method", url: URI.create("https://10.0.0.1:443")] | "https://10.0.0.1/"
|
||||||
|
[method: "test-method", url: URI.create("https://localhost:0/1/")] | "https://localhost/1/"
|
||||||
|
[method: "test-method", url: URI.create("http://123:8080/some/path")] | "http://123:8080/some/path"
|
||||||
|
}
|
||||||
|
|
||||||
|
def "test onConnection"() {
|
||||||
|
setup:
|
||||||
|
def decorator = newDecorator()
|
||||||
|
|
||||||
|
when:
|
||||||
|
decorator.onConnection(span, conn)
|
||||||
|
|
||||||
|
then:
|
||||||
|
if (conn) {
|
||||||
1 * span.setTag(Tags.PEER_HOSTNAME.key, "test-host")
|
1 * span.setTag(Tags.PEER_HOSTNAME.key, "test-host")
|
||||||
1 * span.setTag(Tags.PEER_PORT.key, 555)
|
1 * span.setTag(Tags.PEER_PORT.key, 555)
|
||||||
if (ipv4) {
|
if (ipv4) {
|
||||||
|
@ -32,11 +54,11 @@ class HttpServerDecoratorTest extends ServerDecoratorTest {
|
||||||
0 * _
|
0 * _
|
||||||
|
|
||||||
where:
|
where:
|
||||||
ipv4 | req
|
ipv4 | conn
|
||||||
null | null
|
null | null
|
||||||
null | [method: "test-method", url: "test-url", host: "test-host", ip: null, port: 555]
|
null | [host: "test-host", ip: null, port: 555]
|
||||||
true | [method: "test-method", url: "test-url", host: "test-host", ip: "10.0.0.1", port: 555]
|
true | [host: "test-host", ip: "10.0.0.1", port: 555]
|
||||||
false | [method: "test-method", url: "test-url", host: "test-host", ip: "3ffe:1900:4545:3:200:f8ff:fe21:67cf", port: 555]
|
false | [host: "test-host", ip: "3ffe:1900:4545:3:200:f8ff:fe21:67cf", port: 555]
|
||||||
}
|
}
|
||||||
|
|
||||||
def "test onResponse"() {
|
def "test onResponse"() {
|
||||||
|
@ -90,7 +112,7 @@ class HttpServerDecoratorTest extends ServerDecoratorTest {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
def newDecorator() {
|
def newDecorator() {
|
||||||
return new HttpServerDecorator<Map, Map>() {
|
return new HttpServerDecorator<Map, Map, Map>() {
|
||||||
@Override
|
@Override
|
||||||
protected String[] instrumentationNames() {
|
protected String[] instrumentationNames() {
|
||||||
return ["test1", "test2"]
|
return ["test1", "test2"]
|
||||||
|
@ -107,7 +129,7 @@ class HttpServerDecoratorTest extends ServerDecoratorTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String url(Map m) {
|
protected URI url(Map m) {
|
||||||
return m.url
|
return m.url
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,8 +3,10 @@ package datadog.trace.instrumentation.akkahttp;
|
||||||
import akka.http.scaladsl.model.HttpRequest;
|
import akka.http.scaladsl.model.HttpRequest;
|
||||||
import akka.http.scaladsl.model.HttpResponse;
|
import akka.http.scaladsl.model.HttpResponse;
|
||||||
import datadog.trace.agent.decorator.HttpServerDecorator;
|
import datadog.trace.agent.decorator.HttpServerDecorator;
|
||||||
|
import java.net.URI;
|
||||||
|
|
||||||
public class AkkaHttpServerDecorator extends HttpServerDecorator<HttpRequest, HttpResponse> {
|
public class AkkaHttpServerDecorator
|
||||||
|
extends HttpServerDecorator<HttpRequest, HttpRequest, HttpResponse> {
|
||||||
public static final AkkaHttpServerDecorator DECORATE = new AkkaHttpServerDecorator();
|
public static final AkkaHttpServerDecorator DECORATE = new AkkaHttpServerDecorator();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -23,8 +25,8 @@ public class AkkaHttpServerDecorator extends HttpServerDecorator<HttpRequest, Ht
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String url(final HttpRequest httpRequest) {
|
protected URI url(final HttpRequest httpRequest) {
|
||||||
return httpRequest.uri().toString();
|
return URI.create(httpRequest.uri().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -108,6 +108,7 @@ public final class AkkaHttpServerInstrumentation extends Instrumenter.Default {
|
||||||
.startActive(false);
|
.startActive(false);
|
||||||
|
|
||||||
DECORATE.afterStart(scope.span());
|
DECORATE.afterStart(scope.span());
|
||||||
|
DECORATE.onConnection(scope.span(), request);
|
||||||
DECORATE.onRequest(scope.span(), request);
|
DECORATE.onRequest(scope.span(), request);
|
||||||
|
|
||||||
if (scope instanceof TraceScope) {
|
if (scope instanceof TraceScope) {
|
||||||
|
|
|
@ -2,10 +2,12 @@ package datadog.trace.instrumentation.jetty8;
|
||||||
|
|
||||||
import datadog.trace.agent.decorator.HttpServerDecorator;
|
import datadog.trace.agent.decorator.HttpServerDecorator;
|
||||||
import io.opentracing.Span;
|
import io.opentracing.Span;
|
||||||
|
import java.net.URI;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
public class JettyDecorator extends HttpServerDecorator<HttpServletRequest, HttpServletResponse> {
|
public class JettyDecorator
|
||||||
|
extends HttpServerDecorator<HttpServletRequest, HttpServletRequest, HttpServletResponse> {
|
||||||
public static final JettyDecorator DECORATE = new JettyDecorator();
|
public static final JettyDecorator DECORATE = new JettyDecorator();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -24,8 +26,8 @@ public class JettyDecorator extends HttpServerDecorator<HttpServletRequest, Http
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String url(final HttpServletRequest httpServletRequest) {
|
protected URI url(final HttpServletRequest httpServletRequest) {
|
||||||
return httpServletRequest.getRequestURL().toString();
|
return URI.create(httpServletRequest.getRequestURL().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -36,10 +36,12 @@ public class JettyHandlerAdvice {
|
||||||
.withTag("span.origin.type", source.getClass().getName())
|
.withTag("span.origin.type", source.getClass().getName())
|
||||||
.startActive(false);
|
.startActive(false);
|
||||||
|
|
||||||
DECORATE.afterStart(scope.span());
|
final Span span = scope.span();
|
||||||
DECORATE.onRequest(scope.span(), req);
|
DECORATE.afterStart(span);
|
||||||
|
DECORATE.onConnection(span, req);
|
||||||
|
DECORATE.onRequest(span, req);
|
||||||
final String resourceName = req.getMethod() + " " + source.getClass().getName();
|
final String resourceName = req.getMethod() + " " + source.getClass().getName();
|
||||||
scope.span().setTag(DDTags.RESOURCE_NAME, resourceName);
|
span.setTag(DDTags.RESOURCE_NAME, resourceName);
|
||||||
|
|
||||||
if (scope instanceof TraceScope) {
|
if (scope instanceof TraceScope) {
|
||||||
((TraceScope) scope).setAsyncPropagation(true);
|
((TraceScope) scope).setAsyncPropagation(true);
|
||||||
|
|
|
@ -12,7 +12,6 @@ import io.opentracing.Span;
|
||||||
import io.opentracing.SpanContext;
|
import io.opentracing.SpanContext;
|
||||||
import io.opentracing.propagation.Format;
|
import io.opentracing.propagation.Format;
|
||||||
import io.opentracing.util.GlobalTracer;
|
import io.opentracing.util.GlobalTracer;
|
||||||
import java.net.InetSocketAddress;
|
|
||||||
|
|
||||||
public class HttpServerRequestTracingHandler extends ChannelInboundHandlerAdapter {
|
public class HttpServerRequestTracingHandler extends ChannelInboundHandlerAdapter {
|
||||||
|
|
||||||
|
@ -23,7 +22,6 @@ public class HttpServerRequestTracingHandler extends ChannelInboundHandlerAdapte
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final HttpRequest request = (HttpRequest) msg;
|
final HttpRequest request = (HttpRequest) msg;
|
||||||
final InetSocketAddress remoteAddress = (InetSocketAddress) ctx.channel().remoteAddress();
|
|
||||||
|
|
||||||
final SpanContext extractedContext =
|
final SpanContext extractedContext =
|
||||||
GlobalTracer.get()
|
GlobalTracer.get()
|
||||||
|
@ -33,8 +31,8 @@ public class HttpServerRequestTracingHandler extends ChannelInboundHandlerAdapte
|
||||||
GlobalTracer.get().buildSpan("netty.request").asChildOf(extractedContext).start();
|
GlobalTracer.get().buildSpan("netty.request").asChildOf(extractedContext).start();
|
||||||
try (final Scope scope = GlobalTracer.get().scopeManager().activate(span, false)) {
|
try (final Scope scope = GlobalTracer.get().scopeManager().activate(span, false)) {
|
||||||
DECORATE.afterStart(span);
|
DECORATE.afterStart(span);
|
||||||
|
DECORATE.onConnection(span, ctx.channel());
|
||||||
DECORATE.onRequest(span, request);
|
DECORATE.onRequest(span, request);
|
||||||
DECORATE.onPeerConnection(span, remoteAddress);
|
|
||||||
|
|
||||||
if (scope instanceof TraceScope) {
|
if (scope instanceof TraceScope) {
|
||||||
((TraceScope) scope).setAsyncPropagation(true);
|
((TraceScope) scope).setAsyncPropagation(true);
|
||||||
|
|
|
@ -3,14 +3,18 @@ package datadog.trace.instrumentation.netty40.server;
|
||||||
import static io.netty.handler.codec.http.HttpHeaders.Names.HOST;
|
import static io.netty.handler.codec.http.HttpHeaders.Names.HOST;
|
||||||
|
|
||||||
import datadog.trace.agent.decorator.HttpServerDecorator;
|
import datadog.trace.agent.decorator.HttpServerDecorator;
|
||||||
|
import io.netty.channel.Channel;
|
||||||
import io.netty.handler.codec.http.HttpRequest;
|
import io.netty.handler.codec.http.HttpRequest;
|
||||||
import io.netty.handler.codec.http.HttpResponse;
|
import io.netty.handler.codec.http.HttpResponse;
|
||||||
|
import java.net.InetSocketAddress;
|
||||||
|
import java.net.SocketAddress;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class NettyHttpServerDecorator extends HttpServerDecorator<HttpRequest, HttpResponse> {
|
public class NettyHttpServerDecorator
|
||||||
|
extends HttpServerDecorator<HttpRequest, Channel, HttpResponse> {
|
||||||
public static final NettyHttpServerDecorator DECORATE = new NettyHttpServerDecorator();
|
public static final NettyHttpServerDecorator DECORATE = new NettyHttpServerDecorator();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -29,33 +33,45 @@ public class NettyHttpServerDecorator extends HttpServerDecorator<HttpRequest, H
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String url(final HttpRequest request) {
|
protected URI url(final HttpRequest request) {
|
||||||
// FIXME: This code is duplicated across netty integrations.
|
// FIXME: This code is duplicated across netty integrations.
|
||||||
try {
|
try {
|
||||||
URI uri = new URI(request.getUri());
|
URI uri = new URI(request.getUri());
|
||||||
if ((uri.getHost() == null || uri.getHost().equals("")) && request.headers().contains(HOST)) {
|
if ((uri.getHost() == null || uri.getHost().equals("")) && request.headers().contains(HOST)) {
|
||||||
uri = new URI("http://" + request.headers().get(HOST) + request.getUri());
|
uri = new URI("http://" + request.headers().get(HOST) + request.getUri());
|
||||||
}
|
}
|
||||||
return new URI(uri.getScheme(), null, uri.getHost(), uri.getPort(), uri.getPath(), null, null)
|
return new URI(
|
||||||
.toString();
|
uri.getScheme(), null, uri.getHost(), uri.getPort(), uri.getPath(), null, null);
|
||||||
} catch (final URISyntaxException e) {
|
} catch (final URISyntaxException e) {
|
||||||
log.debug("Cannot parse netty uri: {}", request.getUri());
|
log.debug("Cannot parse netty uri: {}", request.getUri());
|
||||||
return request.getUri();
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String peerHostname(final HttpRequest httpRequest) {
|
protected String peerHostname(final Channel channel) {
|
||||||
|
final SocketAddress socketAddress = channel.remoteAddress();
|
||||||
|
if (socketAddress instanceof InetSocketAddress) {
|
||||||
|
return ((InetSocketAddress) socketAddress).getHostName();
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String peerHostIP(final HttpRequest httpRequest) {
|
protected String peerHostIP(final Channel channel) {
|
||||||
|
final SocketAddress socketAddress = channel.remoteAddress();
|
||||||
|
if (socketAddress instanceof InetSocketAddress) {
|
||||||
|
return ((InetSocketAddress) socketAddress).getAddress().getHostAddress();
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Integer peerPort(final HttpRequest httpRequest) {
|
protected Integer peerPort(final Channel channel) {
|
||||||
|
final SocketAddress socketAddress = channel.remoteAddress();
|
||||||
|
if (socketAddress instanceof InetSocketAddress) {
|
||||||
|
return ((InetSocketAddress) socketAddress).getPort();
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,6 @@ import io.opentracing.Span;
|
||||||
import io.opentracing.SpanContext;
|
import io.opentracing.SpanContext;
|
||||||
import io.opentracing.propagation.Format;
|
import io.opentracing.propagation.Format;
|
||||||
import io.opentracing.util.GlobalTracer;
|
import io.opentracing.util.GlobalTracer;
|
||||||
import java.net.InetSocketAddress;
|
|
||||||
|
|
||||||
public class HttpServerRequestTracingHandler extends ChannelInboundHandlerAdapter {
|
public class HttpServerRequestTracingHandler extends ChannelInboundHandlerAdapter {
|
||||||
|
|
||||||
|
@ -23,7 +22,6 @@ public class HttpServerRequestTracingHandler extends ChannelInboundHandlerAdapte
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final HttpRequest request = (HttpRequest) msg;
|
final HttpRequest request = (HttpRequest) msg;
|
||||||
final InetSocketAddress remoteAddress = (InetSocketAddress) ctx.channel().remoteAddress();
|
|
||||||
|
|
||||||
final SpanContext extractedContext =
|
final SpanContext extractedContext =
|
||||||
GlobalTracer.get()
|
GlobalTracer.get()
|
||||||
|
@ -33,8 +31,8 @@ public class HttpServerRequestTracingHandler extends ChannelInboundHandlerAdapte
|
||||||
GlobalTracer.get().buildSpan("netty.request").asChildOf(extractedContext).start();
|
GlobalTracer.get().buildSpan("netty.request").asChildOf(extractedContext).start();
|
||||||
try (final Scope scope = GlobalTracer.get().scopeManager().activate(span, false)) {
|
try (final Scope scope = GlobalTracer.get().scopeManager().activate(span, false)) {
|
||||||
DECORATE.afterStart(span);
|
DECORATE.afterStart(span);
|
||||||
|
DECORATE.onConnection(span, ctx.channel());
|
||||||
DECORATE.onRequest(span, request);
|
DECORATE.onRequest(span, request);
|
||||||
DECORATE.onPeerConnection(span, remoteAddress);
|
|
||||||
|
|
||||||
if (scope instanceof TraceScope) {
|
if (scope instanceof TraceScope) {
|
||||||
((TraceScope) scope).setAsyncPropagation(true);
|
((TraceScope) scope).setAsyncPropagation(true);
|
||||||
|
|
|
@ -3,14 +3,18 @@ package datadog.trace.instrumentation.netty41.server;
|
||||||
import static io.netty.handler.codec.http.HttpHeaderNames.HOST;
|
import static io.netty.handler.codec.http.HttpHeaderNames.HOST;
|
||||||
|
|
||||||
import datadog.trace.agent.decorator.HttpServerDecorator;
|
import datadog.trace.agent.decorator.HttpServerDecorator;
|
||||||
|
import io.netty.channel.Channel;
|
||||||
import io.netty.handler.codec.http.HttpRequest;
|
import io.netty.handler.codec.http.HttpRequest;
|
||||||
import io.netty.handler.codec.http.HttpResponse;
|
import io.netty.handler.codec.http.HttpResponse;
|
||||||
|
import java.net.InetSocketAddress;
|
||||||
|
import java.net.SocketAddress;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class NettyHttpServerDecorator extends HttpServerDecorator<HttpRequest, HttpResponse> {
|
public class NettyHttpServerDecorator
|
||||||
|
extends HttpServerDecorator<HttpRequest, Channel, HttpResponse> {
|
||||||
public static final NettyHttpServerDecorator DECORATE = new NettyHttpServerDecorator();
|
public static final NettyHttpServerDecorator DECORATE = new NettyHttpServerDecorator();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -29,33 +33,45 @@ public class NettyHttpServerDecorator extends HttpServerDecorator<HttpRequest, H
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String url(final HttpRequest request) {
|
protected URI url(final HttpRequest request) {
|
||||||
// FIXME: This code is duplicated across netty integrations.
|
// FIXME: This code is duplicated across netty integrations.
|
||||||
try {
|
try {
|
||||||
URI uri = new URI(request.uri());
|
URI uri = new URI(request.uri());
|
||||||
if ((uri.getHost() == null || uri.getHost().equals("")) && request.headers().contains(HOST)) {
|
if ((uri.getHost() == null || uri.getHost().equals("")) && request.headers().contains(HOST)) {
|
||||||
uri = new URI("http://" + request.headers().get(HOST) + request.uri());
|
uri = new URI("http://" + request.headers().get(HOST) + request.getUri());
|
||||||
}
|
}
|
||||||
return new URI(uri.getScheme(), null, uri.getHost(), uri.getPort(), uri.getPath(), null, null)
|
return new URI(
|
||||||
.toString();
|
uri.getScheme(), null, uri.getHost(), uri.getPort(), uri.getPath(), null, null);
|
||||||
} catch (final URISyntaxException e) {
|
} catch (final URISyntaxException e) {
|
||||||
log.debug("Cannot parse netty uri: {}", request.uri());
|
log.debug("Cannot parse netty uri: {}", request.uri());
|
||||||
return request.uri();
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String peerHostname(final HttpRequest httpRequest) {
|
protected String peerHostname(final Channel channel) {
|
||||||
|
final SocketAddress socketAddress = channel.remoteAddress();
|
||||||
|
if (socketAddress instanceof InetSocketAddress) {
|
||||||
|
return ((InetSocketAddress) socketAddress).getHostName();
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String peerHostIP(final HttpRequest httpRequest) {
|
protected String peerHostIP(final Channel channel) {
|
||||||
|
final SocketAddress socketAddress = channel.remoteAddress();
|
||||||
|
if (socketAddress instanceof InetSocketAddress) {
|
||||||
|
return ((InetSocketAddress) socketAddress).getAddress().getHostAddress();
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Integer peerPort(final HttpRequest httpRequest) {
|
protected Integer peerPort(final Channel channel) {
|
||||||
|
final SocketAddress socketAddress = channel.remoteAddress();
|
||||||
|
if (socketAddress instanceof InetSocketAddress) {
|
||||||
|
return ((InetSocketAddress) socketAddress).getPort();
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -76,6 +76,7 @@ class Play26Test extends AgentTestRunner {
|
||||||
"http.status_code" status
|
"http.status_code" status
|
||||||
"http.url" "http://localhost:$port/$path"
|
"http.url" "http://localhost:$port/$path"
|
||||||
"http.method" "GET"
|
"http.method" "GET"
|
||||||
|
"peer.ipv4" "127.0.0.1"
|
||||||
"span.kind" "server"
|
"span.kind" "server"
|
||||||
"component" "play-action"
|
"component" "play-action"
|
||||||
if (isError) {
|
if (isError) {
|
||||||
|
|
|
@ -12,7 +12,7 @@ import play.api.mvc.Result;
|
||||||
import scala.Option;
|
import scala.Option;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class PlayHttpServerDecorator extends HttpServerDecorator<Request, Result> {
|
public class PlayHttpServerDecorator extends HttpServerDecorator<Request, Request, Result> {
|
||||||
public static final PlayHttpServerDecorator DECORATE = new PlayHttpServerDecorator();
|
public static final PlayHttpServerDecorator DECORATE = new PlayHttpServerDecorator();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -31,18 +31,18 @@ public class PlayHttpServerDecorator extends HttpServerDecorator<Request, Result
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String url(final Request request) {
|
protected URI url(final Request request) {
|
||||||
// FIXME: This code is similar to that from the netty integrations.
|
// FIXME: This code is similar to that from the netty integrations.
|
||||||
try {
|
try {
|
||||||
URI uri = new URI(request.uri());
|
URI uri = new URI(request.uri());
|
||||||
if ((uri.getHost() == null || uri.getHost().equals("")) && !request.host().isEmpty()) {
|
if ((uri.getHost() == null || uri.getHost().equals("")) && !request.host().isEmpty()) {
|
||||||
uri = new URI("http://" + request.host() + request.uri());
|
uri = new URI("http://" + request.host() + request.uri());
|
||||||
}
|
}
|
||||||
return new URI(uri.getScheme(), null, uri.getHost(), uri.getPort(), uri.getPath(), null, null)
|
return new URI(
|
||||||
.toString();
|
uri.getScheme(), null, uri.getHost(), uri.getPort(), uri.getPath(), null, null);
|
||||||
} catch (final URISyntaxException e) {
|
} catch (final URISyntaxException e) {
|
||||||
log.debug("Cannot parse uri: {}", request.uri());
|
log.debug("Cannot parse uri: {}", request.uri());
|
||||||
return request.uri();
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@ public class PlayHttpServerDecorator extends HttpServerDecorator<Request, Result
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String peerHostIP(final Request request) {
|
protected String peerHostIP(final Request request) {
|
||||||
return null;
|
return request.remoteAddress();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -91,6 +91,7 @@ public final class PlayInstrumentation extends Instrumenter.Default {
|
||||||
scope = GlobalTracer.get().buildSpan("play.request").startActive(false);
|
scope = GlobalTracer.get().buildSpan("play.request").startActive(false);
|
||||||
}
|
}
|
||||||
DECORATE.afterStart(scope);
|
DECORATE.afterStart(scope);
|
||||||
|
DECORATE.onConnection(scope.span(), req);
|
||||||
|
|
||||||
if (GlobalTracer.get().scopeManager().active() instanceof TraceScope) {
|
if (GlobalTracer.get().scopeManager().active() instanceof TraceScope) {
|
||||||
((TraceScope) GlobalTracer.get().scopeManager().active()).setAsyncPropagation(true);
|
((TraceScope) GlobalTracer.get().scopeManager().active()).setAsyncPropagation(true);
|
||||||
|
|
|
@ -57,6 +57,7 @@ class Play24Test extends AgentTestRunner {
|
||||||
"http.status_code" status
|
"http.status_code" status
|
||||||
"http.url" "http://localhost:$port/$path"
|
"http.url" "http://localhost:$port/$path"
|
||||||
"http.method" "GET"
|
"http.method" "GET"
|
||||||
|
"peer.ipv4" "127.0.0.1"
|
||||||
"span.kind" "server"
|
"span.kind" "server"
|
||||||
"component" "play-action"
|
"component" "play-action"
|
||||||
if (isError) {
|
if (isError) {
|
||||||
|
|
|
@ -39,8 +39,10 @@ public class Servlet2Advice {
|
||||||
.withTag("span.origin.type", servlet.getClass().getName())
|
.withTag("span.origin.type", servlet.getClass().getName())
|
||||||
.startActive(true);
|
.startActive(true);
|
||||||
|
|
||||||
DECORATE.afterStart(scope.span());
|
final Span span = scope.span();
|
||||||
DECORATE.onRequest(scope.span(), httpServletRequest);
|
DECORATE.afterStart(span);
|
||||||
|
DECORATE.onConnection(span, httpServletRequest);
|
||||||
|
DECORATE.onRequest(span, httpServletRequest);
|
||||||
|
|
||||||
if (scope instanceof TraceScope) {
|
if (scope instanceof TraceScope) {
|
||||||
((TraceScope) scope).setAsyncPropagation(true);
|
((TraceScope) scope).setAsyncPropagation(true);
|
||||||
|
|
|
@ -2,10 +2,12 @@ package datadog.trace.instrumentation.servlet2;
|
||||||
|
|
||||||
import datadog.trace.agent.decorator.HttpServerDecorator;
|
import datadog.trace.agent.decorator.HttpServerDecorator;
|
||||||
import io.opentracing.Span;
|
import io.opentracing.Span;
|
||||||
|
import java.net.URI;
|
||||||
import javax.servlet.ServletResponse;
|
import javax.servlet.ServletResponse;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
public class Servlet2Decorator extends HttpServerDecorator<HttpServletRequest, ServletResponse> {
|
public class Servlet2Decorator
|
||||||
|
extends HttpServerDecorator<HttpServletRequest, HttpServletRequest, ServletResponse> {
|
||||||
public static final Servlet2Decorator DECORATE = new Servlet2Decorator();
|
public static final Servlet2Decorator DECORATE = new Servlet2Decorator();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -24,8 +26,8 @@ public class Servlet2Decorator extends HttpServerDecorator<HttpServletRequest, S
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String url(final HttpServletRequest httpServletRequest) {
|
protected URI url(final HttpServletRequest httpServletRequest) {
|
||||||
return httpServletRequest.getRequestURL().toString();
|
return URI.create(httpServletRequest.getRequestURL().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -40,7 +42,7 @@ public class Servlet2Decorator extends HttpServerDecorator<HttpServletRequest, S
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Integer peerPort(final HttpServletRequest httpServletRequest) {
|
protected Integer peerPort(final HttpServletRequest httpServletRequest) {
|
||||||
return httpServletRequest.getServerPort();
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -93,7 +93,6 @@ class JettyServlet2Test extends AgentTestRunner {
|
||||||
"component" "java-web-servlet"
|
"component" "java-web-servlet"
|
||||||
"peer.hostname" "127.0.0.1"
|
"peer.hostname" "127.0.0.1"
|
||||||
"peer.ipv4" "127.0.0.1"
|
"peer.ipv4" "127.0.0.1"
|
||||||
"peer.port" Integer
|
|
||||||
"span.origin.type" "TestServlet2\$Sync"
|
"span.origin.type" "TestServlet2\$Sync"
|
||||||
"servlet.context" "/ctx"
|
"servlet.context" "/ctx"
|
||||||
if (auth) {
|
if (auth) {
|
||||||
|
@ -140,7 +139,6 @@ class JettyServlet2Test extends AgentTestRunner {
|
||||||
"component" "java-web-servlet"
|
"component" "java-web-servlet"
|
||||||
"peer.hostname" "127.0.0.1"
|
"peer.hostname" "127.0.0.1"
|
||||||
"peer.ipv4" "127.0.0.1"
|
"peer.ipv4" "127.0.0.1"
|
||||||
"peer.port" Integer
|
|
||||||
"span.origin.type" "TestServlet2\$Sync"
|
"span.origin.type" "TestServlet2\$Sync"
|
||||||
"servlet.context" "/ctx"
|
"servlet.context" "/ctx"
|
||||||
errorTags(RuntimeException, "some $path error")
|
errorTags(RuntimeException, "some $path error")
|
||||||
|
@ -183,7 +181,6 @@ class JettyServlet2Test extends AgentTestRunner {
|
||||||
"component" "java-web-servlet"
|
"component" "java-web-servlet"
|
||||||
"peer.hostname" "127.0.0.1"
|
"peer.hostname" "127.0.0.1"
|
||||||
"peer.ipv4" "127.0.0.1"
|
"peer.ipv4" "127.0.0.1"
|
||||||
"peer.port" Integer
|
|
||||||
"span.origin.type" "TestServlet2\$Sync"
|
"span.origin.type" "TestServlet2\$Sync"
|
||||||
"servlet.context" "/ctx"
|
"servlet.context" "/ctx"
|
||||||
defaultTags()
|
defaultTags()
|
||||||
|
|
|
@ -44,14 +44,16 @@ public class Servlet3Advice {
|
||||||
.withTag("span.origin.type", servlet.getClass().getName())
|
.withTag("span.origin.type", servlet.getClass().getName())
|
||||||
.startActive(false);
|
.startActive(false);
|
||||||
|
|
||||||
DECORATE.afterStart(scope.span());
|
final Span span = scope.span();
|
||||||
DECORATE.onRequest(scope.span(), httpServletRequest);
|
DECORATE.afterStart(span);
|
||||||
|
DECORATE.onConnection(span, httpServletRequest);
|
||||||
|
DECORATE.onRequest(span, httpServletRequest);
|
||||||
|
|
||||||
if (scope instanceof TraceScope) {
|
if (scope instanceof TraceScope) {
|
||||||
((TraceScope) scope).setAsyncPropagation(true);
|
((TraceScope) scope).setAsyncPropagation(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
req.setAttribute(SERVLET_SPAN, scope.span());
|
req.setAttribute(SERVLET_SPAN, span);
|
||||||
return scope;
|
return scope;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,11 +2,12 @@ package datadog.trace.instrumentation.servlet3;
|
||||||
|
|
||||||
import datadog.trace.agent.decorator.HttpServerDecorator;
|
import datadog.trace.agent.decorator.HttpServerDecorator;
|
||||||
import io.opentracing.Span;
|
import io.opentracing.Span;
|
||||||
|
import java.net.URI;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
public class Servlet3Decorator
|
public class Servlet3Decorator
|
||||||
extends HttpServerDecorator<HttpServletRequest, HttpServletResponse> {
|
extends HttpServerDecorator<HttpServletRequest, HttpServletRequest, HttpServletResponse> {
|
||||||
public static final Servlet3Decorator DECORATE = new Servlet3Decorator();
|
public static final Servlet3Decorator DECORATE = new Servlet3Decorator();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -25,8 +26,8 @@ public class Servlet3Decorator
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String url(final HttpServletRequest httpServletRequest) {
|
protected URI url(final HttpServletRequest httpServletRequest) {
|
||||||
return httpServletRequest.getRequestURL().toString();
|
return URI.create(httpServletRequest.getRequestURL().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -5,6 +5,7 @@ import datadog.trace.api.DDSpanTypes;
|
||||||
import datadog.trace.api.DDTags;
|
import datadog.trace.api.DDTags;
|
||||||
import io.opentracing.Scope;
|
import io.opentracing.Scope;
|
||||||
import io.opentracing.Span;
|
import io.opentracing.Span;
|
||||||
|
import java.net.URI;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
@ -13,7 +14,7 @@ import org.springframework.web.servlet.ModelAndView;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class SpringWebHttpServerDecorator
|
public class SpringWebHttpServerDecorator
|
||||||
extends HttpServerDecorator<HttpServletRequest, HttpServletResponse> {
|
extends HttpServerDecorator<HttpServletRequest, HttpServletRequest, HttpServletResponse> {
|
||||||
public static final SpringWebHttpServerDecorator DECORATE = new SpringWebHttpServerDecorator();
|
public static final SpringWebHttpServerDecorator DECORATE = new SpringWebHttpServerDecorator();
|
||||||
public static final SpringWebHttpServerDecorator DECORATE_RENDER =
|
public static final SpringWebHttpServerDecorator DECORATE_RENDER =
|
||||||
new SpringWebHttpServerDecorator() {
|
new SpringWebHttpServerDecorator() {
|
||||||
|
@ -39,8 +40,8 @@ public class SpringWebHttpServerDecorator
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String url(final HttpServletRequest httpServletRequest) {
|
protected URI url(final HttpServletRequest httpServletRequest) {
|
||||||
return httpServletRequest.getRequestURL().toString();
|
return URI.create(httpServletRequest.getRequestURL().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in New Issue