Skip to content

feat(sdk): add DECO_OTEL_ACCESS_LOG_RATE sampling for INFO access logs#293

Open
igoramf wants to merge 1 commit into
mainfrom
feat/access-log-sampling
Open

feat(sdk): add DECO_OTEL_ACCESS_LOG_RATE sampling for INFO access logs#293
igoramf wants to merge 1 commit into
mainfrom
feat/access-log-sampling

Conversation

@igoramf

@igoramf igoramf commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Adds DECO_OTEL_ACCESS_LOG_RATE env var (float 0–1, default 1.0 = 100% = current behavior) to control INFO access log volume
  • 5xx requests always emit an ERROR-level access log regardless of the rate — errors are never sampled
  • Sampling uses FNV-1a 32-bit hash of requestId/traceId for consistent per-request decisions (same request always gets the same pass/drop outcome)
  • Falls back to Math.random() only when no request ID is available

Why

logRequest() emits 1 INFO log per HTTP request. casaevideo + bagaggio alone generate ~2,200 INFO access logs/minute at otel-ingest, even though 99% are discarded after arrival. Moving the sampling decision to the SDK (before the POST) reduces otel-ingest load and billing.

Recommended prod config:

DECO_OTEL_ACCESS_LOG_RATE=0.1   # sample 10% of INFO access logs; 5xx always logged

Test plan

  • Default (DECO_OTEL_ACCESS_LOG_RATE unset): 100% of access logs emitted — same as before
  • DECO_OTEL_ACCESS_LOG_RATE=0: 0 INFO access logs; 5xx still emit ERROR log
  • DECO_OTEL_ACCESS_LOG_RATE=0.1: ~10% of INFO access logs pass; 5xx always pass
  • FNV-1a consistency: same requestId always gets same pass/drop decision

🤖 Generated with Claude Code


Summary by cubic

Adds DECO_OTEL_ACCESS_LOG_RATE to sample INFO access logs and reduce otel-ingest volume. Default remains 100% (no behavior change).

  • New Features

    • Sample INFO access logs via DECO_OTEL_ACCESS_LOG_RATE (0–1; default 1.0).
    • 5xx requests always log at ERROR level (never sampled).
    • Deterministic per-request sampling using FNV-1a hash of requestId/traceId; falls back to Math.random() if missing.
  • Migration

    • Set DECO_OTEL_ACCESS_LOG_RATE=0.1 in production to keep ~10% of INFO logs.

Written for commit 2bcc74b. Summary will update on new commits.

Review in cubic

5xx requests always emit an ERROR-level access log (never sampled). INFO
access logs (2xx/3xx/4xx) are now gated by DECO_OTEL_ACCESS_LOG_RATE
(float 0–1, default 1.0 = 100% = current behavior).

When the rate is < 1, sampling uses FNV-1a 32-bit hash of requestId/
traceId for consistent per-request decisions — same request always gets
the same answer, regardless of isolate. Falls back to Math.random() only
when neither ID is available (should not happen in practice).

Set DECO_OTEL_ACCESS_LOG_RATE=0.1 to reduce INFO access log volume by
90%, eliminating the main source of high-volume INFO traffic to otel-ingest
without affecting error visibility.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@igoramf igoramf requested a review from a team June 26, 2026 17:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant