Traceparent with Spring-ai from Github Copilot

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) 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:

@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:

{
    "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"
        }
    }
}