Bring back webflux client instrumentation (#406)
This commit is contained in:
parent
2308c69875
commit
f6e16c8f90
|
@ -22,14 +22,14 @@ import static net.bytebuddy.matcher.ElementMatchers.isMethod;
|
|||
import static net.bytebuddy.matcher.ElementMatchers.isPublic;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.named;
|
||||
|
||||
import com.google.auto.service.AutoService;
|
||||
import io.opentelemetry.auto.tooling.Instrumenter;
|
||||
import java.util.Map;
|
||||
import net.bytebuddy.description.method.MethodDescription;
|
||||
import net.bytebuddy.description.type.TypeDescription;
|
||||
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 WebClientFilterInstrumentation() {
|
||||
|
|
|
@ -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.SpringWebfluxHttpClientDecorator.DECORATE;
|
||||
import static io.opentelemetry.auto.instrumentation.springwebflux.client.SpringWebfluxHttpClientDecorator.TRACER;
|
||||
import static io.opentelemetry.trace.Span.Kind.CLIENT;
|
||||
|
||||
import io.grpc.Context;
|
||||
import io.opentelemetry.OpenTelemetry;
|
||||
|
@ -38,13 +39,13 @@ public class WebClientTracingFilter implements ExchangeFilterFunction {
|
|||
|
||||
@Override
|
||||
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);
|
||||
|
||||
try (final Scope scope = TRACER.withSpan(span)) {
|
||||
final ClientRequest mutatedRequest =
|
||||
ClientRequest.from(request)
|
||||
.attribute(Span.class.getName(), span)
|
||||
.headers(
|
||||
httpHeaders ->
|
||||
OpenTelemetry.getPropagators()
|
||||
|
|
|
@ -27,7 +27,6 @@ import java.util.function.Function;
|
|||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.reactivestreams.Publisher;
|
||||
import org.reactivestreams.Subscription;
|
||||
import org.springframework.web.reactive.function.client.ClientRequest;
|
||||
import org.springframework.web.reactive.function.server.ServerRequest;
|
||||
import org.springframework.web.server.ServerWebExchange;
|
||||
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(
|
||||
final Map<String, Object> attributes, final Throwable throwable) {
|
||||
|
||||
|
|
|
@ -22,14 +22,10 @@ import io.opentelemetry.auto.test.base.HttpClientTest
|
|||
import org.springframework.http.HttpMethod
|
||||
import org.springframework.web.reactive.function.client.ClientResponse
|
||||
import org.springframework.web.reactive.function.client.WebClient
|
||||
import spock.lang.Ignore
|
||||
import spock.lang.Timeout
|
||||
|
||||
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)
|
||||
class SpringWebfluxHttpClientTest extends HttpClientTest {
|
||||
|
||||
|
@ -54,7 +50,7 @@ class SpringWebfluxHttpClientTest extends HttpClientTest {
|
|||
if (!exception) {
|
||||
trace.span(index + 1) {
|
||||
childOf(trace.span(index))
|
||||
operationName "netty.client.request"
|
||||
operationName "HTTP $method"
|
||||
spanKind CLIENT
|
||||
errored exception != null
|
||||
tags {
|
||||
|
|
Loading…
Reference in New Issue