Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trace DNS resolution in reactor-netty #4627

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
plugins {
id("otel.javaagent-instrumentation")
}

dependencies {
api(project(":instrumentation:netty:netty-4-common:javaagent"))

compileOnly("io.netty:netty-codec-http:4.1.0.Final")
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.instrumentation.netty.v4_1;
package io.opentelemetry.javaagent.instrumentation.netty.v4_1;

import io.netty.util.AttributeKey;
import io.opentelemetry.context.Context;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.javaagent.instrumentation.netty.v4_1.client;

import static io.opentelemetry.javaagent.instrumentation.netty.v4_1.client.NettyClientSingletons.connectionInstrumenter;
package io.opentelemetry.javaagent.instrumentation.netty.v4_1;

import io.netty.resolver.AddressResolver;
import io.netty.resolver.AddressResolverGroup;
Expand All @@ -27,7 +25,7 @@ public static <T extends SocketAddress> AddressResolverGroup<T> wrap(
if (delegate instanceof InstrumentedAddressResolverGroup) {
return delegate;
}
return new InstrumentedAddressResolverGroup<>(connectionInstrumenter(), delegate);
return new InstrumentedAddressResolverGroup<>(instrumenter, delegate);
mateuszrzeszutek marked this conversation as resolved.
Show resolved Hide resolved
}

private final NettyConnectionInstrumenter instrumenter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ muzzle {

dependencies {
library("io.netty:netty-codec-http:4.1.0.Final")
api(project(":instrumentation:netty:netty-4.1:library"))
implementation(project(":instrumentation:netty:netty-4-common:javaagent"))
implementation(project(":instrumentation:netty:netty-4.1-common:javaagent"))

// Contains logging handler
testLibrary("io.netty:netty-handler:4.1.0.Final")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import io.netty.channel.ChannelHandlerContext;
import io.netty.util.Attribute;
import io.opentelemetry.context.Context;
import io.opentelemetry.instrumentation.netty.v4_1.AttributeKeys;
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
import io.opentelemetry.javaagent.instrumentation.netty.common.HttpRequestAndChannel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import io.opentelemetry.javaagent.instrumentation.api.Java8BytecodeBridge;
import io.opentelemetry.javaagent.instrumentation.netty.common.NettyConnectionRequest;
import io.opentelemetry.javaagent.instrumentation.netty.common.client.ConnectionCompleteListener;
import io.opentelemetry.javaagent.instrumentation.netty.v4_1.client.InstrumentedAddressResolverGroup;
import java.net.SocketAddress;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.description.type.TypeDescription;
Expand Down Expand Up @@ -84,7 +83,6 @@ public static void startConnect(

Context parentContext = Java8BytecodeBridge.currentContext();
request = NettyConnectionRequest.connect(remoteAddress);

if (!connectionInstrumenter().shouldStart(parentContext, request)) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import static net.bytebuddy.matcher.ElementMatchers.namedOneOf;

import io.netty.channel.Channel;
import io.opentelemetry.instrumentation.netty.v4_1.AttributeKeys;
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
import io.opentelemetry.javaagent.instrumentation.api.Java8BytecodeBridge;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
import io.netty.util.Attribute;
import io.opentelemetry.context.Context;
import io.opentelemetry.context.Scope;
import io.opentelemetry.instrumentation.netty.v4_1.AttributeKeys;
import io.opentelemetry.javaagent.instrumentation.netty.common.HttpRequestAndChannel;
import io.opentelemetry.javaagent.instrumentation.netty.v4_1.AttributeKeys;

public class HttpClientRequestTracingHandler extends ChannelOutboundHandlerAdapter {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
import io.netty.util.Attribute;
import io.opentelemetry.context.Context;
import io.opentelemetry.context.Scope;
import io.opentelemetry.instrumentation.netty.v4_1.AttributeKeys;
import io.opentelemetry.javaagent.instrumentation.netty.common.HttpRequestAndChannel;
import io.opentelemetry.javaagent.instrumentation.netty.v4_1.AttributeKeys;

public class HttpClientResponseTracingHandler extends ChannelInboundHandlerAdapter {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
import io.netty.util.Attribute;
import io.opentelemetry.context.Context;
import io.opentelemetry.context.Scope;
import io.opentelemetry.instrumentation.netty.v4_1.AttributeKeys;
import io.opentelemetry.javaagent.instrumentation.netty.common.HttpRequestAndChannel;
import io.opentelemetry.javaagent.instrumentation.netty.v4_1.AttributeKeys;

public class HttpServerRequestTracingHandler extends ChannelInboundHandlerAdapter {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
import io.netty.util.Attribute;
import io.opentelemetry.context.Context;
import io.opentelemetry.context.Scope;
import io.opentelemetry.instrumentation.netty.v4_1.AttributeKeys;
import io.opentelemetry.javaagent.instrumentation.netty.common.HttpRequestAndChannel;
import io.opentelemetry.javaagent.instrumentation.netty.common.NettyErrorHolder;
import io.opentelemetry.javaagent.instrumentation.netty.v4_1.AttributeKeys;
import javax.annotation.Nullable;

public class HttpServerResponseTracingHandler extends ChannelOutboundHandlerAdapter {
Expand Down
7 changes: 0 additions & 7 deletions instrumentation/netty/netty-4.1/library/build.gradle.kts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ muzzle {
}

dependencies {
implementation(project(":instrumentation:netty:netty-4.1:library"))
implementation(project(":instrumentation:netty:netty-4.1-common:javaagent"))
library("io.projectreactor.netty:reactor-netty:0.9.0.RELEASE")

testInstrumentation(project(":instrumentation:reactor-netty:reactor-netty-1.0:javaagent"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import io.netty.channel.Channel;
import io.opentelemetry.context.Context;
import io.opentelemetry.context.Scope;
import io.opentelemetry.instrumentation.netty.v4_1.AttributeKeys;
import io.opentelemetry.javaagent.instrumentation.netty.v4_1.AttributeKeys;
import java.util.function.BiConsumer;
import javax.annotation.Nullable;
import reactor.netty.Connection;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
package io.opentelemetry.javaagent.instrumentation.reactornetty.v0_9;

import io.opentelemetry.context.Context;
import io.opentelemetry.instrumentation.netty.v4_1.AttributeKeys;
import io.opentelemetry.javaagent.instrumentation.netty.v4_1.AttributeKeys;
import java.util.function.BiConsumer;
import reactor.netty.Connection;
import reactor.netty.http.client.HttpClientRequest;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ muzzle {
}

dependencies {
implementation(project(":instrumentation:netty:netty-4.1:library"))
implementation(project(":instrumentation:netty:netty-4-common:javaagent"))
compileOnly("com.google.auto.value:auto-value-annotations")
annotationProcessor("com.google.auto.value:auto-value")

implementation(project(":instrumentation:netty:netty-4.1-common:javaagent"))
library("io.projectreactor.netty:reactor-netty-http:1.0.0")

testInstrumentation(project(":instrumentation:reactor-netty:reactor-netty-0.9:javaagent"))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.javaagent.instrumentation.reactornetty.v1_0;

import com.google.auto.value.AutoValue;
import io.opentelemetry.context.Context;
import io.opentelemetry.javaagent.instrumentation.netty.common.NettyConnectionRequest;

@AutoValue
public abstract class ConnectionRequestAndContext {

public static ConnectionRequestAndContext create(
NettyConnectionRequest request, Context context) {
return new AutoValue_ConnectionRequestAndContext(request, context);
}

public abstract NettyConnectionRequest request();

public abstract Context context();
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,42 @@
import static io.opentelemetry.javaagent.instrumentation.reactornetty.v1_0.ReactorNettySingletons.connectionInstrumenter;

import io.netty.channel.Channel;
import io.opentelemetry.context.Context;
import io.opentelemetry.javaagent.instrumentation.netty.common.NettyConnectionRequest;
import io.netty.channel.ChannelPromise;
import io.opentelemetry.instrumentation.api.field.VirtualField;
import reactor.core.publisher.Mono;

public class ConnectionWrapper {
public final class ConnectionWrapper {

public static Mono<Channel> wrap(
Context context, NettyConnectionRequest request, Mono<Channel> mono) {
return mono.doOnError(error -> connectionInstrumenter().end(context, request, null, error))
.doOnSuccess(channel -> connectionInstrumenter().end(context, request, channel, null));
private static final VirtualField<ChannelPromise, ConnectionRequestAndContext>
requestAndContextField =
VirtualField.find(ChannelPromise.class, ConnectionRequestAndContext.class);

public static Mono<Channel> wrap(Mono<Channel> mono) {
// if we didn't attach the connection context&request then we have nothing to instrument
if (!(mono instanceof ChannelPromise)) {
return mono;
}
return mono.doOnError(
error -> {
ConnectionRequestAndContext requestAndContext =
requestAndContextField.get((ChannelPromise) mono);
if (requestAndContext == null) {
return;
}
connectionInstrumenter()
.end(requestAndContext.context(), requestAndContext.request(), null, error);
})
.doOnSuccess(
mateuszrzeszutek marked this conversation as resolved.
Show resolved Hide resolved
channel -> {
ConnectionRequestAndContext requestAndContext =
requestAndContextField.get((ChannelPromise) mono);
if (requestAndContext == null) {
return;
}
connectionInstrumenter()
.end(requestAndContext.context(), requestAndContext.request(), channel, null);
});
}

private ConnectionWrapper() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import io.netty.channel.Channel;
import io.opentelemetry.context.Context;
import io.opentelemetry.context.Scope;
import io.opentelemetry.instrumentation.netty.v4_1.AttributeKeys;
import io.opentelemetry.javaagent.instrumentation.netty.v4_1.AttributeKeys;
import java.util.function.BiConsumer;
import javax.annotation.Nullable;
import reactor.netty.Connection;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
package io.opentelemetry.javaagent.instrumentation.reactornetty.v1_0;

import io.opentelemetry.context.Context;
import io.opentelemetry.instrumentation.netty.v4_1.AttributeKeys;
import io.opentelemetry.javaagent.instrumentation.netty.v4_1.AttributeKeys;
import java.util.function.BiConsumer;
import reactor.netty.Connection;
import reactor.netty.http.client.HttpClientRequest;
Expand Down
Loading