Elastic APM Java Annotation API

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.


Hi and thanks for giving the Java agent a try!

The annotation can be used like this

    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.


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:



Is this expected behaviour?

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

void doSteps() {

void step1() {

void step2() {

void step3() {

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