Skip to content
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

Merged
merged 39 commits into from
May 18, 2020

Conversation

heathkd
Copy link
Contributor

@heathkd heathkd commented Apr 13, 2020

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.

@heathkd heathkd requested a review from a team as a code owner April 13, 2020 16:03
@heathkd heathkd self-assigned this Apr 13, 2020
@heathkd
Copy link
Contributor Author

heathkd commented Apr 13, 2020

The instrumentation in the "clientV2" package is some experimental instrumentation where the client span is created from HttpClientFilter.java instead of AsyncHttpClient.java. However, I'd like to focus on using the instrumentation in the client packaged and the server package.

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 ClientAdvice.java or ServerAdvice.java to make this happen, please let me know.

@heathkd heathkd changed the title Mulesoft instrumentation WIP Mulesoft instrumentation Apr 13, 2020
@heathkd heathkd force-pushed the heather.dsouza/mulesoft-instrumentation branch 6 times, most recently from 2b8c788 to 5e26ea1 Compare April 19, 2020 19:30
Comment on lines 84 to 88
"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",
Copy link
Contributor Author

@heathkd heathkd Apr 20, 2020

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?

Copy link
Contributor Author

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?

final ContextStore<AsyncCompletionHandler, AgentSpan> contextStore =
InstrumentationContext.get(AsyncCompletionHandler.class, AgentSpan.class);
final AgentSpan span = contextStore.get(handler);
final AgentScope scope = activateSpan(span, true);
Copy link
Contributor Author

@heathkd heathkd Apr 20, 2020

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;
Copy link
Contributor Author

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;
Copy link
Contributor Author

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;
Copy link
Contributor Author

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);
Copy link
Contributor Author

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) {
Copy link
Contributor Author

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().

@heathkd heathkd force-pushed the heather.dsouza/mulesoft-instrumentation branch from e40a1a6 to 858f717 Compare April 21, 2020 14:09
}

final AgentScope scope =
activateSpan((AgentSpan) ctx.getAttributes().getAttribute(SPAN), false);
Copy link
Contributor Author

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.

@richardstartin richardstartin force-pushed the heather.dsouza/mulesoft-instrumentation branch from 71f1216 to 3c9d105 Compare April 30, 2020 22:43
@richardstartin richardstartin force-pushed the heather.dsouza/mulesoft-instrumentation branch from ca7ab34 to 9e0a743 Compare May 14, 2020 09:18
@richardstartin richardstartin changed the title Mulesoft instrumentation Grizzly-http and grizzly-client instrumentation May 15, 2020
@richardstartin richardstartin force-pushed the heather.dsouza/mulesoft-instrumentation branch from a74d603 to baab018 Compare May 15, 2020 15:20
Copy link
Contributor

@tylerbenson tylerbenson left a 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.

@@ -43,7 +44,7 @@ class GrizzlyTest extends HttpServerTest<HttpServer> {

@Override
String expectedOperationName() {
return "grizzly.request"
return DDSpanNames.GRIZZLY_REQUEST
Copy link
Contributor

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

@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();
Copy link
Contributor

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);
Copy link
Contributor

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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fill your boots :)

Copy link
Contributor

@tylerbenson tylerbenson left a 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.

@Advice.Argument(0) final Response response) {
ContextStore<AsyncCompletionHandler, Pair> contextStore =
InstrumentationContext.get(AsyncCompletionHandler.class, Pair.class);
Pair<AgentSpan, AgentSpan> spanWithParent = contextStore.get(handler);
Copy link
Contributor

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.

settings.gradle Outdated Show resolved Hide resolved
@tylerbenson tylerbenson deleted the heather.dsouza/mulesoft-instrumentation branch May 15, 2020 16:50
@tylerbenson tylerbenson restored the heather.dsouza/mulesoft-instrumentation branch May 15, 2020 16:50
@tylerbenson tylerbenson reopened this May 15, 2020
@tylerbenson
Copy link
Contributor

sorry, that was an accident.

@richardstartin richardstartin force-pushed the heather.dsouza/mulesoft-instrumentation branch from b8feb7b to 4b9af37 Compare May 15, 2020 17:23
Comment on lines 31 to 32
compileOnly group: 'org.glassfish.grizzly', name: 'grizzly-http-client', version: '1.12'
testCompile group: 'org.glassfish.grizzly', name: 'grizzly-http-client', version: '1.12'
Copy link
Contributor

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.

Copy link
Member

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.

@richardstartin richardstartin merged commit ee191b1 into master May 18, 2020
@richardstartin richardstartin deleted the heather.dsouza/mulesoft-instrumentation branch May 18, 2020 08:59
@github-actions github-actions bot added this to the 0.52.0 milestone May 18, 2020
iNikem added a commit to open-telemetry/opentelemetry-java-instrumentation that referenced this pull request May 31, 2020
* 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants