Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 352
Context API beforeFinish Migration#9422
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
796b57ee8c2baf737e783c9a2e21a0ecac72ef3dc7a14848f112ec20909d174c883e8db847401bebe637f76415f8f4a6ee762c233c8c9ecef715d627fe9c700f0f228ecc50494bd005d9b4d887a3bb790ee71b23dd4c4c07fd52d82c274316e950a05f20aeefd11e7a0c4ab54c13e8cdb9ad08cce77411b33528cc62d570841b27c1f48c71e89c230e7d1a7782884dfFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -56,7 +56,7 @@ public abstract class HttpServerDecorator<REQUEST, CONNECTION, RESPONSE, REQUEST | ||
| private static final Logger log = LoggerFactory.getLogger(HttpServerDecorator.class); | ||
| private static final int UNSET_PORT = 0; | ||
| public static final String DD_SPAN_ATTRIBUTE = "datadog.span"; | ||
| public static final String DD_CONTEXT_ATTRIBUTE = "datadog.context"; | ||
| public static final String DD_DISPATCH_SPAN_ATTRIBUTE = "datadog.span.dispatch"; | ||
| public static final String DD_RUM_INJECTED = "datadog.rum.injected"; | ||
| public static final String DD_FIN_DISP_LIST_SPAN_ATTRIBUTE = | ||
| @@ -537,12 +537,16 @@ private Flow<Void> callIGCallbackURI( | ||
| } | ||
| @Override | ||
| public AgentSpan beforeFinish(AgentSpan span) { | ||
| // TODO Migrate beforeFinish to Context API | ||
zarirhamza marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| onRequestEndForInstrumentationGateway(span); | ||
| public Context beforeFinish(Context context) { | ||
| AgentSpan span = AgentSpan.fromContext(context); | ||
zarirhamza marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| if (span != null) { | ||
| onRequestEndForInstrumentationGateway(span); | ||
| } | ||
| // Close Serverless Gateway Inferred Span if any | ||
| // finishInferredProxySpan(context); | ||
zarirhamza marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| return super.beforeFinish(span); | ||
| return super.beforeFinish(context); | ||
| } | ||
| protected void finishInferredProxySpan(Context context) { | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,36 +1,39 @@ | ||
| package datadog.trace.instrumentation.axway; | ||
| import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.activateSpan; | ||
| import static datadog.trace.bootstrap.instrumentation.api.AgentSpan.fromContext; | ||
| import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.startSpan; | ||
| import static datadog.trace.bootstrap.instrumentation.api.Java8BytecodeBridge.getCurrentContext; | ||
| import static datadog.trace.bootstrap.instrumentation.api.Java8BytecodeBridge.getRootContext; | ||
| import static datadog.trace.instrumentation.axway.AxwayHTTPPluginDecorator.DECORATE; | ||
| import static datadog.trace.instrumentation.axway.AxwayHTTPPluginDecorator.SERVER_TRANSACTION_CLASS; | ||
| import datadog.context.Context; | ||
| import datadog.context.ContextScope; | ||
| import datadog.trace.bootstrap.InstrumentationContext; | ||
| import datadog.trace.bootstrap.instrumentation.api.AgentScope; | ||
| import datadog.trace.bootstrap.instrumentation.api.AgentSpan; | ||
| import net.bytebuddy.asm.Advice; | ||
| public class HTTPPluginAdvice { | ||
| @Advice.OnMethodEnter(suppress = Throwable.class) | ||
| public static AgentScope onEnter(@Advice.Argument(value = 2) final Object serverTransaction) { | ||
| public static ContextScope onEnter(@Advice.Argument(value = 2) final Object serverTransaction) { | ||
| final AgentSpan span = startSpan("axway-api", DECORATE.spanName()).setMeasured(true); | ||
| DECORATE.afterStart(span); | ||
| // serverTransaction is like request + connection in one object: | ||
| DECORATE.onRequest(span, serverTransaction, serverTransaction, getRootContext()); | ||
| return activateSpan(span); | ||
| return getCurrentContext().with(span).attach(); | ||
zarirhamza marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| } | ||
| @Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class) | ||
| public static void onExit( | ||
| @Advice.Enter final AgentScope scope, | ||
| @Advice.Enter final ContextScope scope, | ||
| @Advice.Argument(value = 2) final Object serverTransaction, | ||
| @Advice.Thrown final Throwable throwable) { | ||
| if (scope == null) { | ||
| return; | ||
| } | ||
| final AgentSpan span = scope.span(); | ||
| final Context context = scope.context(); | ||
| final AgentSpan span = fromContext(context); | ||
| try { | ||
| if (null != serverTransaction) { | ||
| // manual DECORATE.onResponse(span, serverTransaction): | ||
| @@ -45,7 +48,7 @@ public static void onExit( | ||
| if (throwable != null) { | ||
| DECORATE.onError(span, throwable); | ||
| } | ||
| DECORATE.beforeFinish(span); | ||
| DECORATE.beforeFinish(context); | ||
| } finally { | ||
| scope.close(); | ||
| span.finish(); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -3,9 +3,10 @@ | ||
| import static datadog.trace.agent.tooling.bytebuddy.matcher.HierarchyMatchers.extendsClass; | ||
| import static datadog.trace.agent.tooling.bytebuddy.matcher.NameMatchers.nameStartsWith; | ||
| import static datadog.trace.agent.tooling.bytebuddy.matcher.NameMatchers.named; | ||
| import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.activateSpan; | ||
| import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.activeSpan; | ||
| import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.startSpan; | ||
| import static datadog.trace.bootstrap.instrumentation.api.Java8BytecodeBridge.getCurrentContext; | ||
| import static datadog.trace.bootstrap.instrumentation.api.Java8BytecodeBridge.spanFromContext; | ||
| import static datadog.trace.bootstrap.instrumentation.decorator.http.HttpResourceDecorator.HTTP_RESOURCE_DECORATOR; | ||
| import static datadog.trace.instrumentation.finatra.FinatraDecorator.DECORATE; | ||
| import static datadog.trace.instrumentation.finatra.FinatraDecorator.FINATRA_CONTROLLER; | ||
| @@ -17,9 +18,9 @@ | ||
| import com.twitter.finagle.http.Request; | ||
| import com.twitter.finagle.http.Response; | ||
| import com.twitter.util.Future; | ||
| import datadog.context.ContextScope; | ||
| import datadog.trace.agent.tooling.Instrumenter; | ||
| import datadog.trace.agent.tooling.InstrumenterModule; | ||
| import datadog.trace.bootstrap.instrumentation.api.AgentScope; | ||
| import datadog.trace.bootstrap.instrumentation.api.AgentSpan; | ||
| import datadog.trace.bootstrap.instrumentation.api.Tags; | ||
| import net.bytebuddy.asm.Advice; | ||
| @@ -61,7 +62,7 @@ public void methodAdvice(MethodTransformer transformer) { | ||
| public static class RouteAdvice { | ||
| @Advice.OnMethodEnter(suppress = Throwable.class) | ||
| public static AgentScope nameSpan( | ||
| public static ContextScope nameSpan( | ||
| @Advice.Argument(0) final Request request, | ||
| @Advice.FieldValue("path") final String path, | ||
| @Advice.FieldValue("clazz") final Class clazz) { | ||
| @@ -78,23 +79,23 @@ public static AgentScope nameSpan( | ||
| DECORATE.afterStart(span); | ||
| span.setResourceName(DECORATE.className(clazz)); | ||
| return activateSpan(span); | ||
| return getCurrentContext().with(span).attach(); | ||
| } | ||
| @Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class) | ||
| public static void setupCallback( | ||
| @Advice.Enter final AgentScope scope, | ||
| @Advice.Enter final ContextScope scope, | ||
| @Advice.Thrown final Throwable throwable, | ||
| @Advice.Return final Some<Future<Response>> responseOption) { | ||
| if (scope == null) { | ||
| return; | ||
| } | ||
| final AgentSpan span = scope.span(); | ||
| final AgentSpan span = spanFromContext(scope.context()); | ||
| if (throwable != null) { | ||
| DECORATE.onError(span, throwable); | ||
| DECORATE.beforeFinish(span); | ||
| DECORATE.beforeFinish(scope.context()); | ||
mhlidd marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| span.finish(); | ||
| scope.close(); | ||
| return; | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❔ question: Can this one be removed then? It will prevent other decorator to override it and never being called.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cannot, WebSocketDecorator and its related instrumentation still call it. Needs to be a separate mini-migration
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is that the only one blocker? Because the
WebSocketDecoratoris calling the emptyBaseDecorator.beforeFinish()and has no override... So technically, the call is doing nothing :/So we can move it from
BaseDecoratortoWebSocketDecoratorand migrate it in a second pass.@amarziali What's the effort to migrate the WebSocket instrumentation to context rather than span?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another place where this is called is within the Mule Instrumentation as well via the
MuleDecoratorin mule-4.Moved the empty call to
WebSocketDecoratorandMuleDecoratorthus allowing me to remove the function fromBaseDecorator.I assume the actual span -> context functionality will be taken care of later for both WebSockets and Mule.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I take it back, I'm not sure how the tests aren't catching it but the
ClientDecoratoralso usesbeforeFinish(span)via theBaseDecorator. This seems to indicate that we need to invest time into looking through all decorators and confirming their reliance on beforeFinish. To save time, for now we can focus just onHttpServerDecoratorrelated instrumentationUh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: It seems that there are no meaningful overrides of
beforeFinish(final AgentSpan span), except forAxisMessageDecorator, which takes an extra parameter. To avoid confusion, let's go ahead and removebeforeFinish(final AgentSpan span).Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update: The
AxisMessageDecoratordoes not override thebeforeFinishmethod, but overloads it taking an extra para. This method is the only implementation of thebeforeFinish(final AgentSpan span)method that simply returns the passed span. Let's remove it!?