feat(contrib/mark3labs/mcp-go): set session ID on tool spans at start time#4943
Conversation
|
BenchmarksBenchmark execution time: 2026-07-01 16:40:01 Comparing candidate commit f6787f2 in PR branch Found 0 performance improvements and 0 performance regressions! Performance is the same for 321 metrics, 2 unstable metrics, 1 flaky benchmarks without significant changes.
|
d0e5464 to
0d1c005
Compare
c008d76 to
0dbe777
Compare
0d1c005 to
a8261f9
Compare
0dbe777 to
e079d34
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files🚀 New features to boost your workflow:
|
e079d34 to
f0a5ee7
Compare
a8261f9 to
a850ceb
Compare
f0a5ee7 to
5142cf6
Compare
a850ceb to
cb69328
Compare
716a66d to
f6787f2
Compare
0c444d5 to
2ff4a7b
Compare
There was a problem hiding this comment.
More details
The diff is a clean, minimal port from dd-source. Three adversarial scenarios were executed: a tool call with a valid session (session_id field matches mcp_session_id tag), a tool call with no session in context (both fields empty, no panic), and a tool call with an empty-string session ID (gracefully falls through to propagation). All 18 tests pass. One test was added covering the no-session branch through toolHandlerMiddleware, which no existing test exercised.
📊 Validated against 3 scenarios · Open Bits AI session
🤖 Datadog Autotest · Commit 716a66d · What is Autotest? · Any feedback? Reach out in #autotest
2d2bdea
into
main
…4944) ## Summary One of the reasons we make a clone of this mcp-go contrib in dd-source was for feature flagging. Originally this was supposed to be temporary, but it continues to be used for org opt-outs and compliance. So in order to remove the clone, we now need to build this per-request optionality as a feature of the SDK. ## What this enables in dd-source The internal dd-source copy of this contrib ships its own `isIntentCaptureEnabled(ctx)` predicate in [`mcp-go/flags.go`](https://github.com/DataDog/dd-source/blob/d10d624c374b69aa02168983be725532a38562b1/domains/mcp_services/libs/go/mcp/pre-release-external/dd-trace-go/contrib/mark3labs/mcp-go/flags.go) and calls it directly inside the hook and middleware (no public knob to override the static boolean). With this PR, dd-source can pass that same predicate through `TracingConfig.IntentCaptureEnabledFunc` and delete the local fork of the hook/middleware. ## Test plan - [x] `TestIntentCaptureEnabledFunc` — same config, two contexts: predicate `false` skips schema injection AND leaves the telemetry argument intact in the handler args; predicate `true` injects and strips. - [x] `TestIntentCaptureEnabledFuncOverridesBool` — when both the static `bool` and the predicate are set, the predicate wins. - [x] All existing intent-capture and tracing tests still pass. Stacked on #4943. --- Parallel port in the modelcontextprotocol/go-sdk contrib: #4950 Co-authored-by: jboolean <julian.boilen@datadoghq.com>

This PR stack ports functionality added in the clone of this contrib in dd-source back to dd-trace-go.
Summary
Pass
llmobs.WithSessionIDatStartToolSpantime so LLMObs groups tool spans under their MCP session natively. The session is read fromserver.ClientSessionFromContext(ctx)if present.The existing
mcp_session_idtag is unchanged — they are complementary: the tag exposes the session ID to span search/filtering, whileWithSessionIDpopulates the LLMObs session field used for trace grouping.Provenance
No single dd-source PR — the change landed as part of a series of LLMObs-session changes. The current dd-source middleware lives at
mcp-go/tracing.go#L36-L44:This PR ports that exact pattern, additionally keeping the existing
llmobs.WithIntegration(...)call since the released llmobs package now has it.Test plan
TestIntegrationToolCallSuccessto asserttoolSpan.SessionIDmatches the MCP client session.Stacked on #4942.