-
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
Merged
richardstartin
merged 39 commits into
master
from
heather.dsouza/mulesoft-instrumentation
May 18, 2020
Merged
Changes from all commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
32928ec
set-up instrumentation module
heathkd b940c76
update decorate with request and response objects
heathkd 1041484
initial HttpListener instrumentation
heathkd c08b1cc
initial HttpRequester instrumentation
heathkd 6860ad0
create client span from mule http client
heathkd 75e2c47
remove http listener instrumentation - this will be handled in server…
heathkd 40f4c0f
reorganize and rename client instrumentation classes
heathkd 0a4ad73
add server span instrumentation
heathkd 86b83ec
change class to instrument to HttpServerFilter
heathkd 544a7c6
experiment with creating the client span from HttpClientFilter
heathkd d2991d0
generalize client instrumentation and remove references to mule classes
heathkd 641b1be
add initial tests for client and server instrumentation
heathkd 2cbdbc5
create inject and extract adapter, and close server span after respon…
heathkd 0696943
update client instrumentation and tests
heathkd 8209648
update instrumentation and add executors to whitelist
heathkd 29d70a1
change naming of server spans and update server tests
heathkd 4de6394
change component name of client instrumentation to include grizzly
heathkd fdd6229
instrument HttpCodecFilter instead of HttpServerFilter for server ins…
heathkd 970835f
remove unneeded executors from whitelist
heathkd e116368
rename test classes to reflect the grizzly components they are testing
heathkd 63ad066
apply google java format
richardstartin 1e37c56
rawtypes and dead code
richardstartin 904a4d0
complete client instrumentation
richardstartin eec2d1b
add overload of activateSpan defaulting to not finishing on close
richardstartin 380d611
apply code formatting
richardstartin 2f7fc6e
generify pair
richardstartin 9195a81
ensure a scope is created for the profiler
richardstartin 9945a4f
parent to child link working
richardstartin 9f333b6
handle error traces and fix tests
richardstartin 399e80d
prepare for merge
richardstartin 10dca37
Merge branch 'master' into heather.dsouza/mulesoft-instrumentation
richardstartin 3c9d105
post merge fix
richardstartin 24e9ab2
address basic comments before moving modules
richardstartin 28c4454
rename filterchain instrumentation
richardstartin 0ed2f02
group filterchain and server, remove ContextAttributes
richardstartin 154ae82
Merge branch 'master' into heather.dsouza/mulesoft-instrumentation
richardstartin dc170af
Merge branch 'master' into heather.dsouza/mulesoft-instrumentation
richardstartin 4b9af37
address review comments
richardstartin a802476
clarify grizzly-client version mismatch
richardstartin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
...agent/agent-bootstrap/src/main/java/datadog/trace/bootstrap/instrumentation/api/Pair.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package datadog.trace.bootstrap.instrumentation.api; | ||
|
||
public final class Pair<T, U> { | ||
|
||
public static <T, U> Pair<T, U> of(T left, U right) { | ||
return new Pair<>(left, right); | ||
} | ||
|
||
private final T left; | ||
private final U right; | ||
|
||
Pair(T left, U right) { | ||
this.left = left; | ||
this.right = right; | ||
} | ||
|
||
public T getLeft() { | ||
return left; | ||
} | ||
|
||
public U getRight() { | ||
return right; | ||
} | ||
|
||
public boolean hasLeft() { | ||
return null != left; | ||
} | ||
|
||
public boolean hasRight() { | ||
return null != right; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
dd-java-agent/instrumentation/grizzly-client-1.9/grizzly-client-1.9.gradle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
ext { | ||
minJavaVersionForTests = JavaVersion.VERSION_1_8 | ||
} | ||
|
||
muzzle { | ||
pass { | ||
group = "org.glassfish.grizzly" | ||
module = "grizzly-http-client" | ||
versions = "[1.9,1.16]" | ||
assertInverse = true | ||
} | ||
pass { | ||
group = "com.ning" | ||
module = "async-http-client" | ||
versions = "[1.9.0,)" | ||
assertInverse = true | ||
} | ||
} | ||
|
||
apply from: "${rootDir}/gradle/java.gradle" | ||
|
||
apply plugin: 'org.unbroken-dome.test-sets' | ||
|
||
testSets { | ||
latestDepTest { | ||
dirName = 'test' | ||
} | ||
} | ||
|
||
dependencies { | ||
compileOnly group: 'org.glassfish.grizzly', name: 'grizzly-http-client', version: '1.9' | ||
// for some reason, the tests don't *load* until 1.12, but muzzles works as far back as 1.9 | ||
testCompile group: 'org.glassfish.grizzly', name: 'grizzly-http-client', version: '1.12' | ||
|
||
latestDepTestCompile group: 'org.glassfish.grizzly', name: 'grizzly-http-client', version: '1.16' | ||
} |
39 changes: 39 additions & 0 deletions
39
...lient-1.9/src/main/java/datadog/trace/instrumentation/grizzly/client/ClientDecorator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package datadog.trace.instrumentation.grizzly.client; | ||
|
||
import static datadog.trace.bootstrap.instrumentation.api.DDComponents.GRIZZLY_HTTP_ASYNC_CLIENT; | ||
|
||
import com.ning.http.client.Request; | ||
import com.ning.http.client.Response; | ||
import datadog.trace.bootstrap.instrumentation.decorator.HttpClientDecorator; | ||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
|
||
public class ClientDecorator extends HttpClientDecorator<Request, Response> { | ||
|
||
public static final ClientDecorator DECORATE = new ClientDecorator(); | ||
|
||
@Override | ||
protected String[] instrumentationNames() { | ||
return new String[] {"grizzly-client", "ning"}; | ||
} | ||
|
||
@Override | ||
protected String component() { | ||
return GRIZZLY_HTTP_ASYNC_CLIENT; | ||
} | ||
|
||
@Override | ||
protected String method(final Request request) { | ||
return request.getMethod(); | ||
} | ||
|
||
@Override | ||
protected URI url(final Request request) throws URISyntaxException { | ||
return request.getUri().toJavaNetURI(); | ||
} | ||
|
||
@Override | ||
protected Integer status(final Response response) { | ||
return response.getStatusCode(); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
...t-1.9/src/main/java/datadog/trace/instrumentation/grizzly/client/ClientRequestAdvice.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package datadog.trace.instrumentation.grizzly.client; | ||
|
||
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.propagate; | ||
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.startSpan; | ||
import static datadog.trace.bootstrap.instrumentation.api.DDSpanNames.HTTP_REQUEST; | ||
import static datadog.trace.instrumentation.grizzly.client.ClientDecorator.DECORATE; | ||
import static datadog.trace.instrumentation.grizzly.client.InjectAdapter.SETTER; | ||
|
||
import com.ning.http.client.AsyncHandler; | ||
import com.ning.http.client.Request; | ||
import datadog.trace.bootstrap.InstrumentationContext; | ||
import datadog.trace.bootstrap.instrumentation.api.AgentScope; | ||
import datadog.trace.bootstrap.instrumentation.api.AgentSpan; | ||
import datadog.trace.bootstrap.instrumentation.api.Pair; | ||
import net.bytebuddy.asm.Advice; | ||
|
||
public class ClientRequestAdvice { | ||
|
||
@Advice.OnMethodEnter(suppress = Throwable.class) | ||
public static AgentScope onEnter( | ||
@Advice.Argument(0) final Request request, | ||
@Advice.Argument(1) final AsyncHandler<?> handler) { | ||
AgentSpan parentSpan = activeSpan(); | ||
AgentSpan span = startSpan(HTTP_REQUEST); | ||
DECORATE.afterStart(span); | ||
DECORATE.onRequest(span, request); | ||
propagate().inject(span, request, SETTER); | ||
InstrumentationContext.get(AsyncHandler.class, Pair.class) | ||
.put(handler, Pair.of(parentSpan, span)); | ||
return activateSpan(span); | ||
} | ||
|
||
@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(); | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
.../main/java/datadog/trace/instrumentation/grizzly/client/ClientRequestInstrumentation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package datadog.trace.instrumentation.grizzly.client; | ||
|
||
import static java.util.Collections.singletonMap; | ||
import static net.bytebuddy.matcher.ElementMatchers.isPublic; | ||
import static net.bytebuddy.matcher.ElementMatchers.named; | ||
import static net.bytebuddy.matcher.ElementMatchers.takesArgument; | ||
|
||
import com.google.auto.service.AutoService; | ||
import datadog.trace.agent.tooling.Instrumenter; | ||
import datadog.trace.bootstrap.instrumentation.api.Pair; | ||
import java.util.Map; | ||
import net.bytebuddy.description.method.MethodDescription; | ||
import net.bytebuddy.description.type.TypeDescription; | ||
import net.bytebuddy.matcher.ElementMatcher; | ||
|
||
@AutoService(Instrumenter.class) | ||
public final class ClientRequestInstrumentation extends Instrumenter.Default { | ||
|
||
public ClientRequestInstrumentation() { | ||
super("grizzly-client", "ning"); | ||
} | ||
|
||
@Override | ||
public Map<String, String> contextStore() { | ||
return singletonMap("com.ning.http.client.AsyncHandler", Pair.class.getName()); | ||
} | ||
|
||
@Override | ||
public ElementMatcher<? super TypeDescription> typeMatcher() { | ||
return named("com.ning.http.client.AsyncHttpClient"); | ||
} | ||
|
||
@Override | ||
public String[] helperClassNames() { | ||
return new String[] {packageName + ".ClientDecorator", packageName + ".InjectAdapter"}; | ||
} | ||
|
||
@Override | ||
protected boolean defaultEnabled() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public Map<? extends ElementMatcher<? super MethodDescription>, String> transformers() { | ||
return singletonMap( | ||
named("executeRequest") | ||
.and(takesArgument(0, named("com.ning.http.client.Request"))) | ||
.and(takesArgument(1, named("com.ning.http.client.AsyncHandler"))) | ||
.and(isPublic()), | ||
packageName + ".ClientRequestAdvice"); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
...-1.9/src/main/java/datadog/trace/instrumentation/grizzly/client/ClientResponseAdvice.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package datadog.trace.instrumentation.grizzly.client; | ||
|
||
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.activateSpan; | ||
import static datadog.trace.instrumentation.grizzly.client.ClientDecorator.DECORATE; | ||
|
||
import com.ning.http.client.AsyncCompletionHandler; | ||
import com.ning.http.client.AsyncHandler; | ||
import com.ning.http.client.Response; | ||
import datadog.trace.bootstrap.ContextStore; | ||
import datadog.trace.bootstrap.InstrumentationContext; | ||
import datadog.trace.bootstrap.instrumentation.api.AgentScope; | ||
import datadog.trace.bootstrap.instrumentation.api.AgentSpan; | ||
import datadog.trace.bootstrap.instrumentation.api.Pair; | ||
import net.bytebuddy.asm.Advice; | ||
|
||
@SuppressWarnings({"unchecked", "rawtypes"}) | ||
public class ClientResponseAdvice { | ||
|
||
@Advice.OnMethodEnter(suppress = Throwable.class) | ||
public static AgentScope onEnter( | ||
@Advice.This final AsyncCompletionHandler<?> handler, | ||
@Advice.Argument(0) final Response response) { | ||
ContextStore<AsyncHandler, Pair> contextStore = | ||
InstrumentationContext.get(AsyncHandler.class, Pair.class); | ||
Pair<AgentSpan, AgentSpan> spanWithParent = contextStore.get(handler); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
if (null != spanWithParent) { | ||
contextStore.put(handler, null); | ||
} | ||
if (spanWithParent.hasRight()) { | ||
DECORATE.onResponse(spanWithParent.getRight(), response); | ||
DECORATE.beforeFinish(spanWithParent.getRight()); | ||
spanWithParent.getRight().finish(); | ||
} | ||
return spanWithParent.hasLeft() ? activateSpan(spanWithParent.getLeft()) : null; | ||
} | ||
|
||
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class) | ||
public static void onExit(@Advice.Enter final AgentScope scope) { | ||
if (null != scope) { | ||
scope.close(); | ||
} | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
...main/java/datadog/trace/instrumentation/grizzly/client/ClientResponseInstrumentation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package datadog.trace.instrumentation.grizzly.client; | ||
|
||
import static datadog.trace.agent.tooling.ClassLoaderMatcher.hasClassesNamed; | ||
import static java.util.Collections.singletonMap; | ||
import static net.bytebuddy.matcher.ElementMatchers.hasSuperClass; | ||
import static net.bytebuddy.matcher.ElementMatchers.isPublic; | ||
import static net.bytebuddy.matcher.ElementMatchers.named; | ||
import static net.bytebuddy.matcher.ElementMatchers.takesArgument; | ||
|
||
import com.google.auto.service.AutoService; | ||
import datadog.trace.agent.tooling.Instrumenter; | ||
import datadog.trace.bootstrap.instrumentation.api.Pair; | ||
import java.util.Map; | ||
import net.bytebuddy.description.method.MethodDescription; | ||
import net.bytebuddy.description.type.TypeDescription; | ||
import net.bytebuddy.matcher.ElementMatcher; | ||
|
||
@AutoService(Instrumenter.class) | ||
public final class ClientResponseInstrumentation extends Instrumenter.Default { | ||
|
||
public ClientResponseInstrumentation() { | ||
super("grizzly-client", "ning"); | ||
} | ||
|
||
@Override | ||
public Map<String, String> contextStore() { | ||
return singletonMap("com.ning.http.client.AsyncHandler", Pair.class.getName()); | ||
} | ||
|
||
@Override | ||
public ElementMatcher<ClassLoader> classLoaderMatcher() { | ||
return hasClassesNamed("com.ning.http.client.AsyncCompletionHandler"); | ||
} | ||
|
||
@Override | ||
protected boolean defaultEnabled() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public ElementMatcher<? super TypeDescription> typeMatcher() { | ||
return hasSuperClass(named("com.ning.http.client.AsyncCompletionHandler")); | ||
} | ||
|
||
@Override | ||
public String[] helperClassNames() { | ||
return new String[] {packageName + ".ClientDecorator"}; | ||
} | ||
|
||
@Override | ||
public Map<? extends ElementMatcher<? super MethodDescription>, String> transformers() { | ||
return singletonMap( | ||
named("onCompleted") | ||
.and(takesArgument(0, named("com.ning.http.client.Response"))) | ||
.and(isPublic()), | ||
packageName + ".ClientResponseAdvice"); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
...-client-1.9/src/main/java/datadog/trace/instrumentation/grizzly/client/InjectAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package datadog.trace.instrumentation.grizzly.client; | ||
|
||
import com.ning.http.client.Request; | ||
import datadog.trace.bootstrap.instrumentation.api.AgentPropagation; | ||
|
||
public class InjectAdapter implements AgentPropagation.Setter<Request> { | ||
|
||
public static final InjectAdapter SETTER = new InjectAdapter(); | ||
|
||
@Override | ||
public void set(final Request carrier, final String key, final String value) { | ||
carrier.getHeaders().replaceWith(key, value); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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