Skip to content

Forward AI agent session/trace id into Cloud API request headers #267

@sdairs

Description

@sdairs

What

Propagate the calling AI agent's session id (and trace id when present) into ClickHouse Cloud API request headers, so backend telemetry can correlate every clickhousectl call made within a single agent session/conversation.

Why

We already detect the agent and tag the User-Agent (agent=claude-code) via is-ai-agent. The new is-ai-agent v0.4.0 adds Agent::session_id and Agent::traceparent / Agent::trace_id(), exposing the per-session identifier the agent publishes to its subprocesses (e.g. CLAUDE_CODE_SESSION_ID). Forwarding this lets the backend group calls by agent run — e.g. see how a single Claude Code session's requests correlate.

How (sketch — impl details for the implementing agent)

  • Bump is-ai-agent 0.2.10.4.0 in crates/clickhousectl/Cargo.toml.
  • In CloudClient::new() (crates/clickhousectl/src/cloud/client.rs), attach the ids as default headers on the reqwest client we build. Both the management API and SQL query paths reuse that self.http, so default headers cover everything — no clickhouse-cloud-api library changes needed.
  • Header names the backend looks for:
    • agent-session-idAgent::session_id
    • traceparentAgent::traceparent (raw W3C value)
  • Guard header values with HeaderValue::from_str(..).ok() (session ids are opaque vendor strings).
  • Tests: a pure-logic header-builder unit test (inject a fake Agent), optionally extend tests/cli_request_shape_test.rs to assert headers land on the wire.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type
No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions