Safeguard
Developer Tools•

Can you sample security logs to cut costs without losing evidence?

Never sample audit and security events; sample high volume noise instead. What OpenTelemetry says about sampling, and a keep, sample, drop table.

Safeguard Security Team
4 min read

Not the events you need as evidence. Keep authentication, authorization, privilege and audit events in full. Sampling suits high volume, repetitive, healthy traffic such as successful health checks or debug traces. Decide per event class, document it, and make sure dropped data cannot be needed for an investigation.

What sampling means

OpenTelemetry defines sampling for traces and spans: a sampled item is processed and exported, and an unsampled one is not. The sampler chooses items that are representative of the whole population, which cuts cost while keeping analysis valid.

Two styles matter. Head sampling decides early, using something like the trace ID and a percentage. It is simple but cannot guarantee that every trace with an error is kept. Tail sampling decides after seeing most of a trace, so it can keep errors, slow requests or specific attributes. It is more powerful and harder to run.

OpenTelemetry's page covers traces. It does not discuss sampling for logs, so treat any log sampling as your own design with its own risks.

It also says not to sample when data volume is low, when you need only aggregates, or when regulations prohibit dropping data. That last point matters for audit trails.

Why security events are different

Representative samples answer questions about averages: how slow is the service, how often does it error. Security questions are about specific events. Did this account log in from that address on that day? A sample can drop the one line that answers it.

So the rule is to keep every event that could be evidence for one actor.

Keep, sample or drop

Event classTreatment
Authentication successes and failuresKeep all
Authorization failuresKeep all
Privilege, admin, export and configuration changesKeep all, in an audit stream
Application errorsKeep all, deduplicate repeated stack traces
Successful health checks and static asset requestsSample or drop
Routine successful read requestsSample, keep a minimum of metadata
Debug level logsDrop in production, enable per request when needed
Traces of healthy requestsHead sample, with tail rules to keep errors

Deduplication is a safer form of reduction than sampling. See log an error once.

Cheaper ways to save

  1. Cut retention on low value streams while keeping audit streams longer. See retention by data class.
  2. Move older logs to cold storage rather than deleting them.
  3. Drop fields you never query, such as large headers.
  4. Fix chatty loggers that print inside loops.
  5. Route health checks away from the application log.

Steps if you must sample

  1. List event classes and mark which are evidence.
  2. Never sample the evidence classes.
  3. Record the sample rate in the event so you can scale counts correctly.
  4. Add a rule that keeps all events from an actor once a detection fires.
  5. Review the policy when a regulation or customer contract changes.

Quick check

Is it fine to sample successful logins?

Avoid it. Successful logins are the context for investigating a compromised account. Keep them, and manage cost with retention instead.

What is tail sampling good for?

Keeping whole traces that contain errors or slow requests, which head sampling can miss.

Safeguard's SBOM and dependency scanning is unrelated to log volume, but a free scan at gold.safeguard.sh/scan shows what you ship.

Sources

Last reviewed: 19 October 2026.

Never miss an update

Weekly insights on software supply chain security, delivered to your inbox.

Self-healing security runs on Safeguard.

Your first fix PR is minutes away.

No sales call required, even your agent can complete the purchase over MCP.