Skip to main content
beforeSend is the last thing that runs before an event enters the batch queue. It sees the event after capture gating and redaction, so by the time it fires the shape is final.

Signature

  • Return the event (unchanged or mutated) to keep it.
  • Return null to drop it entirely — it never hits the queue, never hits the network.
  • Throw — the exception is routed through onError; the event is dropped. A bad hook can never break the contract flow.

beforeSend vs redact.custom

Both give you a final say, but at different granularity: Use them together. Redaction scrubs values; beforeSend makes event-level decisions.

Recipes

Drop noisy contracts

Enrich with a trace ID

Hash the raw output before it leaves

Hashing gives you correlation without exposing content — two runs that produced the same completion are visible as duplicates, but neither the prompt nor the answer leaves your process.

Rate-limit events per contract

Errors inside beforeSend

If your hook throws, the event is dropped and onError fires with the thrown value. The contract that produced the event is unaffected — the hook runs on a separate async path.

See also

Redaction

Per-leaf scrubbing

Capture policy

Strip whole buckets before beforeSend sees the event