-
Notifications
You must be signed in to change notification settings - Fork 293
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
Grizzly-http and grizzly-client instrumentation #1365
Grizzly-http and grizzly-client instrumentation #1365
Conversation
The instrumentation in the "clientV2" package is some experimental instrumentation where the client span is created from Currently, the client and server span are being sent as separate traces. I would like to consolidate the two spans into one trace. If there is anything obvious that is missing and should be added to |
2b8c788
to
5e26ea1
Compare
"org.glassfish.grizzly.threadpool.AbstractThreadPool", | ||
"org.glassfish.grizzly.threadpool.FixedThreadPool", | ||
"org.glassfish.grizzly.threadpool.GrizzlyExecutorService", | ||
"org.glassfish.grizzly.threadpool.QueueLimitedThreadPool", | ||
"org.glassfish.grizzly.threadpool.SyncThreadPool", |
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.
Executor instrumentation was skipped for these four executors. FixedThreadPool
, specifically, is instantiated by GrizzlyExecutorService
after HttpServerFilter
receives a request. QueueLimitedThreadPool
is created if a FixedThreadPool cannot be created. Fixed
, QueueLimited
, and Sync
all extend AbstractThreadPool
. Would it make more sense to just add AbstractThreadPool
to the whitelist?
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.
These executors were added to the whitelist to help resolve this issue: when a request is made to the server that then triggers a network request from the client, two traces are created instead of a single trace with the server span as the parent and the client span as the child. However, the problem still persists. Do I need to check that no executors related to the client have been skipped?
...rc/main/java/datadog/trace/instrumentation/mulehttpconnector/client/ClientRequestAdvice.java
Outdated
Show resolved
Hide resolved
final ContextStore<AsyncCompletionHandler, AgentSpan> contextStore = | ||
InstrumentationContext.get(AsyncCompletionHandler.class, AgentSpan.class); | ||
final AgentSpan span = contextStore.get(handler); | ||
final AgentScope scope = activateSpan(span, true); |
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.
This is in-line with the comment in ClientRequestAdvice
. Should the span be reactivated here?
@@ -0,0 +1,36 @@ | |||
package datadog.trace.instrumentation.mulehttpconnector.clientV2; |
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.
Classes in the "clientV2" package can be ignored during review. Please review the classes in the "client" package instead. I was experimenting with slightly different instrumentation for the client.
@@ -0,0 +1,38 @@ | |||
package datadog.trace.instrumentation.mulehttpconnector.clientV2; |
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.
Classes in the "clientV2" package can be ignored during review. Please review the classes in the "client" package instead. I was experimenting with slightly different instrumentation for the client.
@@ -0,0 +1,40 @@ | |||
package datadog.trace.instrumentation.mulehttpconnector.clientV2; |
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.
Classes in the "clientV2" package can be ignored during review. Please review the classes in the "client" package instead. I was experimenting with slightly different instrumentation for the client.
final AgentSpan span = startSpan("mule.http.server", parentContext); | ||
|
||
final AgentScope scope = activateSpan(span, false); | ||
scope.setAsyncPropagation(true); |
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.
When a request is made to the server that then triggers a network request from the client, two traces are created instead of a single trace with the server span as the parent and the client span as the child. I have set asyncPropagation to true, but I have also closed the scope. Would that result in the disconnected server and client spans?
return ctx.getInvokeAction(); | ||
} | ||
|
||
public HttpResponsePacket buildResponse(HttpRequestPacket request) { |
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.
This needs to be updated to call the connector
method. It should also set SUCCESS.body
to the body of the response instead of the reasonPhrase. However, it is unclear how to do this. It may be possible to write the response body using ctx.write().
e40a1a6
to
858f717
Compare
} | ||
|
||
final AgentScope scope = | ||
activateSpan((AgentSpan) ctx.getAttributes().getAttribute(SPAN), false); |
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.
The span is activated and the scope is explicitly closed. However, the logs point to an error where the tracer is attempting to close a specific scope while the current scope is "null". This code may be the cause for that error.
71f1216
to
3c9d105
Compare
.../instrumentation/mule-http-connector-1.0/src/test/groovy/GrizzlyFilterchainServerTest.groovy
Outdated
Show resolved
Hide resolved
...va-agent/agent-bootstrap/src/main/java/datadog/trace/bootstrap/instrumentation/api/Pair.java
Outdated
Show resolved
Hide resolved
ca7ab34
to
9e0a743
Compare
a74d603
to
baab018
Compare
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.
Looks like you already resolved some of these comments. I'm going to submit now and continue reviewing.
dd-java-agent/instrumentation/grizzly-client-1.1/grizzly-client-1.1.gradle
Outdated
Show resolved
Hide resolved
...y-client-1.1/src/main/java/datadog/trace/instrumentation/grizzly/client/ClientDecorator.java
Outdated
Show resolved
Hide resolved
...src/main/java/datadog/trace/instrumentation/grizzly/client/ClientRequestInstrumentation.java
Outdated
Show resolved
Hide resolved
dd-java-agent/instrumentation/grizzly-client-1.1/grizzly-client-1.1.gradle
Outdated
Show resolved
Hide resolved
@@ -43,7 +44,7 @@ class GrizzlyTest extends HttpServerTest<HttpServer> { | |||
|
|||
@Override | |||
String expectedOperationName() { | |||
return "grizzly.request" | |||
return DDSpanNames.GRIZZLY_REQUEST |
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.
Did you want a static import here
dd-java-agent/instrumentation/grizzly-client-1.1/grizzly-client-1.1.gradle
Outdated
Show resolved
Hide resolved
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class) | ||
public static void onExit(@Advice.Enter final AgentScope scope) { | ||
// span closed in ClientResponseAdvice, scope only created for profiler's benefit | ||
scope.close(); |
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.
We tend to do a null check on these but I don't think it could be null here
@@ -36,6 +37,7 @@ | |||
internConstantsUTF8(Tags.class); | |||
internConstantsUTF8(DDSpanTypes.class); | |||
internConstantsUTF8(DDComponents.class); | |||
internConstantsUTF8(DDSpanNames.class); |
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.
We might want a follow-up PR that goes through all the others and moves them here
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.
fill your boots :)
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.
A few minor questions and comments remaining then I think we can merge.
...ient-1.9/src/main/java/datadog/trace/instrumentation/grizzly/client/ClientRequestAdvice.java
Outdated
Show resolved
Hide resolved
@Advice.Argument(0) final Response response) { | ||
ContextStore<AsyncCompletionHandler, Pair> contextStore = | ||
InstrumentationContext.get(AsyncCompletionHandler.class, Pair.class); | ||
Pair<AgentSpan, AgentSpan> spanWithParent = contextStore.get(handler); |
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.
It's easy to lose track of what's left and what's right below... consider assigning them to more descriptive local variables early.
...ain/java/datadog/trace/instrumentation/grizzlyhttp232/DefaultFilterChainInstrumentation.java
Outdated
Show resolved
Hide resolved
...ain/java/datadog/trace/instrumentation/grizzlyhttp232/DefaultFilterChainInstrumentation.java
Show resolved
Hide resolved
...http-2.3.20/src/main/java/datadog/trace/instrumentation/grizzlyhttp232/GrizzlyDecorator.java
Outdated
Show resolved
Hide resolved
sorry, that was an accident. |
b8feb7b
to
4b9af37
Compare
compileOnly group: 'org.glassfish.grizzly', name: 'grizzly-http-client', version: '1.12' | ||
testCompile group: 'org.glassfish.grizzly', name: 'grizzly-http-client', version: '1.12' |
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.
Please set the compileOnly to 1.9 and add a comment saying that the tests only seem to work with 1.12.
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.
Done. Would be good to get to the bottom of this one.
* Define packages in exporter class loader (#409) * Update docs about needing java 11 to build (#412) * Update version to 0.3.0 (#413) * Update the README (#414) * Move build and configure to top as getting started section * Add manual instrumentation section * Document `@WithSpan` annotation * Move developer specific information to CONTRIBUTING.md * Cleanup formatting and use consistent spacing * Update version to 0.4.0-SNAPSHOT (#415) * Update CONTRIBUTING.md back to Java 11 (#419) * Add Zipkin exporter support (#411) * #375 Add Zipkin exporter support Signed-off-by: Sergei Malafeev <sergeymalafeev@gmail.com> * #375 use OkHttpSender for Zipkin exporter Signed-off-by: Sergei Malafeev <sergeymalafeev@gmail.com> * #375 add Zipkin exporter to README Signed-off-by: Sergei Malafeev <sergeymalafeev@gmail.com> Co-authored-by: Trask Stalnaker <trask.stalnaker@gmail.com> * Remove inactive maintainer (#420) * Fix brolen anchor link (#422) * Fix khttp instrumentation in case of absent or read-only headers map (#416) * Add new approver (#429) * Fix sqlNormalizerEnabled initialization (#432) * Remove unused config (#424) * Change names of servlet based server spans (#428) * Add documentation describing non-obvious points of Servlet instrumentations * Change names of servlet based server spans * Fix java google format (#439) * Remove deprecated usage from internal instrumentation (DataDog/dd-trace-java#1441) * Update gradle to 6.4 (DataDog/dd-trace-java#1443) * Migrate lettuce instrumentation away from deprecated finishSpanOnClose (DataDog/dd-trace-java#1445) * Make Retrys consistent (DataDog/dd-trace-java#1442) * Rename java packages for lettuce 4 and 5 to not have collisions (DataDog/dd-trace-java#1450) * Adding an option to manually disable Kafka headers (DataDog/dd-trace-java#1448) * Add version specific names to allow disabling only a specific version (DataDog/dd-trace-java#1456) * Attempt to improve muzzle time by randomly ignoring versions until 10 remain (DataDog/dd-trace-java#1451) * Save circle cache with name matching restore patterns (DataDog/dd-trace-java#1457) * Wrap log statements using varargs to avoid object allocation (DataDog/dd-trace-java#1466) * Grizzly-http and grizzly-client instrumentation (DataDog/dd-trace-java#1365) * More refactoring for ScopeManager (DataDog/dd-trace-java#1467) * Remove Java 9 and 10 from the build (DataDog/dd-trace-java#1473) * Disable CI cache for muzzle (DataDog/dd-trace-java#1479) * Separate out core instrumentation for AWS SDK to allow manual setup o… (#421) * Separate out core instrumentation for AWS SDK to allow manual setup of instrumentation. * Instrumentation core test * Fix sporadic Elasticsearch test failures (#444) * Fix sporadic grizzly test failure (#448) * Fixes integration with latest version of Finatra (#450) * #425 allow only one propagator per concern (#451) * Updates to reflect new repo name (#454) * Remove printlns that were accidentally committed (#459) * Remove unnecessary version constant (#455) Co-authored-by: Trask Stalnaker <trask.stalnaker@gmail.com> Co-authored-by: Steve Flanders <steve@omnition.io> Co-authored-by: Sergei Malafeev <sergeymalafeev@gmail.com> Co-authored-by: Tyler Benson <tyler.benson@datadoghq.com> Co-authored-by: Nikolay Martynov <mar.kolya@gmail.com> Co-authored-by: Brian Devins-Suresh <brian.devinssuresh@datadoghq.com> Co-authored-by: Richard Startin <richard.startin@datadoghq.com> Co-authored-by: Anuraag Agrawal <anuraaga@gmail.com>
The Mulesoft instrumentation traces API calls made from HttpListener and HttpRequester components. Under the hood, these components use grizzly for both the server and client logic. As a result, this PR adds instrumentation to Grizzly.
For development purposes, the instrumentation is currently located in the mule-http-connector module of the tracer. However, it should be added to the grizzly module before being merged.