agents icon indicating copy to clipboard operation
agents copied to clipboard

Native Agent spans: opt-in way to drop or redact `cloudflare.agents.session.name` (the Durable Object name)

Open MRCORD opened this issue 1 month ago • 1 comments

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._withAgentSpan sets agentId = this.name (in a try/catch), passes it as sessionName, spreads the caller's attributes after it, then calls tracer.withSpan(...). No option or overridable method sits between this.name and the span.
  • READ: Think's _turnTelemetryV7 builds runtimeContext = { agentId: this.name, conversationId, ...metadata }; observability/ai reads agentId from runtime context into gen_ai.agent.id.
  • READ: in observability/ai, isExcludedFromContext honours an explicit includeRuntimeContext: { agentId: false } (the comment says identity is read "without an opt-in", but an explicit false is honoured), and semanticContext then leaves agentId undefined. So the AI-span attribute can be dropped today. Not RUN, only read.
  • NOT FOUND: an equivalent for the native cloudflare.agents.session.name attribute.

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):

  1. An overridable method on Agent, e.g. spanAttributes(attributes), applied in _withAgentSpan after the merge, returning the attributes to emit.
  2. An allow-list (e.g. static spanAttributeAllowList).
  3. 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.

MRCORD avatar Nov 02 '26 14:11 MRCORD

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.

github-actions[bot] avatar Nov 03 '26 15:11 github-actions[bot]