Skip to content

Conversation

@jboolean
Copy link

@jboolean jboolean commented Nov 5, 2025

NB: This is part of a stack

What does this PR do?

In addition to tool calls, record task spans for session initialization.

image.png

Motivation

We want to record data like clientInfo during session Initialization and this seems like the best way to do it.

I considered a metric, but in the future we will also want to tag the session ID, and metrics do not do well with unique tags. Also, this allows viewing everything together in the LLMObs UI.

A writeup with more context on this design

Relates to MLOB-4373

Future

In future PRs I will add tags for client info and session ID.

Reviewer's Checklist

  • Changed code has unit tests for its functionality at or near 100% coverage.
  • System-Tests covering this feature have been added and enabled with the va.b.c-dev version tag.
  • There is a benchmark for any new code, or changes to existing code.
  • If this interacts with the agent in a new way, a system test has been added.
  • New code is free of linting errors. You can check this by running ./scripts/lint.sh locally.
  • Add an appropriate team label so this PR gets put in the right place for the release notes.
  • Non-trivial go.mod changes, e.g. adding new modules, are reviewed by @DataDog/dd-trace-go-guild.

Unsure? Have a question? Request a review!

@github-actions github-actions bot added the apm:ecosystem contrib/* related feature requests or bugs label Nov 5, 2025
Copy link
Author

jboolean commented Nov 5, 2025

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

@jboolean jboolean changed the title Trace initializations with spans feat(contrib/mcp-go): Trace MCP session initializations with MLObs spans Nov 5, 2025
@jboolean jboolean requested review from a team, Kyle-Verhoog, rarguelloF and tomshen November 5, 2025 21:27
@pr-commenter
Copy link

pr-commenter bot commented Nov 5, 2025

Benchmarks

Benchmark execution time: 2025-11-07 19:57:54

Comparing candidate commit 5f20214 in PR branch jb/contrib-mcp-go-init-span with baseline commit 65cc8e1 in branch jb/contrib-mcp-go-base.

Found 0 performance improvements and 0 performance regressions! Performance is the same for 24 metrics, 0 unstable metrics.

@jboolean jboolean marked this pull request as ready for review November 5, 2025 21:39
@tomshen tomshen removed their request for review November 6, 2025 15:36
span.AnnotateTextIO(string(inputJSON), err.Error())
}
if annotator, ok := span.(textIOAnnotator); ok {
inputJSON, _ := json.Marshal(message)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this expected to happen often? I think at least we should log something (debug if this is expected to happen somewhat frequently, or warn if not).

also, should we annotate the input with the error or some special message to let customers know something went wrong directly while viewing the span?

Comment on lines 73 to 78
inputJSON, _ := json.Marshal(request)
var outputText string
if result != nil {
resultJSON, _ := json.Marshal(result)
outputText = string(resultJSON)
}
resultJSON, _ := json.Marshal(result)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here, i think we should handle these errors somehow

)
toolCache.OnEviction(func(ctx context.Context, reason ttlcache.EvictionReason, item *ttlcache.Item[any, *llmobs.ToolSpan]) {
spanCache.OnEviction(func(ctx context.Context, reason ttlcache.EvictionReason, item *ttlcache.Item[any, llmobs.Span]) {
if span := item.Value(); span != nil {
if reason == ttlcache.EvictionReasonExpired {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we also finish spans that were evicted for other reasons?

@jboolean jboolean force-pushed the jb/contrib-mcp-go-init-span branch from 498ae3a to 792093f Compare November 7, 2025 18:57
@jboolean jboolean force-pushed the jb/contrib-mcp-go-base branch from 95af4d3 to 4def1e6 Compare November 7, 2025 19:01
@jboolean jboolean force-pushed the jb/contrib-mcp-go-init-span branch 2 times, most recently from 27c29ed to f2727e3 Compare November 7, 2025 19:40
@jboolean jboolean force-pushed the jb/contrib-mcp-go-init-span branch from f2727e3 to 5f20214 Compare November 7, 2025 19:43
@datadog-official
Copy link
Contributor

datadog-official bot commented Nov 7, 2025

⚠️ Tests

⚠️ Warnings

❄️ 1 New flaky test detected

TestWrapConsumerGroupHandler from github.com/DataDog/dd-trace-go/contrib/IBM/sarama/v2 (Datadog)
Failed

=== RUN   TestWrapConsumerGroupHandler
2025/11/07 19:51:11 Sarama consumer up and running!...
    consumer_group_test.go:146: Message claimed: value = test 1, timestamp = 2025-11-07 19:51:11.207 +0000 UTC, topic = IBM_sarama_TestWrapConsumerGroupHandler
    consumer_group_test.go:88: 
        	Error Trace:	/home/runner/work/dd-trace-go/dd-trace-go/contrib/IBM/sarama/consumer_group_test.go:88
        	Error:      	"[
        	            	name: kafka.produce
        	            	tags: map[string]interface {}{"_dd.base_service":"", "_dd.p.tid":"690e4daf00000000", "_dd.profiling.enabled":0, "_dd.top_level":1, "component":"IBM/sarama", "language":"go", "messaging.destination.name":"IBM_sarama_TestWrapConsumerGroupHandler", "messaging.kafka.partition":0, "messaging.system":"kafka", "offset":0, "resource.name":"Produce Topic IBM_sarama_TestWrapConsumerGroupHandler", "service.name":"kafka", "span.kind":"producer", "span.name":"kafka.produce", "span.type":"queue"}
...

ℹ️ Info

🧪 All tests passed

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 5f20214 | Docs | Datadog PR Page | Was this helpful? Give us feedback!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

apm:ecosystem contrib/* related feature requests or bugs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants