Skip to content

Add parent context to new trace spans#484

Merged
DaleSeo merged 16 commits intomainfrom
david/add-traceparent-context-to-new-spans
Dec 15, 2025
Merged

Add parent context to new trace spans#484
DaleSeo merged 16 commits intomainfrom
david/add-traceparent-context-to-new-spans

Conversation

@david-castaneda
Copy link
Copy Markdown
Contributor

@david-castaneda david-castaneda commented Nov 13, 2025

Support propagating traceparent context into newly created spans. Previously, the server ignored traceparent headers from upstream services, breaking distributed tracing across service boundaries.

Changes in this PR:

  • Added custom otel_context_middleware that extracts traceparent headers and stores the parent span in request extensions for RMCP handlers to access
  • Updated call_tool and list_tools handlers to retrieve parent span from extensions

This fixes mcp-server spans appearing as siblings instead of children of the upstream service trace.

Trace Hierarchy - Before & After

Before

Screenshot 2025-12-10 at 2 45 46 PM

After

Screenshot 2025-12-10 at 2 41 40 PM

@apollo-librarian
Copy link
Copy Markdown
Contributor

apollo-librarian Bot commented Dec 10, 2025

✅ Docs preview has no changes

The preview was not built because there were no changes.

Build ID: 09c6558baec9c5c419753f3d
Build Logs: View logs

@david-castaneda david-castaneda marked this pull request as ready for review December 10, 2025 20:37
@github-actions
Copy link
Copy Markdown
Contributor

Changeset file missing for PR

All changes should include an associated changeset file.
Please refer to README for more information on generating changesets.

@david-castaneda david-castaneda marked this pull request as draft December 10, 2025 21:20
@david-castaneda david-castaneda marked this pull request as ready for review December 10, 2025 21:23
@DaleSeo DaleSeo self-requested a review December 10, 2025 21:48
Copy link
Copy Markdown
Member

@DaleSeo DaleSeo left a comment

Choose a reason for hiding this comment

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

Hey @david-castaneda! Thanks for fixing our distributed trace propagation. The before/after screenshots really show the value! I just have a bit of minor feedback.

Comment thread .changesets/feat_david_support_traceparent_context.md Outdated
Comment thread crates/apollo-mcp-server/src/server/states/telemetry.rs
Copy link
Copy Markdown
Member

@DaleSeo DaleSeo left a comment

Choose a reason for hiding this comment

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

Thanks for adding the tests!

@DaleSeo DaleSeo merged commit fc9bc21 into main Dec 15, 2025
11 checks passed
@DaleSeo DaleSeo deleted the david/add-traceparent-context-to-new-spans branch December 15, 2025 22:00
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.

3 participants