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

Add GlobalTracer #1270

Closed
wants to merge 3 commits into from
Closed

Add GlobalTracer #1270

wants to merge 3 commits into from

Conversation

felixbarny
Copy link
Member

@felixbarny felixbarny commented Jul 2, 2020

What does this PR do?

Depends on #1230

Removes the need for tedious if (tracer != null) checks.

The separation of ElasticApmInstrumentation from TracerAwareElasticApmInstrumentation is a preparation step for creating a apm-agent-plugin-sdk module needed for #937.

Checklist

  • This is an enhancement of existing features, or a new feature in existing plugins
    • I have updated CHANGELOG.asciidoc
    • I have added tests that prove my fix is effective or that my feature works
    • Added an API method or config option? Document in which version this will be introduced
    • I have made corresponding changes to the documentation
  • This is a bugfix
  • This is a new plugin
    • I have updated CHANGELOG.asciidoc
    • My code follows the style guidelines of this project
    • I have made corresponding changes to the documentation
    • I have added tests that prove my fix is effective or that my feature works
    • New and existing unit tests pass locally with my changes
    • I have updated CHANGELOG.asciidoc
    • I have updated supported-technologies.asciidoc
    • Added an API method or config option? Document in which version this will be introduced
    • Added an instrumentation plugin? Describe how you made sure that old, non-supported versions are not instrumented by accident.
  • This is something else

@apmmachine
Copy link
Contributor

apmmachine commented Jul 2, 2020

💚 Build Succeeded

Pipeline View Test View Changes Artifacts preview

Expand to view the summary

Build stats

  • Build Cause: [Pull request #1270 updated]

  • Start Time: 2020-07-02T14:02:17.288+0000

  • Duration: 43 min 22 sec

Test stats 🧪

Test Results
Failed 0
Passed 1459
Skipped 11
Total 1470

@felixbarny felixbarny requested a review from SylvainJuge July 2, 2020 12:54
@felixbarny
Copy link
Member Author

felixbarny commented Jul 2, 2020

Hints for reviewers:
I've based this on #1230 as both touch lots of plugins and rebasing one on the other would be near impossible. Only commit 0e20bf0 is relevant currently.
Most of the interesting changes are in the core plugin. This touches most plugins but there are no significant logic changes other than removed null checks that are not necessary anymore.

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

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.

Copy link
Member

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

@@ -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) {
Copy link
Member

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 ?

Copy link
Member Author

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

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 ?

Copy link
Member Author

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

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

Copy link
Member Author

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.

@felixbarny
Copy link
Member Author

Merged on the command line via dd3e45f

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.

3 participants