Privacy-Safe Agent Observability
Traces are a data store. Record metadata by default, keep prompt and tool content out of spans, and put any captured content in a separate store with scoped readers and short retention.
- Topics
- Secure AI Agents
- Level
- Founder / builder
- Read
- 4 min
- Published
- 2026-11-12
- Reviewed
- 2026-11-12
The problem
Amazon Bedrock's model invocation logging, as documented in November 2026, is off by default. Once a team switches it on, it collects the full request data, response data and metadata for supported calls, keeps request and response bodies of up to 100 KB inline, and stores the logs "until the logging configuration is deleted" [1]. A team can buy a zero-retention model contract and then rebuild a complete prompt archive in its own account with one setting.
The same pattern runs through every observability stack. Tracing libraries, agent frameworks and LLM monitoring tools make it easy to record every prompt, retrieved document and tool response, because that is what engineers want during a bad week. The trace store then holds the most sensitive data in the system, with the weakest access controls and the longest retention.
IBM's 2025 data shows what that exposure looks like when it fails. One in five organizations reported a breach involving shadow AI, and those incidents compromised personal data in 65% of cases against a 53% average [2]. An illustrative case: an incident team debugs a failed support flow and finds raw customer IDs and live authentication tokens in a third-party tracing vendor's logs. The debugging worked. The privacy boundary did not.
How it works
Split content from metadata at the moment of ingestion, before anything is exported.
- Agent trace. Spans for each model call, retrieval and tool execution, joined by a trace ID.
- Redact at ingestion. Secrets, account IDs and tokens are removed or hashed in process, before the exporter runs.
- Metadata, team readers. Trace ID, tool name, latency, error code, token counts, cost and a decision receipt (which policy allowed or denied an action). This is enough for most debugging.
- Sensitive content, scoped readers. Prompts, outputs and tool payloads are captured only when explicitly enabled, sampled, written to a separate store with its own retention, and every export is audited.
The OpenTelemetry GenAI semantic conventions, still marked Development, encode the same split [3]. Content attributes such as gen_ai.input.messages, gen_ai.output.messages and gen_ai.tool.call.arguments are opt-in. The spec states that instrumentations "SHOULD NOT capture them by default". For production it recommends storing content externally and recording only a reference on the span, such as gen_ai.input.messages_ref, so the content store can have separate access controls [3].
Provider logs sit outside your control but inside your threat model. OpenAI keeps API abuse-monitoring logs for up to 30 days unless a zero-retention arrangement applies [4]. Your own trace store sits fully inside your control, which makes it the easier boundary to fix. NIST SP 800-53 already names the controls: protect audit information from unauthorized access (AU-9) and set audit record retention (AU-11) [5]. OWASP lists sensitive information disclosure second among LLM application risks [6].
Split content from metadata at ingestion
Fig. 19- Agent trace
- Redact at ingestionSecrets, IDs, tokens
Trace ID, tool name, latency, error code, cost, decision receipt
Selectively sampled, retention-limited, export access audited
Technical detail
Run automated secret and PII scans on trace output, attempt unauthorized log retrieval, and keep secure evidence for legitimate investigations.
By the numbers
- request and response body kept inline per Bedrock invocation log entry [1]
- 100 KB
- of shadow AI incidents compromised personal data, against a 53% average [2]
- 65%
- organizations reported a breach involving shadow AI in 2025 [2]
- 1 in 5
- content attributes the OpenTelemetry GenAI spec gates behind explicit opt-in [3]
- 9
- default retention of OpenAI API abuse-monitoring logs [4]
- 30 days
| Field | Class | Readers | Retention |
|---|---|---|---|
| Trace ID, span ID, correlation ID | Metadata | Engineering team | 30 to 90 days |
| Model, operation name, token counts, latency, cost | Metadata | Engineering team | 30 to 90 days |
| Tool name, error type, policy decision | Metadata | Engineering and security | 90 days or audit period |
| Prompts, outputs, system instructions | Content | Named on-call, ticket required | 7 days, sampled |
| Tool arguments and results | Content | Named on-call, ticket required | 7 days, sampled |
| Secrets, tokens, account numbers | Never stored | Nobody | None |
The retention periods are illustrative defaults, not figures from the sources. Pick yours, write them down, and make the trace backend enforce them. The 100 KB inline limit means a Bedrock log entry holds a full page of a typical contract, and the 30-day provider window means deleting a chat in your app does not clear the provider's copy.
Implementation
Record metadata on the span. Write content, when it is enabled, to a separate store and keep only a reference. Redact before either write.
import os, re, hashlib, uuid
from opentelemetry import trace
tracer = trace.get_tracer("assistant")
CAPTURE = os.getenv("GENAI_CAPTURE_CONTENT") == "sampled" # off unless explicitly enabled
SECRET = re.compile(r"(sk-[A-Za-z0-9]{20,}|AKIA[0-9A-Z]{16}|Bearer\s+\S+|\b\d{12,19}\b)")
def redact(text: str) -> str:
# Replace secrets and long digit runs with a stable hash so incidents can still be correlated.
return SECRET.sub(lambda m: "red:" + hashlib.sha256(m.group().encode()).hexdigest()[:12], text)
def call_model(client, content_store, model: str, messages: list[dict], tenant: str):
with tracer.start_as_current_span(f"chat {model}") as span:
span.set_attribute("gen_ai.operation.name", "chat")
span.set_attribute("gen_ai.request.model", model)
span.set_attribute("app.tenant_hash", hashlib.sha256(tenant.encode()).hexdigest()[:16])
resp = client.chat(model=model, messages=messages)
span.set_attribute("gen_ai.usage.input_tokens", resp.usage.input_tokens)
span.set_attribute("gen_ai.usage.output_tokens", resp.usage.output_tokens)
if CAPTURE and content_store.should_sample(tenant):
ref = content_store.put( # separate bucket, own KMS key, 7-day lifecycle
key=f"{tenant}/{uuid.uuid4()}.json",
body={"input": [redact(m["content"]) for m in messages],
"output": redact(resp.text)})
span.set_attribute("gen_ai.input.messages_ref", ref)
return respThe client and content_store objects are your own wrappers. Two rules make the pattern hold. Content capture is a deployment flag that defaults to off, so a debug setting cannot leak into production by accident. And the content store is a different system from the trace backend, with its own key, its own reader group and a lifecycle rule that deletes objects on schedule. If you use Bedrock invocation logging, treat its bucket or log group as a content store and give it the same lifecycle and reader rules [1].
Test it
Plant a canary secret in a prompt and a tool result, run the flow, and scan every exported span. The OpenTelemetry SDK's in-memory exporter makes this a unit test.
from opentelemetry import trace
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import SimpleSpanProcessor
from opentelemetry.sdk.trace.export.in_memory_span_exporter import InMemorySpanExporter
import traced_call
CANARY_KEY = "sk-" + "CANARYcanary0123456789abcd"
CANARY_CARD = "4111111111111111"
exporter = InMemorySpanExporter()
provider = TracerProvider()
provider.add_span_processor(SimpleSpanProcessor(exporter))
trace.set_tracer_provider(provider)
traced_call.tracer = trace.get_tracer("assistant")
def test_no_secret_or_content_in_spans(fake_client, fake_store):
msgs = [{"role": "user", "content": f"Use key {CANARY_KEY} and card {CANARY_CARD}"}]
traced_call.call_model(fake_client, fake_store, "model-x", msgs, tenant="acme")
for span in exporter.get_finished_spans():
dump = repr(dict(span.attributes))
assert CANARY_KEY not in dump and CANARY_CARD not in dump
assert "gen_ai.input.messages" not in span.attributes # content never inline
def test_content_store_is_redacted(fake_client, fake_store, monkeypatch):
monkeypatch.setattr(traced_call, "CAPTURE", True)
msgs = [{"role": "user", "content": f"key {CANARY_KEY}"}]
traced_call.call_model(fake_client, fake_store, "model-x", msgs, tenant="acme")
assert all(CANARY_KEY not in repr(obj) for obj in fake_store.objects.values())Expected result: both tests pass, and the canary appears nowhere in spans or stored content. Extend the run in staging:
- A request for a content object from an engineer outside the reader group returns 403 and writes an audit event.
- Objects in the content store expire on the documented schedule. Check one after the window.
- The same canary string searched in the tracing vendor's UI and in provider-side logs you can query returns nothing.
- Turning capture on requires a change ticket, and the flag change itself is logged.
Decision
Treat the trace backend as a data processor with the same review as any vendor that stores customer data. Do it before the first production incident, because that is when someone will turn on full capture.
- Default: metadata only. Trace IDs, model, tokens, latency, errors, policy decisions.
- When content is needed: sampled capture to a separate store, redacted in process, short lifecycle, named readers, audited exports.
- For provider logs: list them by name with their documented windows, and include your own Bedrock or gateway logs in that list.
- Never: secrets, tokens or full account numbers in any log.
The cost is a redaction function, a second bucket and a reader group. Debugging gets slightly slower for rare cases and much safer for all of them.
Sources
- [1]Monitor model invocation using CloudWatch Logs and Amazon S3 (opens in a new tab)AWS, November 2026
- [2]IBM Report: 13% of Organizations Reported Breaches of AI Models or Applications, 97% of Which Reported Lacking Proper AI Access Controls (opens in a new tab)IBM Newsroom, July 2025
- [3]Semantic conventions for generative client AI spans (opens in a new tab)OpenTelemetry, November 2026
- [4]Data controls in the OpenAI platform (opens in a new tab)OpenAI, November 2026
- [5]SP 800-53 Rev. 5, Security and Privacy Controls for Information Systems and Organizations (opens in a new tab)NIST, December 2020
- [6]LLM02:2025 Sensitive Information Disclosure (opens in a new tab)OWASP GenAI Security Project, November 2024
Technical guidance, not security certification or legal advice.
