A team adds the OpenTelemetry Java agent to a service that OneAgent already monitors. The result: every request shows up twice, a trace stops dead halfway down the call chain, and nobody knows which response time to trust. OneAgent OpenTelemetry duplicate spans are a common problem, and the fix is a simple architecture decision: one instrumentation owner per process.
Goal of this tutorial: find the cause of duplicate spans or broken context, choose the right coexistence mode, then check that each request produces a single, complete trace. The content applies to both Dynatrace SaaS and Dynatrace Managed; the trace analysis screens differ, the logic is the same.
For the big picture of an end-to-end instrumented chain, also read OpenTelemetry end to end with Dynatrace.
Why OneAgent and OpenTelemetry create duplicate spans
Three causes come up almost every time:
- Two auto-instrumentations in the same process. OneAgent instruments the JVM (or the .NET, Node.js… runtime) and the OpenTelemetry agent instruments the same HTTP and JDBC libraries. Each call produces two spans, sent along two different paths.
- OpenTelemetry spans captured twice. OneAgent can capture spans created with the OpenTelemetry API in a process it monitors. If the application also exports those spans over OTLP to Dynatrace, they arrive once through OneAgent and once through OTLP.
- Broken context propagation. Service A sends a
traceparentheader (W3C Trace Context) that service B ignores, or a proxy strips the headers. B starts a new trace: the chain is cut in two.
Prerequisites
- A Dynatrace SaaS or Managed environment with OneAgent in full-stack mode on the hosts or through Dynatrace Operator.
- Read access to the environment settings (OneAgent features, process monitoring).
- For OpenTelemetry services: an API token with the
openTelemetryTrace.ingestscope and an OTLP endpoint, direct or through the OpenTelemetry Collector. - Shell or
kubectlaccess to the processes involved.
Steps to remove OneAgent OpenTelemetry duplicate spans
Step 1 — Inventory who instruments what
On a host, list the agents loaded into the JVMs:
# Java agents loaded at startup
ps -eo pid,args | grep -E 'javaagent|JAVA_TOOL_OPTIONS' | grep -v grep
# OpenTelemetry variables of a process (replace 1234 with the PID)
tr '\0' '\n' < /proc/1234/environ | grep -E '^OTEL_|JAVA_TOOL_OPTIONS'
On Kubernetes, look for both possible injections in the pods:
kubectl get pod checkout-7d9f -n shop -o yaml \
| grep -E 'instrumentation.opentelemetry.io|oneagent.dynatrace.com|JAVA_TOOL_OPTIONS'
If you see both a OneAgent injection and the OpenTelemetry Operator annotation instrumentation.opentelemetry.io/inject-java: "true", the process has two owners.
Step 2 — Choose one owner per process
| Mode | Who instruments | When to choose it |
|---|---|---|
| A. OneAgent owns it | OneAgent; the OpenTelemetry API is used only for manual business spans | Services already monitored by OneAgent, teams that want PurePath and profiling |
| B. OpenTelemetry owns it | OpenTelemetry SDK or agent; OneAgent stays on the host without instrumenting this process | Teams standardising on OpenTelemetry, multi-tool portability |
| C. Mixed per service | A for some services, B for others | Gradual migration; requires end-to-end W3C propagation |
What you must never do: run two active auto-instrumentations in the same JVM.
Step 3a — Mode A: OneAgent owns the process
Remove the OpenTelemetry agent from startup and turn off OTLP trace export. Keep the OpenTelemetry API in the code if you create business spans:
# Remove -javaagent:opentelemetry-javaagent.jar from JAVA_TOOL_OPTIONS
# If an OpenTelemetry SDK is still initialised in the code:
export OTEL_TRACES_EXPORTER=none
Then check in the OneAgent features settings that the OneAgent code module’s OpenTelemetry Span Sensor is enabled for your technology (available for Java, Go, Node.js, PHP and .NET). The exact option name varies by language and version; search for « OpenTelemetry » in the list and confirm in the Dynatrace OpenTelemetry documentation. A process restart is usually required.
Step 3b — Mode B: OpenTelemetry owns the process
Stop OneAgent from instrumenting the process without removing it from the host. On Kubernetes with Dynatrace Operator, disable injection at pod level:
apiVersion: apps/v1
kind: Deployment
metadata:
name: checkout
spec:
template:
metadata:
annotations:
oneagent.dynatrace.com/inject: "false"
instrumentation.opentelemetry.io/inject-java: "true"
On a classic host, create a process monitoring rule that excludes this process from deep monitoring (Settings → Processes and containers, depending on your version). OneAgent still collects host metrics. Operator details are in Dynatrace Operator on Kubernetes.
Step 4 — Fix context propagation
For mixed chains, both worlds must speak W3C Trace Context. On the OpenTelemetry side, set the propagators explicitly:
export OTEL_PROPAGATORS=tracecontext,baggage
On the OneAgent side, check in the distributed tracing settings that sending W3C Trace Context headers is enabled (it is on by default in recent versions; confirm on yours). Also check proxies, API gateways and service meshes: they must forward traceparent and tracestate without rewriting them.
How to check it works
Send a test request with a known traceparent:
curl -s -o /dev/null -w '%{http_code}\n' \
-H 'traceparent: 00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01' \
https://checkout.example.internal/api/cart
On SaaS, look for that trace in Grail:
fetch spans, from: now() - 15m
| filter trace.id == "4bf92f3577b34da6a3ce929d0e0e4736"
| summarize spans = count(), by: { dt.entity.service, span.name }
| sort spans desc
Expected: each service/operation pair appears once per real call. Two different services for the same process (for example one named by OneAgent and one named by service.name) point to double instrumentation. Field names may vary: check them with fetch spans | limit 1. On Managed, open the distributed traces view, filter on the service and check that the trace contains every expected service, with no duplicated node.
Best practices
- Write the rule into your platform standards: one process, one instrumentation owner.
- During a migration, use the same
service.nameas the service name OneAgent shows, to keep SLO continuity. - After each change, compare request counts before and after: a volume halved means a duplicate is gone, not that traffic dropped.
- Duplicates also inflate licence consumption and distort SLIs: treat them as a reliability risk, see SLO burn rate alerts.
Frequently asked questions
Can I keep OneAgent and the OpenTelemetry API in the same service?
Yes, that is mode A. The OpenTelemetry API creates business spans; OneAgent captures them. Duplicates only appear if an OTLP exporter also sends those spans.
Are OpenTelemetry metrics duplicated too?
They are not captured by the same mechanism as spans. The main risk is exporting the same metric twice through two paths (SDK and Collector, for example). Check your export pipelines.
Does mixed mode weaken analysis?
It works if W3C propagation is complete. Some OneAgent-specific analyses, such as code profiling, are missing for services instrumented only with OpenTelemetry.
Conclusion
OneAgent OpenTelemetry duplicate spans are not a bug to work around but the symptom of two competing instrumentations. Take inventory, choose one owner per process, enforce W3C Trace Context, then verify trace by trace. Your SLIs become trustworthy again, and so does incident analysis.
span.observer is an independent community blog, not affiliated with Dynatrace LLC. Dynatrace is a trademark of Dynatrace LLC. Features evolve quickly: check their availability in your environment and in the official documentation.
Originally published on span.observer. French version: https://span.observer/fr/oneagent-opentelemetry-doublons-spans/.
Top comments (0)