<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Ishara Ekanayaka on Medium]]></title>
        <description><![CDATA[Stories by Ishara Ekanayaka on Medium]]></description>
        <link>https://medium.com/@emipekanayaka24?source=rss-a297b4218e5c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*PBz8j47uNghCFDkrcsNIFA.jpeg</url>
            <title>Stories by Ishara Ekanayaka on Medium</title>
            <link>https://medium.com/@emipekanayaka24?source=rss-a297b4218e5c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 13:43:44 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@emipekanayaka24/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[One trace, many strangers: when trace context crosses a trust boundary]]></title>
            <link>https://medium.com/@emipekanayaka24/one-trace-many-strangers-when-trace-context-crosses-a-trust-boundary-42b2c608ce07?source=rss-a297b4218e5c------2</link>
            <guid isPermaLink="false">https://medium.com/p/42b2c608ce07</guid>
            <category><![CDATA[observability]]></category>
            <category><![CDATA[distributed-tracing]]></category>
            <category><![CDATA[opentelemetry]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[api-gateway]]></category>
            <dc:creator><![CDATA[Ishara Ekanayaka]]></dc:creator>
            <pubDate>Sun, 01 Nov 2026 08:59:41 GMT</pubDate>
            <atom:updated>2026-11-01T12:24:01.646Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>The trace that shouldn’t exist</strong></h3><p>A trace is the record of one operation as it moves through your system. It is made of spans, and a span is one timed step, such as a single HTTP request handled by a service. All the spans in a trace share the same trace ID. Normally, one request means one trace, which is why a trace holding hundreds of unrelated requests looked wrong.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XzEGQmArYMfLoFCXnUbSBg.png" /><figcaption>All requests landed in one trace, even though they hit different endpoints.</figcaption></figure><p>A few weeks after we rolled OpenTelemetry out to production, I opened a trace in Datadog and found something that made no sense: one trace containing multiple separate HTTP requests which should not be in a single trace.</p><p>Each of those requests was an ordinary, independent API call. None of them called the others. But the tracing backend insisted they were all part of one operation.</p><p>This post covers why that happened, why I couldn’t reproduce it in our dev environment, and the small change at the edge that fixed it. The short version: trace context that arrives from outside your system is input, and you shouldn’t trust it by default.</p><p>Here is the demo setup I used for this post. nginx stands in for the gateway, and the backend runs with the OpenTelemetry Java agent. You can run the whole thing yourself with one command in the <a href="https://github.com/IsharaEkanayaka/one-trace-many-strangers">GitHub repo</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/898/1*tabHBUYKDC5IzuUgmXN9Jg.png" /><figcaption>The demo setup: external caller, nginx gateway, instrumented backend, collector and Jaeger</figcaption></figure><h3><strong>First guess: the client is polling</strong></h3><p>The requests all hit a status-inquiry endpoint, the kind a client calls repeatedly while it waits for a longer operation to finish. So my first theory was a client-side polling bug: something calling the endpoint far more often than it should.</p><p>That theory explained the <em>number</em> of requests. It didn’t explain why they were <em>grouped</em>. Every poll is a fresh HTTP request, and every fresh request should start its own trace.</p><p>Then I tried to reproduce it in dev. I sent the same requests through the same flow, against the same code, with the same OpenTelemetry Java agent. Every request got its own trace, exactly as expected.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SF6-_fUu-FPD_FEbdnWnQA.png" /><figcaption>Without a traceparent header, each request gets its own trace.</figcaption></figure><p>That was the real clue. Same code and same agent, but different behaviour. If the code wasn’t different, the input had to be. Production requests were carrying something that my dev requests weren’t.</p><h3><strong>How a request decides which trace it belongs to</strong></h3><p>OpenTelemetry follows the <a href="https://www.w3.org/TR/trace-context/">W3C Trace Context</a> standard. When one service calls another, it adds a <strong>traceparent</strong> header to the outgoing request:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2h58mGgbC-dW7rd1c8hAtw.png" /><figcaption>Anatomy of a traceparent header</figcaption></figure><p>When a request arrives, the OpenTelemetry Java agent looks for this header. By default it extracts both <strong>traceparent</strong> (plus its companion <strong>tracestate</strong>) and <strong>baggage</strong>. If it finds a valid traceparent, the new server span becomes a child of that remote parent and <strong>reuses its trace ID</strong>.</p><p>That is the whole point of distributed tracing. It’s how one trace follows a request across many services.</p><p>The catch is that the agent can’t tell <em>who</em> sent the header. A <strong>traceparent</strong> from your own upstream service looks exactly like one from an external client. So if an outside caller sends the same <strong>traceparent</strong> on every request, every one of those requests joins the same trace.</p><h3><strong>Reproducing it with curl commands</strong></h3><p>Once I had the theory, testing it in dev took minutes. I sent unrelated requests with the same hand-written <strong>traceparent</strong>:</p><pre>TP=&quot;00–cda6bcd13b8744e35e28b9f6ea3db577–00f067aa0ba902b7–01&quot;<br>curl -H &quot;traceparent: $TP&quot; http://localhost:8081/status/123<br>curl -H &quot;traceparent: $TP&quot; http://localhost:8081/status/123<br>curl -H &quot;traceparent: $TP&quot; http://localhost:8081/orders/456</pre><p>Then we look at trace cda6bcd13b8744e35e28b9f6ea3db577 in Jaeger. Both requests were sitting inside it, one trace, exactly like production. Without the header, the same three calls produced three separate traces.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XzEGQmArYMfLoFCXnUbSBg.png" /><figcaption>All requests landed in one trace, even though they hit different endpoints.</figcaption></figure><p>That was days of theorising about polling, settled by a test you could fit in a tweet. If behaviour differs between environments and the code is identical, diff the inputs, and try sending the suspicious input yourself.</p><h3><strong>The fix: strip trace headers at the edge</strong></h3><p>The gateway is where outside traffic becomes inside traffic, so that’s where the decision belongs. I configured it to remove three headers from every incoming request: <strong>traceparent</strong>, <strong>tracestate</strong> and <strong>baggage</strong>.</p><p>Propagation between our own services keeps working. The gateway only drops context that arrives from outside. When the backend makes its own outgoing calls, the agent injects fresh headers as usual.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/395/1*WvHUbu6unTdNhtd5qW2naQ.png" /></figure><p>The idea isn’t specific to one gateway. In nginx, setting proxy_set_header traceparent “”; stops the header being passed upstream. In Envoy, request_headers_to_remove does the same job.</p><p>I applied the change to the dev gateway first and re-ran the curl test: three requests, three traces. Then I rolled it out to production. The giant merged traces stopped appearing.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Z5NGzEEkeAruhBdU-z5IJw.png" /><figcaption>Traces after the fix</figcaption></figure><p>Why not fix it in the agent instead? The otel.propagators setting controls both extracting <em>and</em> injecting context. Setting it to none would break propagation between our own services too. Only the edge knows which traffic is external.</p><h3><strong>What you give up, and why it’s still worth it</strong></h3><p>Stripping the headers has one real cost: you lose the connection to the caller’s trace. If a partner wants to follow a request from their system into yours, that link is gone.</p><p>If you need that link, OpenTelemetry has a better tool than blind trust: <strong>span links</strong>. Instead of joining the caller’s trace, you start a new trace and attach a link pointing at the incoming context. Each request stays its own trace, and the relationship is still recorded. This usually needs a bit of custom instrumentation.</p><p>The headers also carry two other things you probably don’t want strangers controlling:</p><ul><li><strong>Sampling.</strong> The last field of traceparent says whether the caller sampled the trace. OpenTelemetry’s default sampler is parent-based, so it follows that flag. An external caller can effectively decide whether your spans are recorded.</li><li><strong>Baggage.</strong> The baggage header is arbitrary key-value data that can flow into your services.</li></ul><h3><strong>Takeaways</strong></h3><p>- <strong>Trace context headers are input.</strong> Treat traceparent, tracestate and baggage like any other untrusted input at your trust boundary.</p><p>- <strong>Decide at the edge.</strong> Your gateway knows which traffic is external; your services and agents don’t.</p><p>- <strong>When environments disagree, diff the inputs.</strong> Identical code with different behaviour means the requests differ.</p><p>- <strong>Reproduce before you theorise.</strong> curl commands answered what a week of guessing about polling couldn’t.</p><p>If you’re rolling out OpenTelemetry behind a public API, check what your gateway forwards today. It takes five minutes, and it might explain a trace that shouldn’t exist.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=42b2c608ce07" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>