# Elastic APM with Playframework

**URL:** <https://discuss.elastic.co/t/elastic-apm-with-playframework/172122>\
**Category:** APM\
**Created:** [March 13, 2019, 10:31am UTC](https://discuss.elastic.co/t/elastic-apm-with-playframework/172122 "2019-03-13T10:31:54Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![matpil](https://avatars.discourse-cdn.com/v4/letter/m/df788c/32.png) [@matpil](https://discuss.elastic.co/u/matpil)\
**Post date:** [March 13, 2019, 10:31am UTC](https://discuss.elastic.co/t/elastic-apm-with-playframework/172122/1 "2019-03-13T10:31:55Z")

</div>

Hi all,  
I try to integrate Elastic APM with playframework.

For this reason I wrote a simple filter:

```
package filters;

import akka.stream.Materializer;
import co.elastic.apm.api.ElasticApm;
import co.elastic.apm.api.Transaction;

import javax.inject.Inject;
import java.util.concurrent.CompletionStage;
import java.util.function.Function;

import co.elastic.apm.attach.ElasticApmAttacher;
import play.mvc.*;

public class APMFilter extends Filter {

    @Inject
    public APMFilter(Materializer mat) {
        super(mat);
    }

    @Override
    public CompletionStage<Result> apply(Function<Http.RequestHeader, CompletionStage<Result>> next, Http.RequestHeader rh) {

        Transaction transaction = ElasticApm.startTransaction();
        transaction.setName("play_transaction");
        transaction.setType(Transaction.TYPE_REQUEST);

        return next.apply(rh).thenApply(result -> {
            transaction.setResult(""+result.status());
            transaction.end();
            return result;
        });
    }

}

```

but in elastic APM nothing is visualized.

Someone can help me?

## Regars

matpil

---

<div class="post-metadata">

**Author:** ![Eyal\_Koren](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/eyal_koren/32/36830_2.png) [@Eyal\_Koren](https://discuss.elastic.co/u/Eyal_Koren)\
**Post date:** [March 18, 2019, 8:01am UTC](https://discuss.elastic.co/t/elastic-apm-with-playframework/172122/2 "2019-03-18T08:01:29Z")

</div>

Hi and thanks for trying it out.

I don't have any experience with Play, but I'll try 🙂

I am not sure why you imported `co.elastic.apm.attach.ElasticApmAttacher`, which is used for remote attachment to the JVM. Please review [the different available setup options](https://www.elastic.co/guide/en/apm/agent/java/current/setup.html).  
Basically, the Java agent is either provided as the `javaagent` command line argument (e.g. using [these Play options to specify JVM arguments](https://www.playframework.com/documentation/2.2.x/ProductionConfiguration#Specifying-additional-JVM-arguments)), or remotely attached.

In any case, the agent itself needs to be installed. Note that the API jar (which contains the `co.elastic.apm.api.ElasticApm` you are using here) is acting as noop as long as the Java agent is not installed.

I hope this makes sense.  
Eyal.

---

<div class="post-metadata">

**Author:** ![matpil](https://avatars.discourse-cdn.com/v4/letter/m/df788c/32.png) [@matpil](https://discuss.elastic.co/u/matpil)\
**Post date:** [March 18, 2019, 8:44am UTC](https://discuss.elastic.co/t/elastic-apm-with-playframework/172122/3 "2019-03-18T08:44:24Z")

</div>

Hi,  
thank for reply!

Actually the co.elastic.apm.attach.ElasticApmAttacher import it's not used (but thanks for reporting).

In the end the only way to make it work was to use cinnamon and connect it via opentracing to ElasticApm.  
To do this, however, I had to start 2 agents (apm and cinnamon).

...and add a custom tracer factory like this:

```
import co.elastic.apm.opentracing.ElasticApmTracer;
import com.lightbend.cinnamon.opentracing.TracerFactory;
import io.opentracing.Tracer;

public class CustomTracerFactory implements TracerFactory {

    @Override
    public Tracer create() {
        return new ElasticApmTracer();
    }

}

```

I hope this is useful to someone

Regards  
matpil

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [April 8, 2019, 4:44am UTC](https://discuss.elastic.co/t/elastic-apm-with-playframework/172122/4 "2019-04-08T04:44:24Z")

</div>

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