Skip to content

search_events links to traces explorer instead of /explore/conversations/{id}/ for AI conversation queries #1034

@sentry-junior

Description

@sentry-junior

Problem

When the MCP returns results related to AI conversations, the "View in Sentry" link points to the generic traces explorer with a filter query:

https://sentry.sentry.io/explore/traces/?query=gen_ai.conversation.id%3A%2214365297%22&project=6178942&statsPeriod=7d

The correct link is the dedicated AI Conversations page:

https://sentry.sentry.io/explore/conversations/14365297/

The Conversations page exists specifically for this data and gives a much better experience than the traces explorer with a filter bolted on.


Root cause

In search-events/handler.ts, the explorer URL is always built via apiService.getEventsExplorerUrl(...), which unconditionally generates an /explore/traces/ URL. There's no special case for when the query targets a specific conversation ID.

Meanwhile, getAIConversationUrl() already exists in url-utils.ts and generates the correct /explore/conversations/{id}/ path — it's just never used in the search_events path.

The get_ai_conversation_details tool already uses the right URL (it calls apiService.getAIConversationUrl(...) directly), so the problem is isolated to the search_events surface.


Fix

In search-events/handler.ts, after the query is resolved, check if the Sentry query contains a single gen_ai.conversation.id value. If so, override explorerUrl with the conversations page URL instead of the traces explorer URL:

// After sentryQuery is resolved:
const conversationIdMatch = sentryQuery.match(/gen_ai\.conversation\.id:"?([^"\s]+)"?/);
const explorerUrl = conversationIdMatch
  ? apiService.getAIConversationUrl(organizationSlug, conversationIdMatch[1])
  : apiService.getEventsExplorerUrl(...);

Acceptance Criteria

  • When search_events is called with a query containing gen_ai.conversation.id:X, the "View in Sentry" link in the result is https://{host}/organizations/{org}/explore/conversations/X/
  • All other span/error/log/replay queries continue to use the traces explorer URL unchanged
  • Test updated to assert the correct URL format

References


View Session in Sentry

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingjavascriptPull requests that update javascript code
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions