Logs
You can useconsole.log(), console.error(), and other console methods as normal — they will appear in your run log. Any logs emitted by packages your task calls are also captured.
Using the logger object
We recommend using the logger export from @trigger.dev/sdk. It creates structured logs that include key-value metadata, making it easy to search and filter runs.
/trigger/logging-example.ts
Log levels
| Method | Level | Use case |
|---|---|---|
logger.debug() | DEBUG | Verbose diagnostic info, hidden by default |
logger.log() | LOG | General log messages |
logger.info() | INFO | Informational messages about task progress |
logger.warn() | WARN | Non-fatal issues that should be reviewed |
logger.error() | ERROR | Errors that affect task execution |
Tracing and spans
Trigger.dev uses OpenTelemetry tracing under the hood. Automatic tracing is provided for:| Name | Description |
|---|---|
| Task triggers | When a task is triggered |
| Task attempts | Each attempt of a task run |
| HTTP requests | Outgoing HTTP requests made by your code |
Adding instrumentations
You can add instrumentations in yourtrigger.config.ts. For example, the Prisma instrumentation automatically traces all Prisma queries.
Custom traces
Uselogger.trace() to create a custom OpenTelemetry span around any block of code. You can set attributes on the span and return a value from the callback.
/trigger/custom-trace.ts
Metrics
Trigger.dev collects system and runtime metrics automatically for deployed tasks, and provides an API for recording custom metrics using OpenTelemetry. You can view metrics in query them with TRQL, and export them to external services via telemetry exporters.Custom metrics API
Importotel from @trigger.dev/sdk and use the standard OpenTelemetry Metrics API. Create instruments at module level — outside the run function — so they are reused across runs.
/trigger/metrics.ts
Available instrument types
| Instrument | Method | Use case |
|---|---|---|
| Counter | meter.createCounter() | Monotonically increasing values (items processed, requests sent) |
| Histogram | meter.createHistogram() | Distributions of values (durations, sizes) |
| UpDownCounter | meter.createUpDownCounter() | Values that go up and down (queue depth, active connections) |
Automatic system and runtime metrics
Trigger.dev automatically collects the following metrics for deployed tasks. No configuration is needed. Requires SDK version 4.4.1 or later.| Metric name | Type | Unit | Description |
|---|---|---|---|
process.cpu.utilization | gauge | ratio | Process CPU usage (0–1) |
process.cpu.time | counter | seconds | CPU time consumed |
process.memory.usage | gauge | bytes | Process memory usage |
nodejs.event_loop.utilization | gauge | ratio | Event loop utilization (0–1) |
nodejs.event_loop.delay.p95 | gauge | seconds | Event loop delay p95 |
nodejs.event_loop.delay.max | gauge | seconds | Event loop delay max |
nodejs.heap.used | gauge | bytes | V8 heap used |
nodejs.heap.total | gauge | bytes | V8 heap total |
In dev mode (
trigger dev), only process.* and custom metrics are available.Context attributes
All metrics (both automatic and custom) are tagged with run context so you can filter and group them:run_id— the run that produced the metrictask_identifier— the task slugattempt_number— the attempt numbermachine_name— the machine preset (e.g.,small-1x)worker_version— the deployed worker versionenvironment_type—PRODUCTION,STAGING,DEVELOPMENT, orPREVIEW
Querying metrics
Use TRQL to query metrics data. For example, to see average CPU utilization over time:metrics table schema.
Exporting metrics
You can send metrics to external observability services (Axiom, Honeycomb, Datadog, etc.) by configuring telemetry exporters in yourtrigger.config.ts.