# Traceparent with Spring-ai from Github Copilot

**URL:** <https://discuss.elastic.co/t/traceparent-with-spring-ai-from-github-copilot/389953>\
**Category:** APM\
**Tags:** java\
**Created:** [August 27, 2026, 1:54pm UTC](https://discuss.elastic.co/t/traceparent-with-spring-ai-from-github-copilot/389953 "2026-08-27T13:54:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Wolfram\_Haussig](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/wolfram_haussig/32/70528_2.png) [@Wolfram\_Haussig](https://discuss.elastic.co/u/Wolfram_Haussig)\
**Post date:** [August 27, 2026, 1:54pm UTC](https://discuss.elastic.co/t/traceparent-with-spring-ai-from-github-copilot/389953/1 "2026-08-27T13:54:47Z")

</div>

**Kibana version** : 8.19.17

**Elasticsearch version** : 8.19.17

**APM Server version** : 8.19.17

**APM Agent language and version** : Java, 1.56.0

**Browser version** : Chrome

**Original install method (e.g. download page, yum, deb, from source, etc.) and version**: deb

**Fresh install or upgraded from other version?** upgraded

**Is there anything special in your setup?** Usage with Spring-AI

**Description of the problem including expected versus actual behavior. Please include screenshots (if relevant)**:

I have implemented an MCP-Server in my Java Application (using [Spring-AI](https://docs.spring.io/spring-ai/reference/api/mcp/mcp-server-boot-starter-docs.html)) and use it in Github Copilot. As the Copilot adds a traceparent in the body, I created the following Aspect to get it into Elastic:

```java
@Aspect
@Component
public class McpApmTraceAspect {

    @Around("@annotation(org.springframework.ai.mcp.annotation.McpTool) && args(context,..)")
    public Object traceMcpToolCall(ProceedingJoinPoint joinPoint, McpSyncRequestContext context) throws Throwable {
        Map<String, Object> meta = context.request().meta();
        String methodName = joinPoint.getSignature().getName();

        // ElasticApm nutzt die HeaderExtractor-Lambda, um 'traceparent' & 'tracestate' aus der Map zu lesen
        Transaction transaction = ElasticApm.startTransactionWithRemoteParent(headerName -> {
            Object val = meta.get(headerName);
            return val != null ? val.toString() : null;
        });

        transaction.setName("MCP Tool: " + methodName);
        transaction.setType("request");

        try (Scope scope = transaction.activate()) {
            Object result = joinPoint.proceed();
            transaction.setOutcome(Outcome.SUCCESS);
            return result;
        } catch (Throwable t) {
            transaction.captureException(t);
            transaction.setOutcome(Outcome.FAILURE);
            throw t;
        } finally {
            transaction.end();
        }
    }
}

```

Now, I correctly get the traceId and can search for it in Elastic. So far so good.

But: Github Copilot seems to use simple counters to generate the traceID in the traceParent:

> traceparent=00-00000000000000000000000000000231-0000000000000242-01

What would you suggest would be the best way to store the original trace.parent while preventing conflicts? Just add it as a Custom Context?

Do you think the agent could support Spring AI and read the traceparent directly?

Best regards  
Wolfram

Update:

Here is an example request as logged by the Github Copilot:

```json
{
    "jsonrpc": "2.0",
    "id": 6,
    "method": "tools/call",
    "params": {
        "name": "getXXX",
        "arguments": {},
        "_meta": {
            "progressToken": "e0a9024e-bbb3-431e-81a3-38a0af2353a1",
            "vscode.conversationId": "a43345c8-a4c8-4cd9-97ba-7665e4714c3f",
            "vscode.requestId": "06bb0f3a-3416-4bcb-85bc-2dd68377b7ce",
            "traceparent": "00-00000000000000000000000000000231-0000000000000241-01"
        }
    }
}

```

---

<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:** [September 1, 2026, 1:19pm UTC](https://discuss.elastic.co/t/traceparent-with-spring-ai-from-github-copilot/389953/2 "2026-09-01T13:19:36Z")

</div>

Try with elastic.apm.[trace\_continuation\_strategy](https://www.elastic.co/docs/reference/apm/agents/java/config-core#config-trace-continuation-strategy)=restart\_external and see if that works for this
