# OpenTracing#setTag vs ElasticAPM#setLabel

**URL:** <https://discuss.elastic.co/t/opentracing-settag-vs-elasticapm-setlabel/240263>\
**Category:** APM\
**Tags:** java\
**Created:** [July 8, 2020, 5:29am UTC](https://discuss.elastic.co/t/opentracing-settag-vs-elasticapm-setlabel/240263 "2020-07-08T05:29:28Z")\
**Posts on this page:** 5\
**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:** [July 8, 2020, 5:29am UTC](https://discuss.elastic.co/t/opentracing-settag-vs-elasticapm-setlabel/240263/1 "2020-07-08T05:29:28Z")

</div>

When using the ElasticAPM Openbridge, does this mean that functionality such as ElasticAPM.setLabel needs to be replaced with calls to the OpenTracing API?

Does this also means that it is not possible to use `setType` when using the OpenTracingBridge?

Cheers,  
Milan

---

<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:** [July 8, 2020, 12:40pm UTC](https://discuss.elastic.co/t/opentracing-settag-vs-elasticapm-setlabel/240263/2 "2020-07-08T12:40:46Z")

</div>

You can use both the agent API and the OpenTracing API at the same time if you want to. You can also set the type via the OT API by using the `co.elastic.apm.opentracing.ElasticApmTags#TYPE` constant.

---

<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:** [July 9, 2020, 6:08am UTC](https://discuss.elastic.co/t/opentracing-settag-vs-elasticapm-setlabel/240263/3 "2020-07-09T06:08:09Z")

</div>

Oke, Ill continue testing this then as I currently have a scenario where the label is not being set when using the ElasticAPMAgent but is working with the OpentracingAgent.

---

<div class="post-metadata">

**Author:** ![cyrilleleclerc](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cyrilleleclerc/32/60493_2.png) [@cyrilleleclerc](https://discuss.elastic.co/u/cyrilleleclerc)\
**Post date:** [July 16, 2020, 2:47pm UTC](https://discuss.elastic.co/t/opentracing-settag-vs-elasticapm-setlabel/240263/4 "2020-07-16T14:47:23Z")

</div>

Hello @milanvdm,

Based on @felixbarny, I wrote a simple demo to define "`co.elastic.apm.api.Transaction#type`" through OpenTracing APIs.

Demo: [https://github.com/cyrille-leclerc/my-elasticapm-custom-instrumentation/tree/set-transaction-type](https://github.com/cyrille-leclerc/my-elasticapm-custom-instrumentation/tree/set-transaction-type)

Code snippet

```auto
import co.elastic.apm.api.Transaction;
import co.elastic.apm.opentracing.ElasticApmTags;
...
Span span = tracer.buildSpan("MessageSender#send").start();
try (Scope scope = tracer.scopeManager().activate(span)) {
   ...
   Tags.SPAN_KIND.set(tracer.activeSpan(), Tags.SPAN_KIND_CLIENT);
   Tags.MESSAGE_BUS_DESTINATION.set(tracer.activeSpan(), queueUrl);
   // the transaction type you want: the standard 'request' or a custom type
   ElasticApmTags.TYPE.set(tracer.activeSpan(), Transaction.TYPE_REQUEST);
   ...
} catch (Exception e) {
   Tags.ERROR.set(span, true);
   throw e;
} finally {
   span.finish();
}

```

Sample Elastic APM Transaction JSON document with `transaction.type` defined using OpenTracing APIs: [https://github.com/cyrille-leclerc/my-elasticapm-custom-instrumentation/blob/set-transaction-type/docs/elastic-apm-open-tracing-with-tx-type-amazon-sqs-distributed-trace.json](https://github.com/cyrille-leclerc/my-elasticapm-custom-instrumentation/blob/set-transaction-type/docs/elastic-apm-open-tracing-with-tx-type-amazon-sqs-distributed-trace.json)

---

<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:** [August 6, 2020, 10:47am UTC](https://discuss.elastic.co/t/opentracing-settag-vs-elasticapm-setlabel/240263/5 "2020-08-06T10:47:36Z")

</div>

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