Early access: verified fix PRs ·

See how a fix is proven
AutoSRE
Reliability Engineering

Redacting JWTs, Auth Headers, and PII Before Trace Storage and Replay

Learn how to sanitize trace telemetry at ingestion and safely execute production replays in isolated sandboxes without leaking tokens, cookies, or user PII.

AutoSRE Engineering·November 28, 2026·4 min read
Back to all articles

Capturing production traces gives engineering teams high-fidelity visibility into software crashes, race conditions, and unhandled exceptions. Distributed tracing formats like OpenTelemetry (OTel) record comprehensive request contexts: HTTP headers, URL query parameters, database statements, and body attributes.

However, this fidelity poses a severe risk to production security. A single unhandled exception trace can capture raw JSON Web Tokens (JWTs), basic authorization credentials, session cookies, payment information, or personally identifiable information (PII). Storing or passing this data down to automated triage systems and Large Language Models creates a massive compliance and security hazard.

To safely inspect failures and run automated reproductions, teams must implement comprehensive trace scrubbing at ingestion and isolate test executions inside air-gapped sandboxes.

The Anatomy of Sensitive Trace Attributes

When distributed tracing is enabled via standard OpenTelemetry instrumentation, spans capture contextual metadata across multiple protocols and layers. Common vectors where secrets leak include:

  • Transport Headers: http.request.header.authorization, http.request.header.cookie, and http.response.header.set-cookie frequently contain raw session IDs or Bearer tokens.
  • HTTP Payloads: Request bodies serialized into span attributes (e.g., http.request.body) containing customer email addresses, phone numbers, or credit card numbers.
  • Database Spans: Unsanitized SQL statements in db.statement where query literals expose user credentials or identifiers instead of parameterized placeholders.
  • Exception Stack Traces: Local variable values serialized directly into exception events.

Once sensitive data is ingested into trace stores, scrub operations become expensive and error-prone. Sanitization must occur immediately on the ingest stream.

Pattern 1: Deterministic Ingestion-Time Scrubbing

When receiving OpenTelemetry Protocol (OTLP) payloads—such as traces sent to /v1/ingest/otlp/v1/traces—the scrubbing layer must evaluate attributes before persisting them or passing them to inference engines.

Sanitization relies on two complementary mechanisms: automatic heuristic scrubbing and targeted custom rules.

Automatic Secret and PII Scrubbing

A baseline ingestion pipeline should automatically identify and mask canonical token formats:

  • JWT Tokens: Detected by looking for base64url-encoded header and payload segments starting with standard headers (e.g., ey...). The signature and payload should be stripped or masked.
  • Authorization Headers: Any header matching Bearer [A-Za-z0-9-_=.]+ or Basic [A-Za-z0-9+/=]+ replaced with [REDACTED_AUTH_TOKEN].
  • Standard PII Formats: Regex engines evaluating fields for PCI card numbers (Luhn check), email patterns ([a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+), and E.164 phone numbers.

Custom Path and Regex Rules

Standard rules catch universal formats, but internal domain models often use bespoke keys such as x-api-key, sessionSecret, or customer tax identifiers. An ideal ingestion pipeline allows configuring up to 30 custom rules targeting specific JSONPath expressions or key-value pairs.

Consider this simplified payload representation before ingestion:

{ "resourceSpans": [{ "scopeSpans": [{ "spans": [{ "name": "POST /api/v1/checkout", "attributes": [ { "key": "http.request.header.authorization", "value": { "stringValue": "Bearer eyJhbGciOi..." } }, { "key": "user.email", "value": { "stringValue": "dev@example.com" } }, { "key": "app.internal_token", "value": { "stringValue": "sec_live_99a8b1c" } } ] }] }] }] }

Applying deterministic scrubbing updates the attributes before storage:

{ "key": "http.request.header.authorization", "value": { "stringValue": "[REDACTED_BEARER_TOKEN]" }

By executing redaction before signature deduplication and triage, raw secrets never hit secondary analysis pipelines or logs.

Pattern 2: Sanitized Production Replays in Sandboxes

Capturing an error is only the first step. To verify a bug, engineers or automated systems must reproduce the incident using the captured context. However, executing production replays introduces serious operational risks: unredacted tokens could query third-party APIs, trigger external webhooks, or alter real database rows.

To resolve this, reproduction must happen within isolated, ephemeral sandboxes.

Structuring the Replay Configuration

Rather than executing arbitrary traces directly, define an explicit replay configuration, such as .tracefix/replay.json. This configuration maps incoming trace data to isolated test scenarios:

{ "environment": "node18", "setupCommands": [ "npm ci", "npm run build" ], "replayEntrypoint": "tests/repro/trace-case.spec.ts", "mockOverrides": { "AUTH_SERVICE_URL": "http://127.0.0.1:9099", "PAYMENT_GATEWAY_URL": "http://127.0.0.1:9098" } }

Network Isolation Post-Setup

When running a reproduction inside an ephemeral container—such as an Upstash Box sandbox—apply a strict boundary on outbound network access:

  • Phase 1: Environment Provisioning (Network Enabled)

Repository dependencies are cloned and installed via lockfiles (npm ci).

  • Phase 2: Post-Setup Lockdown (Network Disabled)

Before replaying the trace payload, outbound network interfaces are severed or restricted to localhost. External service calls must resolve to synthetic mocks.

Disabling outbound networking ensures that even if a developer or custom rule fails to redact an external credential, that credential cannot be leaked or used against a live production endpoint during replay.

Closing the Loop with Safe Remediation

When trace scrubbing and isolated sandboxes are integrated with automated remediation (such as AutoSRE's triage modes using Google Gemini 2.5 models), the resulting bug fixes can be validated safely:

  • Deterministic Test Generation: Traces are converted into isolated regression tests using sanitized inputs.
  • Flake Verification: Repros are executed with three-time flake checks to ensure failures are reproducible and not environment-dependent.
  • Controlled Code Changes: Suggested fixes are submitted exclusively as draft PRs on feature branches via GitHub App integrations, maintaining high-risk path guards and requiring admin approval without direct merges to main.

By pairing strict ingestion-time PII redaction with offline ephemeral sandbox execution, reliability engineering teams can safely automate failure reproduction without compromising production security.

#Reliability Engineering#PII redaction#trace scrubbing#production security#sandbox
Live Now · Grow into 360° SRE

Start with OTLP trace replay and verified PRs today.

GET EARLY ACCESS