Repository navigation
feat(mcp): add attributes detail info to matches in search_attributes - #2864
nikkikapadia wants to merge 10 commits into
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
📊 MCP Server Token Cost ReportSummary
Per-Tool Breakdown
Note: This measures the static overhead of tool definitions sent to LLM clients with every request. Lower is better. MCP Apps viewsEach
The budget applies to raw bytes, and the view's generator fails over it. |
There was a problem hiding this comment.
The details merge and output schema look solid, and the tests cover the partial-failure paths well. A few things before this goes to the team:
- Feature flag: in getsentry/sentry,
OrganizationTraceItemAttributeDetailsEndpointreturns a bare 404 unless the org hasorganizations:attribute-management(still a FlagPole flag intemporary.py). For any org without it, everysearch_attributesmatch now makes up tolimitextra requests that all 404, and every response gets "Some additional attribute details are unavailable." Check the org feature once, from the org'sfeatureslist, before fanning out, and skip the details calls and the note when the flag is off. - Required
projectSlug: it now gates the whole tool, including listing (noquery), which never calls the details endpoint, and org-wide matching, which the attributes endpoint handles fine. Agents now have to pick a project before they can discover keys for org-widesearch_traces/search_logsqueries, and attributes that only exist in other projects drop out. Since the slow part is only the details fan-out, keepprojectSlugoptional and fetch details only when a project is set. That also keepsSearchAttributesParams.projectSlug: string | nulland theif (params.projectSlug)branch insearch.tsmeaningful; right now both are dead. - Wrapper layers:
fetchAttributeDetailsin the newutils.tsandfetchSingleAttributeDetailsinsearch.tsboth just forward toapiService.getTraceItemAttributeDetails. Call the client method directly inside themapand droputils.ts.
Also worth knowing: each details request re-lists every attribute across spans, logs, and tracemetrics server-side before computing stats. Running ~10 of them in parallel per search is heavy even with a project set, so it's worth keeping an eye on latency once this is live.
via Nikki Kapadia.
Dismissed at the author's request; the feedback stands as comments only.
JoshuaKGoldberg
left a comment
There was a problem hiding this comment.
Love it! There's a bug I think is blocked, and some smaller ones. But the overall architecture/strategy looks very solid to me.
Note: I'm trying out a new adversarial review skill that posts a bunch of comments. I deleted ones that I didn't think were really worth it*. I think the rest are ones I like. But LMK what you think, I definitely don't want to be too nitpicky!
*I typed that, and then got paranoid I said that phrase because Claude tends to say it... but I couldn't think of a better fit.
| const hasAttributeDetailsFlag = await hasAttributeDetailsFeature( | ||
| apiService, | ||
| organizationSlug, | ||
| ); |
There was a problem hiding this comment.
[Performance] We fetch this even if projectId !== undefined && matchedAttributes.length > 0. That's an extra network request that might not get used. Then hasAttributeDetailsFlag is only used later on after the attributeDetailsEnabled check once in the file, if projectId === undefined.
Do you think it might be worth it to set up some kind of small lazy getter? Like a ...
let attributesDetailedEnabled: boolean | undefined;
const getAttributesDetailedEnabled = async () => {
attributesDetailedEnabled ??= await stuff();
};...? I don't see precedent for this elsewhere but it might be nice to speed things up?
My intuition is no, this isn't worth it for a since request to a short-lived feature flag. But just putting it out there as something we might want to suggest if we end up seeing this pattern a lot.
| // Details only add to a match, so the requests run in parallel and a failed | ||
| // one leaves just its match without them. Each returns whether it got a 404. | ||
| const attributeDetailsNotFound = await Promise.all( | ||
| attributesToGetDetailsFor.map(async (attribute) => { |
There was a problem hiding this comment.
[Bug] If there are hundreds of requests this will spam the server and get rate limited. A couple of strategy thoughts:
- Maybe we could have a multi-attribute-detail endpoint? One that takes a list of them and returns an array of results? This would be my preference.
- Aside: I know GraphQL is no longer in vogue but whoo is it good for this kind of "same data store, different API needs" use case...
- If that's not doable (why? 😢) we probably want some kind of throttled queue
I think this is blocking, but lmk if I'm misinterpreting please!
| const apiNotes = attributeDetailsNotFound.some(Boolean) | ||
| ? ["Some additional attribute details are unavailable."] | ||
| : []; | ||
| // The details need a project, so say how to get them. |
There was a problem hiding this comment.
[Docs] Nit: I think this is indicated nicely by the code?
| // The details need a project, so say how to get them. |
| return { | ||
| ...attributeDetails, | ||
| ...attribute, | ||
| ...(attributeDetails?.context && { context: attributeDetails.context }), |
There was a problem hiding this comment.
[Bug] The details endpoint merges context across spans, logs, and tracemetrics, and keeps whichever has the highest precedence (merge_attributes_across_datasets in Sentry). So this can replace the searched dataset's description, examples, and deprecation with another dataset's.
The list call's context is already scoped to the dataset we searched, so I think we should keep that one and only take changelog, lastSeen, and datasets from the details.
| }, | ||
| }); | ||
| } | ||
| return error instanceof ApiNotFoundError; |
There was a problem hiding this comment.
[Bug] Only a 404 adds the "Some additional attribute details are unavailable." note. A 5xx, 429, 403, or parse error leaves lastSeen: null with no note, which reads as "not seen in the period" rather than "unknown".
Could we add the note for any failed request? Naming the affected keys in it would help the agent too.
| const result = await searchAttributes.handler( | ||
| z.object(searchAttributes.inputSchema).parse({ | ||
| organizationSlug: FIXTURES.organizationSlug, | ||
| projectSlug: FIXTURES.projectSlug, |
There was a problem hiding this comment.
[Testing] Every eval passes projectSlug now, so none of them covers the default call without a project. As I understand it that's an important agent use case. Maybe keep at least one without it?
| replacementAttribute: z.string().optional(), | ||
| details: z.array(z.string()).optional(), | ||
| isInOtel: z.boolean().optional(), | ||
| unit: z.string().optional(), |
There was a problem hiding this comment.
[Cleanup] Nit: nothing reads context.unit. Can we drop it?
| ...(modifiedCount !== undefined && { modifiedCount }), | ||
| })); | ||
|
|
||
| export const TraceItemAttributeChangelogEntrySchema = z |
There was a problem hiding this comment.
[Cleanup] Nit: nothing outside client.ts uses this export.
| attributeSource: TraceItemAttributeSource; | ||
| projectId?: string | undefined; | ||
| statsPeriod?: string | undefined; | ||
| start?: string | undefined; |
There was a problem hiding this comment.
[Cleanup] Nit: nothing passes start or end. Can we drop them for now?
| * | ||
| * @param params Query parameters | ||
| * @param params.organizationSlug Organization identifier | ||
| * @param attributeName Name of the attribute to query for |
There was a problem hiding this comment.
[Docs] These don't match the signature: they're missing the params. prefix, and params.attributeSource isn't listed. I think the one non-obvious bit is that attributeName is the attribute's name, not its key. Maybe keep just that?
This isn't at the level of https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/informative-docs.md but, that kind of spirit.
This PR integrates the attributes detail endpoint into the
search_attributestool call. Once the endpoint finds the matches, the attributes detail endpoint will be called for each of them and the additional info we get from that endpoint will be attached onto the attribute. This way when the user get's the matches back they get shown this data as well.To make this happen there are a few things that have changed; I've adjusted the output schema and i've made project required to call the attribute details endpoint. This is how the attribute details work in the UI so i'd thought i'd reflect the same in the MCP. Also calling the attribute details endpoint on all projects hangs and takes the call forever to finish.
In addition, i've added the api caller function, new mocks, and updated the eval file.
Contributes to EXP-1349