use spring-webflux-5.1+ ClientResponse.rawStatusCode when available (DataDog/dd-trace-java#1711)
This commit is contained in:
parent
e2aca0f378
commit
0d4fe92296
|
@ -7,6 +7,16 @@ apply from: "$rootDir/gradle/instrumentation.gradle"
|
|||
|
||||
muzzle {
|
||||
pass {
|
||||
name = "webflux_5.0.0+_with_netty_0.8.0"
|
||||
group = "org.springframework"
|
||||
module = "spring-webflux"
|
||||
versions = "[5.0.0.RELEASE,)"
|
||||
assertInverse = true
|
||||
extraDependency "io.projectreactor.netty:reactor-netty:0.8.0.RELEASE"
|
||||
}
|
||||
|
||||
pass {
|
||||
name = "webflux_5.0.0_with_ipc_0.7.0"
|
||||
group = "org.springframework"
|
||||
module = "spring-webflux"
|
||||
versions = "[5.0.0.RELEASE,)"
|
||||
|
@ -15,6 +25,15 @@ muzzle {
|
|||
}
|
||||
|
||||
pass {
|
||||
name = "netty_0.8.0+_with_spring-webflux:5.1.0"
|
||||
group = "io.projectreactor.netty"
|
||||
module = "reactor-netty"
|
||||
versions = "[0.8.0.RELEASE,)"
|
||||
extraDependency "org.springframework:spring-webflux:5.1.0.RELEASE"
|
||||
}
|
||||
|
||||
pass {
|
||||
name = "ipc_0.7.0+_with_spring-webflux:5.0.0"
|
||||
group = "io.projectreactor.ipc"
|
||||
module = "reactor-netty"
|
||||
versions = "[0.7.0.RELEASE,)"
|
||||
|
|
|
@ -22,6 +22,9 @@ import io.opentelemetry.context.propagation.TextMapPropagator.Setter;
|
|||
import io.opentelemetry.instrumentation.api.tracer.HttpClientTracer;
|
||||
import io.opentelemetry.trace.Span;
|
||||
import io.opentelemetry.trace.Tracer;
|
||||
import java.lang.invoke.MethodHandle;
|
||||
import java.lang.invoke.MethodHandles;
|
||||
import java.lang.invoke.MethodType;
|
||||
import java.net.URI;
|
||||
import java.util.List;
|
||||
import org.springframework.web.reactive.function.client.ClientRequest;
|
||||
|
@ -32,6 +35,8 @@ public class SpringWebfluxHttpClientTracer
|
|||
|
||||
public static final SpringWebfluxHttpClientTracer TRACER = new SpringWebfluxHttpClientTracer();
|
||||
|
||||
private static final MethodHandle RAW_STATUS_CODE = findRawStatusCode();
|
||||
|
||||
public void onCancel(Span span) {
|
||||
span.setAttribute("event", "cancelled");
|
||||
span.setAttribute("message", "The subscription was cancelled");
|
||||
|
@ -49,6 +54,15 @@ public class SpringWebfluxHttpClientTracer
|
|||
|
||||
@Override
|
||||
protected Integer status(ClientResponse httpResponse) {
|
||||
if (RAW_STATUS_CODE != null) {
|
||||
// rawStatusCode() method was introduced in webflux 5.1
|
||||
try {
|
||||
return (int) RAW_STATUS_CODE.invokeExact(httpResponse);
|
||||
} catch (Throwable ignored) {
|
||||
}
|
||||
}
|
||||
// prior to webflux 5.1, the best we can get is HttpStatus enum, which only covers standard
|
||||
// status codes
|
||||
return httpResponse.statusCode().value();
|
||||
}
|
||||
|
||||
|
@ -76,4 +90,16 @@ public class SpringWebfluxHttpClientTracer
|
|||
public Tracer getTracer() {
|
||||
return tracer;
|
||||
}
|
||||
|
||||
// rawStatusCode() method was introduced in webflux 5.1
|
||||
// prior to this method, the best we can get is HttpStatus enum, which only covers standard status
|
||||
// codes (see usage above)
|
||||
private static MethodHandle findRawStatusCode() {
|
||||
try {
|
||||
return MethodHandles.publicLookup()
|
||||
.findVirtual(ClientResponse.class, "rawStatusCode", MethodType.methodType(int.class));
|
||||
} catch (IllegalAccessException | NoSuchMethodException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue