1515import io .opentelemetry .javaagent .extension .instrumentation .TypeTransformer ;
1616import io .opentelemetry .javaagent .instrumentation .opentelemetryapi .context .AgentContextStorage ;
1717import io .opentelemetry .javaagent .instrumentation .opentelemetryapi .trace .Bridging ;
18+ import javax .annotation .Nullable ;
1819import net .bytebuddy .asm .Advice ;
1920import net .bytebuddy .asm .Advice .AssignReturned ;
2021import net .bytebuddy .description .type .TypeDescription ;
@@ -42,6 +43,8 @@ public void transform(TypeTransformer transformer) {
4243
4344 @ SuppressWarnings ("unused" )
4445 public static class StoreInContextAdvice {
46+
47+ @ Nullable
4548 @ Advice .OnMethodEnter (skipOn = Advice .OnNonDefaultValue .class )
4649 public static Context onEnter (
4750 @ Advice .This SpanKey applicationSpanKey ,
@@ -74,18 +77,16 @@ public static Context onEnter(
7477 @ AssignReturned .ToReturned
7578 @ Advice .OnMethodExit (suppress = Throwable .class )
7679 public static Context onExit (
77- @ Advice .Return Context originalResult , @ Advice .Enter Context newApplicationContext ) {
78- Context result = originalResult ;
79-
80- if (newApplicationContext != null ) {
81- result = newApplicationContext ;
82- }
83- return result ;
80+ @ Advice .Return Context originalResult ,
81+ @ Advice .Enter @ Nullable Context newApplicationContext ) {
82+ return newApplicationContext != null ? newApplicationContext : originalResult ;
8483 }
8584 }
8685
8786 @ SuppressWarnings ("unused" )
8887 public static class FromContextOrNullAdvice {
88+
89+ @ Nullable
8990 @ Advice .OnMethodEnter (skipOn = Advice .OnNonDefaultValue .class )
9091 public static Span onEnter (
9192 @ Advice .This SpanKey applicationSpanKey , @ Advice .Argument (0 ) Context applicationContext ) {
@@ -112,13 +113,8 @@ public static Span onEnter(
112113 @ AssignReturned .ToReturned
113114 @ Advice .OnMethodExit (suppress = Throwable .class )
114115 public static Span onExit (
115- @ Advice .Return Span originalResult , @ Advice .Enter Span applicationSpan ) {
116- Span result = originalResult ;
117-
118- if (applicationSpan != null ) {
119- result = applicationSpan ;
120- }
121- return result ;
116+ @ Advice .Return Span originalResult , @ Advice .Enter @ Nullable Span applicationSpan ) {
117+ return applicationSpan != null ? applicationSpan : originalResult ;
122118 }
123119 }
124120}
0 commit comments