# Opentracing for java apm agent

**URL:** <https://discuss.elastic.co/t/opentracing-for-java-apm-agent/146638>\
**Category:** APM\
**Created:** [August 30, 2018, 7:55am UTC](https://discuss.elastic.co/t/opentracing-for-java-apm-agent/146638 "2018-08-30T07:55:02Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![jibsonline](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jibsonline/32/63154_2.png) [@jibsonline](https://discuss.elastic.co/u/jibsonline)\
**Post date:** [August 30, 2018, 7:55am UTC](https://discuss.elastic.co/t/opentracing-for-java-apm-agent/146638/1 "2018-08-30T07:55:02Z")

</div>

I see opentracing code in java apm agent. How do I enable it and see spans and transactions in APM?

---

<div class="post-metadata">

**Author:** ![felixbarny](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/felixbarny/32/27341_2.png) [@felixbarny](https://discuss.elastic.co/u/felixbarny)\
**Post date:** [August 30, 2018, 8:22am UTC](https://discuss.elastic.co/t/opentracing-for-java-apm-agent/146638/2 "2018-08-30T08:22:59Z")

</div>

Hi, the [documentation](https://www.elastic.co/guide/en/apm/agent/java/current/opentracing-bridge.html) tells you how to get started with OT and Elastic APM. Is there anything you are missing in the docs?

---

<div class="post-metadata">

**Author:** ![jibsonline](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jibsonline/32/63154_2.png) [@jibsonline](https://discuss.elastic.co/u/jibsonline)\
**Post date:** [August 30, 2018, 8:55am UTC](https://discuss.elastic.co/t/opentracing-for-java-apm-agent/146638/3 "2018-08-30T08:55:20Z")

</div>

Sorry but I forgot to mention.... The APM jar is loaded as a java agent when I start my springboot application. So do I need to load it via gradle?

And do I have to initialise the tracer in every controller or is there a common location?

---

<div class="post-metadata">

**Author:** ![felixbarny](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/felixbarny/32/27341_2.png) [@felixbarny](https://discuss.elastic.co/u/felixbarny)\
**Post date:** [August 30, 2018, 9:15am UTC](https://discuss.elastic.co/t/opentracing-for-java-apm-agent/146638/4 "2018-08-30T09:15:49Z")

</div>

Could you tell me a bit more about your use case? What do you want to use the OpenTracing API for? Do you still want the auto instrumentation from the Elastic agent?

You need to use the javaagent and add a dependency to the `apm-opentracing` artifact.

> [@jibsonline](#):
>
> And do I have to initialise the tracer in every controller or is there a common location?

You can use the `GlobalTracer` from `opentracing-util` to globally register your tracer.

---

<div class="post-metadata">

**Author:** ![jibsonline](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jibsonline/32/63154_2.png) [@jibsonline](https://discuss.elastic.co/u/jibsonline)\
**Post date:** [August 30, 2018, 9:31am UTC](https://discuss.elastic.co/t/opentracing-for-java-apm-agent/146638/5 "2018-08-30T09:31:14Z")

</div>

I am already using JAVA APM Agent snapshot(0.7.0) to track my java agents. Right now only SQL queries are being traced behind every transaction. I wanted to know if the internal API calls also can be traced

---

<div class="post-metadata">

**Author:** ![felixbarny](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/felixbarny/32/27341_2.png) [@felixbarny](https://discuss.elastic.co/u/felixbarny)\
**Post date:** [August 30, 2018, 9:39am UTC](https://discuss.elastic.co/t/opentracing-for-java-apm-agent/146638/6 "2018-08-30T09:39:36Z")

</div>

> [@jibsonline](#):
>
> I wanted to know if the internal API calls also can be traced

Which technologies are you using for the internal API calls? Are these external calls, which go over the network? If yes, which protocol are you using? Or do you want to trace internal method calls of certain methods?

You can also use the [public API](https://www.elastic.co/guide/en/apm/agent/java/current/public-api.html) of the agent, which might be a bit easier to use than the OT API.

---

<div class="post-metadata">

**Author:** ![jibsonline](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jibsonline/32/63154_2.png) [@jibsonline](https://discuss.elastic.co/u/jibsonline)\
**Post date:** [August 30, 2018, 9:49am UTC](https://discuss.elastic.co/t/opentracing-for-java-apm-agent/146638/7 "2018-08-30T09:49:43Z")

</div>

We are using

Springboot 1.5.10  
Java : 1.8

We have around 20 microservices which call each other and also call external URLs. I had tried spring sleuth and zipkin. It was pretty straightforward and didn't involve any change in code.

I wanted to know if APM agent worked like that so I dont have to depend on sleuth for tracing

---

<div class="post-metadata">

**Author:** ![jibsonline](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jibsonline/32/63154_2.png) [@jibsonline](https://discuss.elastic.co/u/jibsonline)\
**Post date:** [August 31, 2018, 6:45am UTC](https://discuss.elastic.co/t/opentracing-for-java-apm-agent/146638/8 "2018-08-31T06:45:43Z")

</div>

@felixbarny any suggestions?

---

<div class="post-metadata">

**Author:** ![felixbarny](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/felixbarny/32/27341_2.png) [@felixbarny](https://discuss.elastic.co/u/felixbarny)\
**Post date:** [August 31, 2018, 7:08am UTC](https://discuss.elastic.co/t/opentracing-for-java-apm-agent/146638/9 "2018-08-31T07:08:55Z")

</div>

> [@jibsonline](#):
>
> We have around 20 microservices which call each other and also call external URLs

Sounds like you need distributed tracing. We are currently working on implementing this and it will be the next big feature we are releasing. In the meantime, you can use the java agent to trace each service individually. As soon as we support distributed tracing, you won't have to change anything apart from updating to the new version. To get a glance at how it might look like, see [this](https://github.com/elastic/kibana/issues/20658) issue.

---

<div class="post-metadata">

**Author:** ![felixbarny](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/felixbarny/32/27341_2.png) [@felixbarny](https://discuss.elastic.co/u/felixbarny)\
**Post date:** [August 31, 2018, 8:05am UTC](https://discuss.elastic.co/t/opentracing-for-java-apm-agent/146638/10 "2018-08-31T08:05:20Z")

</div>

BTW, which library are you using to make calls to your services? SpringRestTemplate?

---

<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:** [September 21, 2018, 4:05am UTC](https://discuss.elastic.co/t/opentracing-for-java-apm-agent/146638/11 "2018-09-21T04:05:40Z")

</div>

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