Bring back webflux client instrumentation (#406)

This commit is contained in:
Trask Stalnaker 2020-05-18 13:06:18 -07:00 committed by GitHub
parent 2308c69875
commit f6e16c8f90
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 6 additions and 17 deletions

View File

@ -22,14 +22,14 @@ import static net.bytebuddy.matcher.ElementMatchers.isMethod;
import static net.bytebuddy.matcher.ElementMatchers.isPublic; import static net.bytebuddy.matcher.ElementMatchers.isPublic;
import static net.bytebuddy.matcher.ElementMatchers.named; import static net.bytebuddy.matcher.ElementMatchers.named;
import com.google.auto.service.AutoService;
import io.opentelemetry.auto.tooling.Instrumenter; import io.opentelemetry.auto.tooling.Instrumenter;
import java.util.Map; import java.util.Map;
import net.bytebuddy.description.method.MethodDescription; import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.description.type.TypeDescription; import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.matcher.ElementMatcher; import net.bytebuddy.matcher.ElementMatcher;
// FIXME this instrumentation is not currently reliable, see DefaultWebClientAdvice @AutoService(Instrumenter.class)
// @AutoService(Instrumenter.class)
public class WebClientFilterInstrumentation extends Instrumenter.Default { public class WebClientFilterInstrumentation extends Instrumenter.Default {
public WebClientFilterInstrumentation() { public WebClientFilterInstrumentation() {

View File

@ -18,6 +18,7 @@ package io.opentelemetry.auto.instrumentation.springwebflux.client;
import static io.opentelemetry.auto.instrumentation.springwebflux.client.HttpHeadersInjectAdapter.SETTER; import static io.opentelemetry.auto.instrumentation.springwebflux.client.HttpHeadersInjectAdapter.SETTER;
import static io.opentelemetry.auto.instrumentation.springwebflux.client.SpringWebfluxHttpClientDecorator.DECORATE; import static io.opentelemetry.auto.instrumentation.springwebflux.client.SpringWebfluxHttpClientDecorator.DECORATE;
import static io.opentelemetry.auto.instrumentation.springwebflux.client.SpringWebfluxHttpClientDecorator.TRACER; import static io.opentelemetry.auto.instrumentation.springwebflux.client.SpringWebfluxHttpClientDecorator.TRACER;
import static io.opentelemetry.trace.Span.Kind.CLIENT;
import io.grpc.Context; import io.grpc.Context;
import io.opentelemetry.OpenTelemetry; import io.opentelemetry.OpenTelemetry;
@ -38,13 +39,13 @@ public class WebClientTracingFilter implements ExchangeFilterFunction {
@Override @Override
public Mono<ClientResponse> filter(final ClientRequest request, final ExchangeFunction next) { public Mono<ClientResponse> filter(final ClientRequest request, final ExchangeFunction next) {
final Span span = TRACER.spanBuilder("http.request").startSpan(); final Span span =
TRACER.spanBuilder(DECORATE.spanNameForRequest(request)).setSpanKind(CLIENT).startSpan();
DECORATE.afterStart(span); DECORATE.afterStart(span);
try (final Scope scope = TRACER.withSpan(span)) { try (final Scope scope = TRACER.withSpan(span)) {
final ClientRequest mutatedRequest = final ClientRequest mutatedRequest =
ClientRequest.from(request) ClientRequest.from(request)
.attribute(Span.class.getName(), span)
.headers( .headers(
httpHeaders -> httpHeaders ->
OpenTelemetry.getPropagators() OpenTelemetry.getPropagators()

View File

@ -27,7 +27,6 @@ import java.util.function.Function;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.reactivestreams.Publisher; import org.reactivestreams.Publisher;
import org.reactivestreams.Subscription; import org.reactivestreams.Subscription;
import org.springframework.web.reactive.function.client.ClientRequest;
import org.springframework.web.reactive.function.server.ServerRequest; import org.springframework.web.reactive.function.server.ServerRequest;
import org.springframework.web.server.ServerWebExchange; import org.springframework.web.server.ServerWebExchange;
import reactor.core.CoreSubscriber; import reactor.core.CoreSubscriber;
@ -85,13 +84,6 @@ public class AdviceUtils {
} }
} }
public static void finishSpanIfPresent(
final ClientRequest clientRequest, final Throwable throwable) {
if (clientRequest != null) {
finishSpanIfPresentInAttributes(clientRequest.attributes(), throwable);
}
}
private static void finishSpanIfPresentInAttributes( private static void finishSpanIfPresentInAttributes(
final Map<String, Object> attributes, final Throwable throwable) { final Map<String, Object> attributes, final Throwable throwable) {

View File

@ -22,14 +22,10 @@ import io.opentelemetry.auto.test.base.HttpClientTest
import org.springframework.http.HttpMethod import org.springframework.http.HttpMethod
import org.springframework.web.reactive.function.client.ClientResponse import org.springframework.web.reactive.function.client.ClientResponse
import org.springframework.web.reactive.function.client.WebClient import org.springframework.web.reactive.function.client.WebClient
import spock.lang.Ignore
import spock.lang.Timeout import spock.lang.Timeout
import static io.opentelemetry.trace.Span.Kind.CLIENT import static io.opentelemetry.trace.Span.Kind.CLIENT
// FIXME this instrumentation is not currently reliable and so is currently disabled
// see DefaultWebClientInstrumentation and DefaultWebClientAdvice
@Ignore
@Timeout(5) @Timeout(5)
class SpringWebfluxHttpClientTest extends HttpClientTest { class SpringWebfluxHttpClientTest extends HttpClientTest {
@ -54,7 +50,7 @@ class SpringWebfluxHttpClientTest extends HttpClientTest {
if (!exception) { if (!exception) {
trace.span(index + 1) { trace.span(index + 1) {
childOf(trace.span(index)) childOf(trace.span(index))
operationName "netty.client.request" operationName "HTTP $method"
spanKind CLIENT spanKind CLIENT
errored exception != null errored exception != null
tags { tags {