Native Agent spans: opt-in way to drop or redact `cloudflare.agents.session.name` (the Durable Object name)
Hi, and thanks for the tracing work. Context: we build a library for agents that handle sensitive conversations, so we look closely at what leaves the Worker in traces.
Observation. The native span attributes added with the identity block (PR #1978) include the Durable Object instance name as cloudflare.agents.session.name, and the AI spans carry it as gen_ai.agent.id. When the instance name is itself personal data (e.g. a phone number or email used as the object name), every trace contains it. The tracing docs warn that "Message and tool payloads can contain personally identifiable information" and describe storeMessages / storeTools, but nothing covers the identity attributes. I could not find an existing issue on this.
Evidence (all [email protected], @cloudflare/[email protected]; function names, since bundle line numbers change per release)
- READ:
agentSpanAttributes(input)returns a fixed record that includes"cloudflare.agents.session.name": input.sessionName. - READ:
Agent._withAgentSpansetsagentId = this.name(in a try/catch), passes it assessionName, spreads the caller'sattributesafter it, then callstracer.withSpan(...). No option or overridable method sits betweenthis.nameand the span. - READ: Think's
_turnTelemetryV7buildsruntimeContext = { agentId: this.name, conversationId, ...metadata };observability/aireadsagentIdfrom runtime context intogen_ai.agent.id. - READ: in
observability/ai,isExcludedFromContexthonours an explicitincludeRuntimeContext: { agentId: false }(the comment says identity is read "without an opt-in", but an explicitfalseis honoured), andsemanticContextthen leavesagentIdundefined. So the AI-span attribute can be dropped today. Not RUN, only read. - NOT FOUND: an equivalent for the native
cloudflare.agents.session.nameattribute.
Repro (synthetic; the behaviour above is READ, not RUN)
export class Chat extends Agent {}
const stub = await getAgentByName(env.Chat, "+15550100");
await stub.fetch(request);
// native spans (agent_start, restore_agent_state, ...) carry
// cloudflare.agents.session.name = "+15550100"
Options (any would help; defaults unchanged):
- An overridable method on
Agent, e.g.spanAttributes(attributes), applied in_withAgentSpanafter the merge, returning the attributes to emit. - An allow-list (e.g.
static spanAttributeAllowList). - If you prefer not to add API: documenting that the instance name is exported as an attribute, and that
includeRuntimeContext: { agentId: false }covers only the AI spans.
Related: the sub-agent naming issue, https://github.com/cloudflare/agents/issues/2791. Happy to adjust the shape to whatever fits the tracing design.
Thanks for the detailed report. I triaged it and confirmed that agentSpanAttributes in packages/agents/src/observability/agent-span-attributes.ts emits the instance name as cloudflare.agents.session.name.
Decision: Only apps that put personal data in the Durable Object name are affected, and they can avoid it by using an opaque name. A new public span-attribute hook would be API we maintain for that narrow case, so I'm closing this as not planned. A maintainer can reopen it if more evidence shows up.