From 36bd3629784c9cd41dc1d8961514b74434f5fb9f Mon Sep 17 00:00:00 2001 From: nikkikapadia Date: Thu, 26 Nov 2026 16:04:55 -0500 Subject: [PATCH 1/3] feat(mcp): add sentry telemetry to search_attributes tool --- docs/operations/monitoring.md | 2 + .../tools/support/search-attributes/search.ts | 71 +++++++++++++++---- 2 files changed, 59 insertions(+), 14 deletions(-) diff --git a/docs/operations/monitoring.md b/docs/operations/monitoring.md index cabe2f56f..958ba0411 100644 --- a/docs/operations/monitoring.md +++ b/docs/operations/monitoring.md @@ -189,6 +189,8 @@ These are Sentry MCP application attributes that are not part of the MCP semanti - `app.side_quests.detected`, `app.side_quests.shown` - Integer counts of side quests detected and shown; `0` when detectors ran and found none. Each shown quest also increments the `app.side_quest.shown` counter metric, tagged `side_quest.id`, which trace sampling does not drop - `app.side_quest.related_issues_open.issue_ids` - Comma-separated short IDs of the related issues that `update_issue`'s `related_issues_open` quest lists (up to 3), so analytics can match a later `get_sentry_resource` or `update_issue` call to a suggested issue - `app.side_quest.related_issues_open.count` - Integer count of related issues still open when `update_issue` shows the `related_issues_open` quest, the number its tip states; a lower bound when a relation type filled its page +- `app.search_attributes.outcome` - How a `search_attributes` call ended: `list` (no `query`), `best_match`, `candidates`, `no_match`, `none_seen` (no attributes in the period), or a fallback to listing, `no_ai_provider` or `ai_unavailable`. Each call also increments the `app.search_attributes.result` counter metric, tagged `dataset`, `outcome`, and `key_cap_reached`, which trace sampling does not drop +- `app.search_attributes.key_cap_reached` - Whether any attribute type came back near the attributes endpoint's limit of about 1000 keys, so the first list may be missing keys - `app.upstream.host` - Upstream Sentry host configured for the server - `app.url.full` - MCP URL configured for stdio diff --git a/packages/mcp-core/src/tools/support/search-attributes/search.ts b/packages/mcp-core/src/tools/support/search-attributes/search.ts index 9f7d8c9e6..0b9003ef0 100644 --- a/packages/mcp-core/src/tools/support/search-attributes/search.ts +++ b/packages/mcp-core/src/tools/support/search-attributes/search.ts @@ -1,3 +1,4 @@ +import { getActiveSpan } from "@sentry/core"; import { ApiClientError, type TraceItemAttribute } from "../../../api-client"; import { ConfigurationError, UserInputError } from "../../../errors"; import { hasAgentProvider } from "../../../internal/agents/provider-factory"; @@ -101,11 +102,16 @@ export async function runSearchAttributes( mayBeIncomplete: rowsReachesLimit, }); - if (!query) return listAttributes(); + if (!query) { + return recordResult(listAttributes(), { keyCapReached: rowsReachesLimit }); + } if (!hasAgentProvider()) { - return listAttributes( - "Matching by `query` needs an AI provider, so these are the dataset's attributes instead.", + return recordResult( + listAttributes( + "Matching by `query` needs an AI provider, so these are the dataset's attributes instead.", + ), + { keyCapReached: rowsReachesLimit, fallback: "no_ai_provider" }, ); } @@ -179,21 +185,58 @@ export async function runSearchAttributes( }); if (!matches) { - return listAttributes( - narrowedByHints - ? "The AI provider couldn't match `query` right now, so these are the attributes with names related to it, plus Sentry's common search fields." - : "The AI provider couldn't match `query` right now, so these are the dataset's attributes instead.", + return recordResult( + listAttributes( + narrowedByHints + ? "The AI provider couldn't match `query` right now, so these are the attributes with names related to it, plus Sentry's common search fields." + : "The AI provider couldn't match `query` right now, so these are the dataset's attributes instead.", + ), + { keyCapReached: rowsReachesLimit, fallback: "ai_unavailable" }, ); } - return buildFindResult({ - dataset, - period, - query, - matches, - totalAttributes: rows.length, - mayBeIncomplete: !allSearchHintCallsSuccessful && rowsReachesLimit, + return recordResult( + buildFindResult({ + dataset, + period, + query, + matches, + totalAttributes: rows.length, + mayBeIncomplete: !allSearchHintCallsSuccessful && rowsReachesLimit, + }), + { keyCapReached: rowsReachesLimit }, + ); +} + +/** + * Records how the call ended on the tool span, plus a counter metric that + * trace sampling does not drop. Outcome values are part of this contract. + */ +function recordResult( + output: SearchAttributesOutput, + { + keyCapReached, + fallback, + }: { + keyCapReached: boolean; + fallback?: "no_ai_provider" | "ai_unavailable"; + }, +): SearchAttributesOutput { + let outcome: string; + if (fallback) outcome = fallback; + else if (output.totalAttributes === 0) outcome = "none_seen"; + else if (output.resultType === "list") outcome = "list"; + else if (output.best) outcome = "best_match"; + else if (output.attributes.length > 0) outcome = "candidates"; + else outcome = "no_match"; + + getActiveSpan()?.setAttributes({ + "gen_ai.tool.call.result.count": + output.attributes.length + (output.best ? 1 : 0), + "app.search_attributes.outcome": outcome, + "app.search_attributes.key_cap_reached": keyCapReached, }); + return output; } /** From 9c25a8d0a202b6d3b686a239247deca00d39082c Mon Sep 17 00:00:00 2001 From: nikkikapadia Date: Thu, 26 Nov 2026 16:09:15 -0500 Subject: [PATCH 2/3] remove comment --- .../mcp-core/src/tools/support/search-attributes/search.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/mcp-core/src/tools/support/search-attributes/search.ts b/packages/mcp-core/src/tools/support/search-attributes/search.ts index 0b9003ef0..0304feaff 100644 --- a/packages/mcp-core/src/tools/support/search-attributes/search.ts +++ b/packages/mcp-core/src/tools/support/search-attributes/search.ts @@ -209,8 +209,7 @@ export async function runSearchAttributes( } /** - * Records how the call ended on the tool span, plus a counter metric that - * trace sampling does not drop. Outcome values are part of this contract. + * Records how the call ended on the tool span */ function recordResult( output: SearchAttributesOutput, From d1ec38c8f2e480860f975b852bd436ec6fe4054e Mon Sep 17 00:00:00 2001 From: nikkikapadia Date: Thu, 26 Nov 2026 16:14:34 -0500 Subject: [PATCH 3/3] I missed the metrics reference in monitoring.md --- docs/operations/monitoring.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/operations/monitoring.md b/docs/operations/monitoring.md index 958ba0411..07bc6195a 100644 --- a/docs/operations/monitoring.md +++ b/docs/operations/monitoring.md @@ -189,7 +189,7 @@ These are Sentry MCP application attributes that are not part of the MCP semanti - `app.side_quests.detected`, `app.side_quests.shown` - Integer counts of side quests detected and shown; `0` when detectors ran and found none. Each shown quest also increments the `app.side_quest.shown` counter metric, tagged `side_quest.id`, which trace sampling does not drop - `app.side_quest.related_issues_open.issue_ids` - Comma-separated short IDs of the related issues that `update_issue`'s `related_issues_open` quest lists (up to 3), so analytics can match a later `get_sentry_resource` or `update_issue` call to a suggested issue - `app.side_quest.related_issues_open.count` - Integer count of related issues still open when `update_issue` shows the `related_issues_open` quest, the number its tip states; a lower bound when a relation type filled its page -- `app.search_attributes.outcome` - How a `search_attributes` call ended: `list` (no `query`), `best_match`, `candidates`, `no_match`, `none_seen` (no attributes in the period), or a fallback to listing, `no_ai_provider` or `ai_unavailable`. Each call also increments the `app.search_attributes.result` counter metric, tagged `dataset`, `outcome`, and `key_cap_reached`, which trace sampling does not drop +- `app.search_attributes.outcome` - How a `search_attributes` call ended: `list` (no `query`), `best_match`, `candidates`, `no_match`, `none_seen` (no attributes in the period), or a fallback to listing, `no_ai_provider` or `ai_unavailable` - `app.search_attributes.key_cap_reached` - Whether any attribute type came back near the attributes endpoint's limit of about 1000 keys, so the first list may be missing keys - `app.upstream.host` - Upstream Sentry host configured for the server - `app.url.full` - MCP URL configured for stdio