Skip to content

feat(core): Associate resource/tool/prompt invocations with request span instead of response span #16126

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from

Conversation

lforst
Copy link
Member

@lforst lforst commented Apr 24, 2025

This PR adds a best effor mechanism to associate handler spans for resource, tool and prompt with the incoming message requests instead of the outgoing SSE response.

The work is based on the upstream PR which exposes the request id on the handler metadata: modelcontextprotocol/typescript-sdk#358

This PR actually also fixes a bug where we were instrumenting the registering of the handler instead of the actual handler 🤦‍♂️.

One thing to note in this PR is that it has a risk of being slightly memory leaky. We are storing away spans by session and request id and cleaning them up when they are used. In the case of long lived sessions the span will not be garbage collected for a long time. There is unfortunately no way of doing a weak reference because session id and request ids are primitives and the framework doesn't give us any identity objects to cross-reference stuff with.

@lforst lforst requested a review from AbhiPrasad April 24, 2025 12:04
@lforst lforst requested review from Lms24 and mydea April 25, 2025 09:26
Co-authored-by: Lukas Stracke <[email protected]>
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