Skip to content

Commit eed2240

Browse files
sentry-junior[bot]Junior
andauthored
feat: add trace/span/log hints to issue details response (#987)
## Summary When the MCP tool returns issue details, the "Using this information" section now includes contextual hints for inspecting traces, spans, and logs — but only when the event has a `trace_id` in its context. ### What changed In `formatIssueOutput` (formatting.ts), three new bullets are added when `event.contexts.trace.trace_id` exists: - **Trace tree**: `get_sentry_resource(resourceType='trace', ...)` — inspect the full distributed trace and span tree - **Search spans**: `search_events(dataset='spans', query='trace:<traceId>')` — find related spans - **Search logs**: `search_events(dataset='logs', query='trace:<traceId>')` — find related logs Each hint uses the correct parameter names and explicit `dataset` values, matching the pattern in `get-trace-details.ts`. ### Why As noted by @AniketDhilip — the issue details response already tells the LLM how to search for other error events (`search_issue_events`), but doesn't mention how to explore traces, spans, or logs. This is a gap since those are often the most useful next steps for debugging. ### Design choices - **Contextual**: hints only appear when a trace_id exists, so responses for events without traces stay compact - **Minimal**: three bullets, using existing tools (`get_sentry_resource` and `search_events`) with correct param names and explicit datasets - **Non-breaking**: breadcrumbs hint remains gated behind `experimentalMode` as before - All existing tests pass with updated snapshot expectations --------- Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com> Co-authored-by: Junior <junior@sentry.io>
1 parent e31c851 commit eed2240

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

‎packages/mcp-core/src/internal/formatting.ts‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1927,11 +1927,22 @@ export function formatIssueOutput({
19271927
output += "\n";
19281928
}
19291929

1930+
const traceId =
1931+
typeof event.contexts?.trace?.trace_id === "string" &&
1932+
event.contexts.trace.trace_id.length > 0
1933+
? event.contexts.trace.trace_id
1934+
: undefined;
1935+
19301936
output += "# Using this information\n\n";
19311937
output += `- You can reference the IssueID in commit messages (e.g. \`Fixes ${issue.shortId}\`) to automatically close the issue when the commit is merged.\n`;
19321938
output +=
19331939
"- The stacktrace includes both first-party application code as well as third-party code, its important to triage to first-party code.\n";
19341940
output += `- To search for specific occurrences or filter events within this issue, use \`search_issue_events(organizationSlug='${organizationSlug}', issueId='${issue.shortId}', query='your query')\`\n`;
1941+
if (traceId) {
1942+
output += `- To inspect the full distributed trace and span tree for this event, use \`get_sentry_resource(resourceType='trace', organizationSlug='${organizationSlug}', resourceId='${traceId}')\`\n`;
1943+
output += `- To search related spans, use \`search_events(organizationSlug='${organizationSlug}', dataset='spans', query='trace:${traceId}')\`\n`;
1944+
output += `- To search related logs, use \`search_events(organizationSlug='${organizationSlug}', dataset='logs', query='trace:${traceId}')\`\n`;
1945+
}
19351946
if (experimentalMode) {
19361947
output += `- To see the trail of events leading up to this error, use \`get_sentry_resource(url='${apiService.getIssueUrl(organizationSlug, issue.shortId)}', resourceType='breadcrumbs')\`\n`;
19371948
}

‎packages/mcp-core/src/tools/get-issue-details.test.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,9 @@ describe("get_issue_details", () => {
258258
- You can reference the IssueID in commit messages (e.g. \`Fixes CLOUDFLARE-MCP-41\`) to automatically close the issue when the commit is merged.
259259
- The stacktrace includes both first-party application code as well as third-party code, its important to triage to first-party code.
260260
- To search for specific occurrences or filter events within this issue, use \`search_issue_events(organizationSlug='sentry-mcp-evals', issueId='CLOUDFLARE-MCP-41', query='your query')\`
261+
- To inspect the full distributed trace and span tree for this event, use \`get_sentry_resource(resourceType='trace', organizationSlug='sentry-mcp-evals', resourceId='3032af8bcdfe4423b937fc5c041d5d82')\`
262+
- To search related spans, use \`search_events(organizationSlug='sentry-mcp-evals', dataset='spans', query='trace:3032af8bcdfe4423b937fc5c041d5d82')\`
263+
- To search related logs, use \`search_events(organizationSlug='sentry-mcp-evals', dataset='logs', query='trace:3032af8bcdfe4423b937fc5c041d5d82')\`
261264
"
262265
`);
263266
});
@@ -514,6 +517,9 @@ describe("get_issue_details", () => {
514517
- You can reference the IssueID in commit messages (e.g. \`Fixes CLOUDFLARE-MCP-41\`) to automatically close the issue when the commit is merged.
515518
- The stacktrace includes both first-party application code as well as third-party code, its important to triage to first-party code.
516519
- To search for specific occurrences or filter events within this issue, use \`search_issue_events(organizationSlug='sentry-mcp-evals', issueId='CLOUDFLARE-MCP-41', query='your query')\`
520+
- To inspect the full distributed trace and span tree for this event, use \`get_sentry_resource(resourceType='trace', organizationSlug='sentry-mcp-evals', resourceId='3032af8bcdfe4423b937fc5c041d5d82')\`
521+
- To search related spans, use \`search_events(organizationSlug='sentry-mcp-evals', dataset='spans', query='trace:3032af8bcdfe4423b937fc5c041d5d82')\`
522+
- To search related logs, use \`search_events(organizationSlug='sentry-mcp-evals', dataset='logs', query='trace:3032af8bcdfe4423b937fc5c041d5d82')\`
517523
"
518524
`);
519525
});
@@ -796,6 +802,9 @@ describe("get_issue_details", () => {
796802
- You can reference the IssueID in commit messages (e.g. \`Fixes CLOUDFLARE-MCP-41\`) to automatically close the issue when the commit is merged.
797803
- The stacktrace includes both first-party application code as well as third-party code, its important to triage to first-party code.
798804
- To search for specific occurrences or filter events within this issue, use \`search_issue_events(organizationSlug='sentry-mcp-evals', issueId='CLOUDFLARE-MCP-41', query='your query')\`
805+
- To inspect the full distributed trace and span tree for this event, use \`get_sentry_resource(resourceType='trace', organizationSlug='sentry-mcp-evals', resourceId='3032af8bcdfe4423b937fc5c041d5d82')\`
806+
- To search related spans, use \`search_events(organizationSlug='sentry-mcp-evals', dataset='spans', query='trace:3032af8bcdfe4423b937fc5c041d5d82')\`
807+
- To search related logs, use \`search_events(organizationSlug='sentry-mcp-evals', dataset='logs', query='trace:3032af8bcdfe4423b937fc5c041d5d82')\`
799808
"
800809
`);
801810
});

0 commit comments

Comments
 (0)