On this page
monitoring
Observability
Executes side-effect callbacks on success or failure without modifying the result or error.
Observability
Observability decorators let you inspect function execution without changing its result. Use them for logging, metrics, audit trails, and debugging.
tap
What it is
Executes side-effect callbacks on success or failure without modifying the result or error.
When to use it
- Logging
- Metrics emission
- Debugging
- Analytics tracking
Async / sync support
Func<R> | Func1<T, R> | Func2<T1, T2, R> | FuncSync<R> |
|---|---|---|---|
| ✅ | ✅ | ✅ | ❌ |
API reference
| |
Examples
Minimal
| |
Real world
| |
Best practices
- Keep tap callbacks fast; they run on the critical path.
- Do not throw inside
onValueoronError; useauditorcatchErrorfor that.
Common pitfalls
tapdoes not catch errors; ifonErrorthrows, that exception propagates.- Slow callbacks increase latency.
monitorObservability
What it is
Collects execution metrics: count, errors, durations, success rate.
When to use it
- Health checks
- Performance monitoring
- SLO dashboards
Async / sync support
Func<R> | Func1<T, R> | Func2<T1, T2, R> | FuncSync<R> |
|---|---|---|---|
| ✅ | ✅ | ✅ | ❌ |
API reference
| |
Methods:
Metrics getMetrics()— returns a snapshot.void resetMetrics()— resets counters.
Metrics fields:
executionCounterrorCounttotalDurationlastDurationlastErrorlastExecutionTimeaverageDurationsuccessRate
Examples
Minimal
| |
Real world
| |
Best practices
- Export metrics to your monitoring system periodically.
- Reset metrics when deploying a new version to get per-version stats.
Common pitfalls
- Public API name is
monitorObservability()to avoid clashing with the concurrencymonitordecorator. - Metrics are kept in memory; they are lost when the process restarts.
audit
What it is
Records detailed per-execution logs including arguments, result, error, stack trace, and duration.
When to use it
- Compliance logging
- Security audit trails
- Debugging complex failures
Async / sync support
Func<R> | Func1<T, R> | Func2<T1, T2, R> | FuncSync<R> |
|---|---|---|---|
| ❌ | ✅ | ✅ | ❌ |
API reference
| |
For Func2:
| |
Methods:
List<AuditLog<T, R>> getLogs()List<AuditLog<T, R>> getSuccessLogs()List<AuditLog<T, R>> getFailureLogs()void clearLogs()
Examples
Minimal
| |
Real world
| |
Best practices
- Set
maxLogsbased on expected call volume and memory budget. - Use
onAuditto ship logs to a durable store.
Common pitfalls
auditis only available onFunc1andFunc2(the extension classes are hidden from public API but exposed via the decorator method).- Errors in
onAuditare caught and ignored so they do not affect the wrapped function.