Elastic APM Java Annotation API


(Ronald Tumulak) #1

I'm trying to test the Annotation API on a Spring application but I get a compile-time error "cannot find symbol" related to the annotations for both @CaptureScan() and @CaptureTransaction().

I've already configured application_packages and am using agent version 1.0.0.

Without the annotations, the other public APIs (like createSpan(), addTag(), etc) work perfectly, able to create child spans and propagate across in the methods they are embedded in.

As I couldn't find any example annotations use nor more in-depth documentation on this, I'm wondering if I am missing other dependencies or configuration settings.

Thanks!


(Felix Barnsteiner) #2

Hi and thanks for giving the Java agent a try!

The annotation can be used like this

    @CaptureSpan
    private void testSpan() {
    }

Don't forget to import co.elastic.apm.api.CaptureSpan and make sure you are using the apm-agent-api artifact.

See https://github.com/elastic/opbeans-java/pull/20/files for an example.

Cheers,
Felix


(Ronald Tumulak) #3

Thank you very much Felix, we got it working now.

We have a follow up question on @CaptureSpan.

When we are using @CaptureSpan, we notice that each child span graph extends all the way to the end of the transaction, even if we explicitly call end() for each annotated method.

If we are using ElasticApm.createSpan() from the parent span, each method we have a trace on correctly captures the span graph as a waterfall diagram.

It's something like this:

Annotation

Code-only

Is this expected behaviour?


Any plans for manual instrumentation (java)?
(Felix Barnsteiner) #4

Calling end on the span created with @CaptureSpan is not supported and leads to undefined behavior. You could create three different methods like this:

@CaptureSpan
void doSteps() {
    step1();
    step2();
    step3();
}

@CaptureSpan
void step1() {
}

@CaptureSpan
void step2() {
}

@CaptureSpan
void step3() {
}

(system) #5

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.