Options
| Option | Type | Default | Description |
|---|---|---|---|
api_key | str | required | Your TruLayer API key (tl_...) |
project | str | required | Project identifier — any string; created on first use |
environment | str | "production" | Free-form label; filter in the dashboard |
endpoint | str | https://api.trulayer.ai | Override for self-hosted or private deployments |
batch_size | int | 50 | Flush when this many spans are buffered |
flush_interval | float | 2.0 | Flush after this many seconds, whichever comes first |
timeout | float | 5.0 | HTTP request timeout in seconds |
sample_rate | float | 1.0 | Fraction of traces to send (0.0 – 1.0) |
scrub_fn | Callable[[Any], Any] | None | None | Run every input/output through this function before ingest |
metadata_validator | Callable[[dict], bool] | None | None | Return False to reject malformed metadata |
debug | bool | False | Log trace payloads locally instead of (or in addition to) sending |
Example — production
Example — local/offline
For CI, local development without network to the TruLayer backend, or sandboxed tests:Sampling
sample_rate=0.1 means 10% of traces are sent. Sampling is applied per trace (not per span), so a sampled trace always contains all of its spans.
For deterministic sampling (same trace always in or out based on its ID), use the SDK’s default hash-based sampler. For random sampling, pass a callable: