Skip to content

Conversation

@philprime
Copy link
Member

Problem

MCP tool calls were creating orphaned spans without parent transactions, causing Sentry to display <unlabeled transaction> instead of meaningful transaction names. This made it impossible to properly track and analyze MCP tool usage.

Root Cause

The implementation used sentry.StartSpan() which creates spans without transactions. When spans don't have a parent transaction, Sentry automatically wraps them in unlabeled transactions.

Solution

Updated the tracing implementation to create proper transactions following OpenTelemetry MCP Semantic Conventions:

  • Transaction name: tools/call {tool_name} (e.g., tools/call get_action_parameters)
  • Operation: mcp.server
  • Hub management: Proper context propagation
  • All MCP attributes: Correctly attached to transactions

Changes

  • Changed from sentry.StartSpan() to sentry.StartTransaction()
  • Added proper hub management with context cloning
  • Set transaction source to SourceCustom
  • Ensured all MCP semantic convention attributes are preserved

Impact

Before (Broken)

<unlabeled transaction> in Sentry
❌ No visibility into which tool was called
❌ Difficult to filter or analyze

After (Fixed)

✅ Transaction Name: tools/call get_action_parameters
✅ Operation: mcp.server
✅ All MCP metadata properly attached
✅ Easy to filter and analyze by tool name

Testing

  • ✅ All existing tests pass
  • ✅ Build succeeds
  • ✅ Static analysis passes
  • ✅ Code formatted

Compliance

Fully compliant with OpenTelemetry MCP Semantic Conventions:

  • Required attributes: mcp.method.name, mcp.tool.name, mcp.transport, network.transport
  • Optional attributes: mcp.request.argument.*, mcp.tool.result.*

Previously, MCP tool calls created orphaned spans without parent
transactions, causing Sentry to display '<unlabeled transaction>'
instead of meaningful transaction names.

This change updates the tracing implementation to create proper
transactions following OpenTelemetry MCP Semantic Conventions:

- Transaction name: 'tools/call {tool_name}'
- Operation: 'mcp.server'
- Proper hub management to ensure context propagation
- All MCP attributes correctly attached to transactions

Resolves the issue of unlabeled transactions appearing in Sentry,
making MCP tool analytics properly visible and filterable by tool name.
@philprime philprime enabled auto-merge (squash) November 6, 2025 09:15
@philprime philprime merged commit 47a4232 into main Nov 6, 2025
4 checks passed
@philprime philprime deleted the fix/mcp-unlabeled-transactions branch November 6, 2025 09:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants