Prompt
I'm building a startup and need a logging setup that won't explode in cost as volume grows
Latest observation
Here’s a practical logging setup that stays useful without turning into a runaway bill as your startup scales.
Core principle
Don’t treat every log line as equally valuable.
Costs usually explode from:
- too much volume
- too many high-cardinality fields
- retaining everything too long
- shipping raw debug logs to a paid observability platform
So the goal is: small, structured, searchable, sampled by default, and tiered by retention.
Recommended architecture
1) Log locally in structured JSON
Use structured logs from day one.
Include:
- timestamp
- level
- service name
- environment
- request_id / trace_id
- user_id or tenant_id only if needed
- event name
- message
- key business fields
Avoid:
- large blobs
- stack traces in every info log
- full request/response bodies
- high-cardinality tags like raw URLs with query params
Example fields:
{
"ts": "2026-10-28T12:00:00Z",
"level": "info",
"service": "api",
"env": "prod",
"trace_id": "abc123",
"request_id": "req_789",
"event": "checkout_completed",
"user_id": "u_42",
"order_id": "o_99",
"amount": 129.50
}
2) Set aggressive log level defaults
Default production logging should be:
- INFO for normal business events
- WARN for unusual but recoverable issues
- ERROR for failures
- DEBUG only when explicitly enabled and usually only in staging or for short-lived incident windows
A common mistake is leaving debug logs on in production.
3) Sample noisy logs
For high-volume endpoints or repetitive events:
- log every error
- log all warnings
- sample info logs at 1–10%
- for very hot paths, emit only counters/metrics instead of logs
Sampling strategies:
- per request
- per event type
- adaptive sampling during spikes
- always keep logs for failed requests
Example rule:
checkout_completed: sample 10%payment_failed: 100%healthcheck: 0%
4) Split logs into “hot” and “cold”
Use two tiers:
- Hot storage: searchable, recent, expensive
- Cold storage: cheap object storage for long retention
A good pattern:
- 7–14 days in your observability tool
- 30–180 days archived in S3/GCS/Azure Blob
- query archived logs only when needed
This keeps debugging easy without paying premium rates for old data.
5) Keep metrics separate from logs
If something is:
- frequent
- aggregatable
- used for dashboards/alerts
…it should probably be a metric, not a log.
Examples:
- request latency
- error rate
- queue depth
- retry counts
- signup conversions
Use logs for:
- rare events
- rich context
- debugging
- audits
This alone can cut log volume a lot.
Cost-control guardrails
6) Limit payload size
Enforce max log entry size:
- truncate large strings
- drop request/response bodies
- cap stack traces
- redact secrets
A single giant log line can be surprisingly expensive at scale.
7) Redact sensitive data
Do not log:
- passwords
- API keys
- tokens
- full credit card numbers
- raw PII unless absolutely necessary
Use automatic redaction middleware if possible.
8) Use retention by environment
Typical setup:
- dev/staging: short retention, low cost
- prod: medium retention in logging platform
- archive: longer retention in object storage
There’s no reason staging logs should cost anywhere near production logs.
9) Route only important logs to paid SaaS
Not every log must go to Datadog, New Relic, etc.
Possible split:
- application logs → cheap collector + object storage
- critical errors → observability platform
- security/audit logs → separate secure sink
- access logs → sample or aggregate
This is often the biggest savings lever.
A lean startup-friendly setup
If you want simple and cost-conscious:
- App emits JSON logs to stdout
- Container/host agent ships logs
- Use OpenTelemetry or a lightweight log agent
- Send:
- errors and warnings to your observability vendor
- all logs to object storage for archive
- Set log retention in vendor to 7–14 days
- Use metrics for dashboards and alerting
Good stack examples
- Kubernetes: stdout + Fluent Bit + OpenTelemetry Collector + S3 + observability vendor
- AWS: CloudWatch only for short-term, archive to S3, consider Firehose
- Bare metal/VMs: journald/syslog → shipper → storage
Recommended policy
You can adopt a policy like this:
- All production logs must be structured JSON
- No DEBUG in prod by default
- No request/response bodies in logs
- Redaction required for secrets and PII
- Info logs must be sampled in hot paths
- Retention in observability tool: 7–14 days
- Archive all logs to cheap storage for longer retention
- Metrics for anything high-volume and repetitive
What to avoid
- Logging every database query
- Logging every successful request at full detail
- Using logs as your primary analytics system
- Keeping all logs indefinitely in a premium platform
- Allowing unrestricted DEBUG logs in production
- Putting high-cardinality identifiers in every line
A practical default for an early-stage startup
If you want a sensible default today:
- INFO/WARN/ERROR only
- JSON logs
- 10% sampling for routine success events
- 100% for errors
- 7 days in your main log tool
- 90 days in cheap object storage
- Metrics for all high-frequency operational data
- Redaction middleware enabled
If you want, I can also give you:
- a reference architecture for AWS/GCP/Azure,
- a logging policy template for your team, or
- an example setup in Python, Node, Go, or Java.