-
Notifications
You must be signed in to change notification settings - Fork 325
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
Add GlobalTracer #1270
Add GlobalTracer #1270
Conversation
Hints for reviewers: EDIT: rebased on master and force-pushed |
bye bye tracer null checks
private static final Logger logger = LoggerFactory.getLogger(GlobalTracer.class); | ||
|
||
private static final GlobalTracer INSTANCE = new GlobalTracer(); | ||
private volatile Tracer tracer = NoopTracer.INSTANCE; |
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.
Currently, we don't declare the tracer volatile as it's usually created once on startup and never changed in non-test scenarios.
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.
LGTM, only few minor questions & comments.
apm-agent-core/src/main/java/co/elastic/apm/agent/impl/GlobalTracer.java
Outdated
Show resolved
Hide resolved
apm-agent-core/src/main/java/co/elastic/apm/agent/bci/ElasticApmAgent.java
Outdated
Show resolved
Hide resolved
apm-agent-core/src/main/java/co/elastic/apm/agent/bci/ElasticApmAgent.java
Outdated
Show resolved
Hide resolved
apm-agent-core/src/main/java/co/elastic/apm/agent/bci/ElasticApmAgent.java
Outdated
Show resolved
Hide resolved
apm-agent-core/src/main/java/co/elastic/apm/agent/bci/TracerAwareElasticApmInstrumentation.java
Outdated
Show resolved
Hide resolved
apm-agent-core/src/main/java/co/elastic/apm/agent/impl/GlobalTracer.java
Outdated
Show resolved
Hide resolved
@@ -175,8 +183,8 @@ protected AbstractAsyncHandlerInstrumentation(ElementMatcher<? super MethodDescr | |||
|
|||
public static class AsyncHandlerOnCompletedInstrumentation extends AbstractAsyncHandlerInstrumentation { | |||
|
|||
public AsyncHandlerOnCompletedInstrumentation() { | |||
super(named("onCompleted").and(takesArguments(0))); | |||
public AsyncHandlerOnCompletedInstrumentation(ElasticApmTracer tracer) { |
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.
Why do we have to provide tracer explicitly here ? shouldn't we use make AsyncHandlerOnCompletedInstrumentation
extend TracerAwareElasticApmInstrumentation
?
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 because co.elastic.apm.agent.bci.HelperClassManager.ForAnyClassLoader
requires a ElasticApmTracer
@@ -92,6 +93,7 @@ public static Object createSpan(@Advice.Argument(value = 0, typing = Assigner.Ty | |||
String operationName, long microseconds, | |||
@Nullable Iterable<Map.Entry<String, String>> baggage, ClassLoader applicationClassLoader) { | |||
AbstractSpan<?> result = null; | |||
ElasticApmTracer tracer = GlobalTracer.getTracerImpl(); |
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.
Why can't we use GlobalTracer.get()
here instead ?
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.
Because Tracer#startSpan
is not part of the Tracer
interface. That is because it returns a non-null span but because the NoopTracer
only returns nulls, we can't add it to the interface. Normally it's not an issue because spans are started via getActive().createSpan
@@ -121,6 +123,7 @@ public static String onExit(@Advice.FieldValue(value = "childTraceContext", typi | |||
@VisibleForAdvice | |||
@Nullable | |||
public static TraceContext parseTextMap(Iterable<Map.Entry<String, String>> textMap) { | |||
ElasticApmTracer tracer = GlobalTracer.getTracerImpl(); |
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.
as previous, why not use GlobalTracer.get()
?
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.
Similar reason: because TraceContext
needs a ElasticApmTracer
instance so it can start spans.
Merged on the command line via dd3e45f |
What does this PR do?
Depends on #1230
Removes the need for tedious
if (tracer != null)
checks.The separation of
ElasticApmInstrumentation
fromTracerAwareElasticApmInstrumentation
is a preparation step for creating aapm-agent-plugin-sdk
module needed for #937.Checklist
I have updated CHANGELOG.asciidoc