feat: add listAttributeKeys telemetry endpoint#1712
Conversation
🦋 Changeset detectedLatest commit: 25e38f1 The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
AGE-1429
… attribute keys for telemetry filtering.
| return { | ||
| queryKey: queryKeyListAttributeKeys({ | ||
| gramKey: request.gramKey, | ||
| gramSession: request.gramSession, | ||
| gramProject: request.gramProject, | ||
| }), |
There was a problem hiding this comment.
🔴 React Query cache key omits from/to body parameters, causing stale data across different time ranges
The queryKeyListAttributeKeys function only includes header parameters (gramKey, gramSession, gramProject) but excludes the request body's from and to time-range fields. This means TanStack Query treats requests with different time ranges as identical, serving stale cached data.
Root Cause and Impact
At client/sdk/src/react-query/listAttributeKeys.core.ts:47-52, the query key is built using only header params:
queryKey: queryKeyListAttributeKeys({
gramKey: request.gramKey,
gramSession: request.gramSession,
gramProject: request.gramProject,
}),The request object also contains getProjectMetricsSummaryPayload (which holds from and to), but these are not included in the cache key at client/sdk/src/react-query/listAttributeKeys.core.ts:77-85.
Scenario:
- Component calls
useListAttributeKeyswithfrom: "2025-01-01",to: "2025-06-01"→ fetches and caches result under key["@gram/client", "telemetry", "listAttributeKeys", {gramProject: "x"}] - User changes time range to
from: "2025-06-01",to: "2025-12-01"→ TanStack Query finds a cache hit on the same key and returns the old result without refetching.
Impact: Users see incorrect/stale attribute keys when changing the time range filter in the UI.
Prompt for agents
In client/sdk/src/react-query/listAttributeKeys.core.ts, the queryKeyListAttributeKeys function at lines 77-85 and the call site at lines 47-52 need to include the request body parameters (from/to) in the cache key. Since the request body is typed as getProjectMetricsSummaryPayload (containing from and to fields), these should be included in the parameters object passed to queryKeyListAttributeKeys. Similarly, update the queryKeyBase type in client/sdk/src/react-query/listAttributeKeys.ts for setListAttributeKeysData and invalidateListAttributeKeys. Note: since this is generated code (Speakeasy), the fix may need to be applied at the OpenAPI spec or Speakeasy configuration level to ensure the code generator includes request body fields in the query key.
Was this helpful? React with 👍 or 👎 to provide feedback.
Summary
POST /rpc/telemetry.listAttributeKeysendpoint that returns all distinct attribute paths fromtelemetry_logsfor a project + time rangeJSONAllPaths()to discover paths, translatesapp.*→@-prefixed user keys, returns system keys bareCloses AGE-1429
Example
Request:
Response:
{ "keys": [ "@error.code", "@order.total", "@user.id", "@user.region", "@user.tier", "gen_ai.conversation.id", "gen_ai.response.model", "gen_ai.usage.input_tokens", "gram.tool.urn", "http.request.method", "http.response.status_code", "http.route", "..." ] }User attributes (
app.*) are returned with@prefix. System attributes are returned bare. Results are sorted alphabetically and deduplicated.Test plan
mise build:serverpassesmise lint:serverpasseslist_attribute_keys_test.gopass