Logging & Tracing
Logging
When building a DBOS app, we recommend using the built-in DBOS logger.
This allows DBOS Cloud to collect and display your logs.
You can access the logger through DBOS.logger
.
DBOS.logger.info("Welcome to DBOS!");
The logger provides four logging levels: info()
, debug()
, warn()
and error()
.
Each accepts and logs any output that can be serialized to JSON.
error()
additionally logs a stack trace.
In your dbos-config.yaml
, you can configure the log level and whether to add metadata such as the workflow ID to logs:
telemetry:
logs:
logLevel: 'info' # info (default) | debug | warn | error
addContextMetadata: 'true' # true (default) | false
You can also configure the logging level from the command line:
npx dbos start --loglevel debug
Tracing
DBOS automatically constructs OpenTelemetry traces of all workflows and their steps.
DBOS constructs hierarchical spans for workflows and each of their steps.
For example, if an HTTP endpoint calls a workflow that calls a transaction, DBOS constructs a trace encompassing the entire request, with spans for the HTTP endpoint, the workflow, and the transaction.
The transaction span is a child of the workflow span, which is a child of the HTTP endpoint span.
You can access your current span via DBOS.span
.
OpenTelemetry Export
You can export DBOS logs and traces to any OpenTelemetry Protocol (OTLP)-compliant receiver. In DBOS Cloud, this is done automatically, and you can view your logs and traces in the cloud console.
Locally, you can configure exporters in your dbos-config.yaml
:
telemetry:
OTLPExporter:
logsEndpoint: http://localhost:4318/v1/logs
tracesEndpoint: http://localhost:4318/v1/traces
For example, try using Jaeger to visualize the traces of your local application.