# This can happen when not properly deactivating a previous span or context

**URL:** <https://discuss.elastic.co/t/this-can-happen-when-not-properly-deactivating-a-previous-span-or-context/378026>\
**Category:** APM\
**Tags:** java, open-telemetry\
**Created:** [May 12, 2025, 8:34am UTC](https://discuss.elastic.co/t/this-can-happen-when-not-properly-deactivating-a-previous-span-or-context/378026 "2025-05-12T08:34:35Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Oskars\_Adamovics](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/oskars_adamovics/32/143039_2.png) [@Oskars\_Adamovics](https://discuss.elastic.co/u/Oskars_Adamovics)\
**Post date:** [May 12, 2025, 8:34am UTC](https://discuss.elastic.co/t/this-can-happen-when-not-properly-deactivating-a-previous-span-or-context/378026/1 "2025-05-12T08:34:35Z")

</div>

Current stack setup:

1. Spring boot version: 3.4.1
2. Apache camel version: 4.9.0
3. ActiveMQ: 5.14.0
4. Elastic apm agent version: 1.53.0
5. Apm server version: 8.12.2
6. Java version: 17

After upgrading Spring boot version from 2.7.6 to 3.4.1 and apache camel from 3.14.6 to 4.9.0 we partially lost trace id information in log messages. For some messages it logged empty trace id.

Before upgrade we had apache camel camel-opentracing-starter dependecy which worked great in cooperation with elastic-apm-agent-1.48.1.jar and APM server with version 8.12.2. But during apache camel upgrade from v3 to v4 camel-opentracing become deprecated and apache camel suggested to start using camel-opentelemetry-starter.

After upgrade we partialy lost trace id information in part of log messages. It logged empty trace id and some warning information like this:

```auto
2025-05-12 09:38:21.533 | 2025-05-12 06:38:21,532 [Camel (camel-1) thread #28 - JmsConsumer[annual.party.renewal]] WARN co.elastic.apm.agent.opentelemetry.tracing.OTelSpan - The addEvent API is not supported at the moment
2025-05-12 09:38:21.538 | [2025-05-12 06:38:21,538][INFO][annual-party-renewal-request-handle] {trace.id=90c5220d6c2e3b4b2dfb9ad7679f4ee6, transaction.id=311045dd12ac947a} Processing Party Renewal request
2025-05-12 09:38:21.544 | 2025-05-12 06:38:21,543 [Camel (camel-1) thread #28 - JmsConsumer[annual.party.renewal]] WARN co.elastic.apm.agent.impl.ActiveStack - Deactivating a context (OTelBridgeContext[{opentelemetry-trace-span-key=OtelSpan['activemq' 00-90c5220d6c2e3b4b2dfb9ad7679f4ee6-5a49f3b9b8fc9bc5-01 (4d9154a7)]}]) which is not the currently active one ('JMS RECEIVE from queue annual.party.renewal' 00-90c5220d6c2e3b4b2dfb9ad7679f4ee6-311045dd12ac947a-01 (742172c3)). This can happen when not properly deactivating a previous span or context.
2025-05-12 09:38:22.861 | 2025-05-12 06:38:22,861 [Camel (camel-1) thread #28 - JmsConsumer[annual.party.renewal]] WARN co.elastic.apm.agent.impl.ActiveStack - Deactivating a context (OTelBridgeContext[{opentelemetry-trace-span-key=OtelSpan['activemq' 00-90c5220d6c2e3b4b2dfb9ad7679f4ee6-5a49f3b9b8fc9bc5-01 (4d9154a7)]}]) which is not the currently active one (OTelBridgeContext[{}]). This can happen when not properly deactivating a previous span or context.
2025-05-12 09:38:23.879 | 2025-05-12 06:38:23,878 [Camel (camel-1) thread #58 - JmsConsumer[annual.policy.lifecycle.handle]] WARN co.elastic.apm.agent.impl.ActiveStack - Deactivating a context (OTelBridgeContext[{opentelemetry-trace-span-key=OtelSpan['activemq' 00-90c5220d6c2e3b4b2dfb9ad7679f4ee6-de91df46cd8b6fbb-01 (372fca52)]}]) which is not the currently active one ('JMS RECEIVE from queue annual.policy.lifecycle.handle' 00-90c5220d6c2e3b4b2dfb9ad7679f4ee6-ddd3f4d93dc45faa-01 (7dd3b0d7)). This can happen when not properly deactivating a previous span or context.
2025-05-12 09:38:23.893 | 2025-05-12 06:38:23,892 [Camel (camel-1) thread #58 - JmsConsumer[annual.policy.lifecycle.handle]] WARN co.elastic.apm.agent.impl.ActiveStack - Deactivating a context (OTelBridgeContext[{opentelemetry-trace-span-key=OtelSpan['activemq' 00-90c5220d6c2e3b4b2dfb9ad7679f4ee6-de91df46cd8b6fbb-01 (372fca52)]}]) which is not the currently active one (OTelBridgeContext[{}]). This can happen when not properly deactivating a previous span or context.
2025-05-12 09:38:23.901 | [2025-05-12 06:38:23,901][INFO][annual-renewal-handle-serve] {} Processing Enrich request
2025-05-12 09:38:30.172 | [2025-05-12 06:38:30,171][INFO][com.lv.app.enrichment.Service] {} Found bad debt score

```

Replacing elastic-apm-agent-1.53.0.jar java agent with opentelemetry-javaagent.jar trace id again were presented in log messages.

Is this some OpenTelemetry bridge problem?  
We are not using manual instrumentation.  
We are using apache camel provided component camel-opentelemetry in order to trace routes.

---

<div class="post-metadata">

**Author:** ![Jack\_Shirazi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jack_shirazi/32/91641_2.png) [@Jack\_Shirazi](https://discuss.elastic.co/u/Jack_Shirazi)\
**Post date:** [May 14, 2025, 1:52pm UTC](https://discuss.elastic.co/t/this-can-happen-when-not-properly-deactivating-a-previous-span-or-context/378026/2 "2025-05-14T13:52:59Z")

</div>

Did the log messages with empty trace IDs correspond to each "addEvent API is not supported"?

Are there specific features of the Elastic APM Java agent you need, or can you switch to using the [EDOT Java agent](https://github.com/elastic/elastic-otel-java)?

---

<div class="post-metadata">

**Author:** ![Oskars\_Adamovics](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/oskars_adamovics/32/143039_2.png) [@Oskars\_Adamovics](https://discuss.elastic.co/u/Oskars_Adamovics)\
**Post date:** [May 14, 2025, 2:29pm UTC](https://discuss.elastic.co/t/this-can-happen-when-not-properly-deactivating-a-previous-span-or-context/378026/3 "2025-05-14T14:29:28Z")

</div>

```auto
Are there specific features of the Elastic APM Java agent you need, or can you switch to using the EDOT Java agent?

```

I tried elastic-otel-javaagent-1.4.1.jar and trace ID were presented in log messages, but had the problem with metrics. Metric informations were missing in Elasticsearch (Kibana -\> Observability -\> Applications -\> Service Inventory -\> some app -\> Metrics)  
Tried to pass -Dotel.instrumentation.micrometer.enabled=true but without success.

Also didn`t find the way how to pass in elastic-otel-javaagent those parameters:  
-Delastic.apm.service\_node\_name="service node"  
-Delastic.apm.hostname="hostname"  
-Delastic.apm.application\_packages="application package"

> **[Migration](https://elastic.github.io/opentelemetry/edot-sdks/java/migration.html)**
>
> Migrating to EDOT Java from the Elastic Java Agent This documentation describes how to update applications that are currently using the Elastic APM Java agent to use the Elastic Distribution of OpenTelemetry Java (EDOT Java).

Can it be passed via OTEL\_RESOURCE\_ATTRIBUTES?

I guess there are no such options in OpenTelemetry?  
Have to check if there are specific features of the Elastic APM Java agent which we need.

```auto
Did the log messages with empty trace IDs correspond to each "addEvent API is not supported"?

```

Not sure. I made test for concrete use case and a log example was added here.

---

<div class="post-metadata">

**Author:** ![Jack\_Shirazi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jack_shirazi/32/91641_2.png) [@Jack\_Shirazi](https://discuss.elastic.co/u/Jack_Shirazi)\
**Post date:** [May 14, 2025, 3:21pm UTC](https://discuss.elastic.co/t/this-can-happen-when-not-properly-deactivating-a-previous-span-or-context/378026/4 "2025-05-14T15:21:16Z")

</div>

-Dotel.resource.attributes=host.name=somethingelse,...

application\_packages is not needed

I'm not sure about the service node name, but I don't think you need to set it, it should find the right ID for that

micrometer should be enabled with that flag, what metric are you expecting that isn't present?

---

<div class="post-metadata">

**Author:** ![Oskars\_Adamovics](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/oskars_adamovics/32/143039_2.png) [@Oskars\_Adamovics](https://discuss.elastic.co/u/Oskars_Adamovics)\
**Post date:** [May 15, 2025, 8:56am UTC](https://discuss.elastic.co/t/this-can-happen-when-not-properly-deactivating-a-previous-span-or-context/378026/5 "2025-05-15T08:56:25Z")

</div>

```auto
micrometer should be enabled with that flag, what metric are you expecting that isn't present?

```

Sorry, my fault, had to wait a little bit longer. Now metrics are presented in Kibana. Only need to find out how to change from dot chart to line chart in tables.

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/3/e/3ee1383a18982e53aa3b3b34ed2e46707029b3ea.png)

```auto
I'm not sure about the service node name, but I don't think you need to set it, it should find the right ID for that

```

It would be great if I could somehow manage to pass this service\_node\_name information, otherwise it does not look readable:

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/2/6/266ef3714d4296439c4b30b7fea04b3528f741e0.png)

So far everything looks good with elastic-otel-javaagent, except this "service\_node\_name" 🙂

---

<div class="post-metadata">

**Author:** ![Jack\_Shirazi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jack_shirazi/32/91641_2.png) [@Jack\_Shirazi](https://discuss.elastic.co/u/Jack_Shirazi)\
**Post date:** [May 15, 2025, 11:11am UTC](https://discuss.elastic.co/t/this-can-happen-when-not-properly-deactivating-a-previous-span-or-context/378026/6 "2025-05-15T11:11:29Z")

</div>

-Dotel.resource.attributes=host.name=else,service.instance.id=something

---

<div class="post-metadata">

**Author:** ![Oskars\_Adamovics](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/oskars_adamovics/32/143039_2.png) [@Oskars\_Adamovics](https://discuss.elastic.co/u/Oskars_Adamovics)\
**Post date:** [May 15, 2025, 11:28am UTC](https://discuss.elastic.co/t/this-can-happen-when-not-properly-deactivating-a-previous-span-or-context/378026/7 "2025-05-15T11:28:43Z")

</div>

A huge thank to You! service.instace.id=something works fine.  
Migrating elastic-apm-agent to elastic-otel-javaagent solved the problem.

But returning to the original problem, do you have any clue why elastic-apm-agent + camel-opentelemtry does not work out of the box as it should?

---

<div class="post-metadata">

**Author:** ![Jack\_Shirazi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jack_shirazi/32/91641_2.png) [@Jack\_Shirazi](https://discuss.elastic.co/u/Jack_Shirazi)\
**Post date:** [May 15, 2025, 11:59am UTC](https://discuss.elastic.co/t/this-can-happen-when-not-properly-deactivating-a-previous-span-or-context/378026/8 "2025-05-15T11:59:53Z")

</div>

There could be many different things. When there's an upgrade and especially where they've removed support for a technology it runs across instrumentation, the bridge, configuration. Given there's a valid solution, I won't be able to prioritizing spending more effort on this at this time
