File tree Expand file tree Collapse file tree
dd-java-agent/instrumentation/micronaut/http-server-netty-4.0/src/main
java17/datadog/trace/instrumentation/micronaut/v4_0
java/datadog/trace/instrumentation/micronaut/v4_0 Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -23,6 +23,8 @@ public MicronautInstrumentation() {
2323 public String [] knownMatchingTypes () {
2424 return new String [] {
2525 "io.micronaut.http.server.netty.RoutingInBoundHandler" ,
26+ // starting with 4.8.0, encodeHttpResponse methods have been moved from 👆 to 👇
27+ "io.micronaut.http.server.ResponseLifecycle" ,
2628 "io.micronaut.http.server.RouteExecutor" ,
2729 "io.micronaut.http.server.netty.NettyRequestLifecycle" ,
2830 };
@@ -70,6 +72,13 @@ public void methodAdvice(MethodTransformer transformer) {
7072 .and (takesArgument (0 , named ("io.micronaut.http.server.netty.NettyHttpRequest" )))
7173 .and (takesArgument (1 , named ("io.micronaut.http.HttpResponse" ))),
7274 packageName + ".EncodeHttpResponseAdvice2" );
75+ // for micronaut 4.8 onwards
76+ transformer .applyAdvice (
77+ isMethod ()
78+ .and (named ("encodeHttpResponse" ))
79+ .and (takesArgument (0 , named ("io.micronaut.http.HttpRequest" )))
80+ .and (takesArgument (1 , named ("io.micronaut.http.HttpResponse" ))),
81+ packageName + ".EncodeHttpResponseAdvice3" );
7382 }
7483
7584 @ Override
Original file line number Diff line number Diff line change 1+ package datadog .trace .instrumentation .micronaut .v4_0 ;
2+
3+ import static datadog .trace .bootstrap .instrumentation .api .AgentTracer .activateSpan ;
4+ import static datadog .trace .instrumentation .micronaut .v4_0 .MicronautDecorator .DECORATE ;
5+ import static datadog .trace .instrumentation .micronaut .v4_0 .MicronautDecorator .SPAN_ATTRIBUTE ;
6+
7+ import datadog .trace .bootstrap .instrumentation .api .AgentScope ;
8+ import datadog .trace .bootstrap .instrumentation .api .AgentSpan ;
9+ import io .micronaut .http .HttpRequest ;
10+ import io .micronaut .http .HttpResponse ;
11+ import net .bytebuddy .asm .Advice ;
12+
13+ public class EncodeHttpResponseAdvice3 {
14+ @ Advice .OnMethodEnter (suppress = Throwable .class )
15+ public static void finishHandlerSpan (
16+ @ Advice .Argument (0 ) final HttpRequest <?> request ,
17+ @ Advice .Argument (1 ) final HttpResponse <?> message ) {
18+ AgentSpan span = request .removeAttribute (SPAN_ATTRIBUTE , AgentSpan .class ).orElse (null );
19+ if (null == span ) {
20+ return ;
21+ }
22+
23+ try (final AgentScope scope = activateSpan (span )) {
24+ DECORATE .onResponse (span , message );
25+ DECORATE .beforeFinish (span );
26+ span .finish ();
27+ }
28+ }
29+ }
You can’t perform that action at this time.
0 commit comments