# Scala integration

**URL:** <https://discuss.elastic.co/t/scala-integration/219214>\
**Category:** APM\
**Tags:** java\
**Created:** [February 13, 2020, 1:48pm UTC](https://discuss.elastic.co/t/scala-integration/219214 "2020-02-13T13:48:07Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![milanvdm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/milanvdm/32/82732_2.png) [@milanvdm](https://discuss.elastic.co/u/milanvdm)\
**Post date:** [February 13, 2020, 1:48pm UTC](https://discuss.elastic.co/t/scala-integration/219214/1 "2020-02-13T13:48:07Z")

</div>

Hi all,

I would like to start with adding some scala support to the java-apm-agent.

Since the current repo is completely focussed on Java, I would like to discuss how this should be organized. For example, this is how Datadog does it: [https://github.com/DataDog/dd-trace-java](https://github.com/DataDog/dd-trace-java)

One of the main things that I would like to work on, is adding support for the Scala ExecutionContext (and maybe some cats-effect ContextShift support).  
This would allow adding some traces manually on the incoming and outgoing http-requests, but without the need to change your code-base drastically by having to pass the span-ids manually when you are writing Concurrent code.

What do you think?

---

<div class="post-metadata">

**Author:** ![Sylvain\_Juge](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sylvain_juge/32/55521_2.png) [@Sylvain\_Juge](https://discuss.elastic.co/u/Sylvain_Juge)\
**Post date:** [February 13, 2020, 3:54pm UTC](https://discuss.elastic.co/t/scala-integration/219214/2 "2020-02-13T15:54:05Z")

</div>

Hi @milanvdm,

Providing support for Scala is definitely something that we have on our radar, thus any pull-request is welcome :-).

We already have a few issues listed: [https://github.com/elastic/apm-agent-java/search?q=scala&type=Issues](https://github.com/elastic/apm-agent-java/search?q=scala&type=Issues)

There are quite a few challenges to expect, because the agent works at class/bytecode level (and not at source level), and I'm not familiar with the way scala compiler lays out classes from source code (in java it's close to a 1:1 mapping between bytecode and source).

A good start would be to start with building a wrapper for those classes, and make this wrapper call agent API to create transactions/spans.

Once you have that, you should be able to monitor with _minimal code changes_ on the application, and it could then be used as a basis to create a plugin in the agent itself.

---

<div class="post-metadata">

**Author:** ![milanvdm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/milanvdm/32/82732_2.png) [@milanvdm](https://discuss.elastic.co/u/milanvdm)\
**Post date:** [February 21, 2020, 6:18pm UTC](https://discuss.elastic.co/t/scala-integration/219214/3 "2020-02-21T18:18:16Z")

</div>

Hi @Sylvain_Juge,

I'll have a closer look to see if I can create a PR adding a Scala related plugin.

In the meantime, I've created a repo that does some jdbc calls and http-requests using Scala and added the ElasticAPM instrumentation to it: [https://github.com/milanvdm/scala-elastic-apm](https://github.com/milanvdm/scala-elastic-apm)

Since quite some Scala libraries use Java libraries underneath it, I expect things such as jdbc calls to work already.

Some observations:

- JVM metrics are sent correctly (heap-usage, …)
- The Manual Transaction I create at the start of the program and close at the end is also seen correctly
- The debug logs of the ElasticAPMAgent seems to match on the JDBC methods and Thread switches

- Not a single span is shown in the ElasticAPM dashboard
- It doesn’t seem to match on http-calls in the debug logs (although AsyncHttpClient is used as an underlying library)

Since the ElasticAgent clearly logs that it is matching some Bytecode, I'm unsure what the exact reason is on why no spans are being created.

---

<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:** [March 13, 2020, 2:18pm UTC](https://discuss.elastic.co/t/scala-integration/219214/4 "2020-03-13T14:18:20Z")

</div>

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