Skip to content

perf(agent-sessions): project the span read down to the keys the mapper reads - #739

Open
JeremyFunk wants to merge 2 commits into
mainfrom
feat/agent-sessions-lean-span-projection
Open

perf(agent-sessions): project the span read down to the keys the mapper reads#739
JeremyFunk wants to merge 2 commits into
mainfrom
feat/agent-sessions-lean-span-projection

Conversation

@JeremyFunk

@JeremyFunk JeremyFunk commented Sep 2, 2026

Copy link
Copy Markdown
Collaborator

Why

The Agent Sessions spans read selected the whole SpanAttributes and ResourceAttributes maps per span and then mapped a fixed set of keys server-side. On the largest sessions in the warehouse the resource map alone was ~60% of the raw response and a single unrelated key (db.query.text) was half of the rest. The mapper never read either, so the byte ceiling on the read was measuring bytes that never reached the client.

What

  • spanProjection projects SpanAttributes through mapFilter to aiSpanAttributeKeys — the union of every integration's source keys, the maple_ai.* envelope, and the keys refine hooks read (now declared on the integration as refineKeys) — plus the gen_ai.prompt.variable.* family. ResourceAttributes is no longer selected.
  • mapFilterKeys added to @maple-dev/clickhouse-builder: mapFilter((k, v) -> <predicate>, map) with the key predicate written in DSL conditions.
  • Row schema, output type, fixtures and the SQL baseline follow. The two mapper tests that asserted resource-level keys are ignored are gone with the column.

Verification

  • clickhouse-builder, query-engine-integrations (AI + catalog/baseline) and apps/api route tests green.
  • CLICKHOUSE_E2E=1 SQL catalog sweep against a local ClickHouse: 253 shapes pass.
  • Scoped typecheck green.

🤖 Generated with Claude Code


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

…er reads

The session spans read selected `SpanAttributes` and `ResourceAttributes`
whole, then `mapAiSpan` read a fixed list of keys off the first and nothing
off the second. Measured on the largest production sessions, the resource
map was ~60% of the raw bytes and one unrelated key (`db.query.text`) was
half of what remained — none of it reached the wire.

`spanProjection` now filters the span map to `aiSpanAttributeKeys` — every
source key of every integration plus what the refine hooks read, declared
next to the hook as `refineKeys` — and the prompt-variable prefix, and drops
the resource map. The byte cap on the read now measures what actually ships.

`mapFilterKeys` is the builder primitive: `mapFilter((k, v) -> …)` with the
key predicate written in the DSL's own conditions.
…ean-span-projection

# Conflicts:
#	packages/query-engine-integrations/src/ai/ai-sessions.ts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant