Logs
In addition to host-level logging, wasmCloud supports log exports using the OpenTelemetry (OTEL) specification.
For more information on wasmCloud's implementation of OpenTelemetry, including advanced configuration options, see Observability with OpenTelemetry.
Configuration
By default, wasmCloud hosts write info
level logs to stderr
in plaintext.
To enable all OTEL signals, including logs, use the WASMCLOUD_OBSERVABILITY_ENABLED
environment variable:
WASMCLOUD_OBSERVABILITY_ENABLED="true"
To enable only logs, use the WASMCLOUD_LOGS_ENABLED
environment variable:
WASMCLOUD_LOGS_ENABLED="true"
Enabling OTEL signals automatically structures logs for OTEL export. (In this case, local stderr
logs remain plaintext.)
wasmCloud hosts export structured logs via HTTP/OpenTelemetry Protocol (otlp
) on port 4318.
The endpoint for exports may be overwritten with the OTEL_EXPORTER_OTLP_ENDPOINT
environment variable:
OTEL_EXPORTER_OTLP_ENDPOINT=http://my-custom-host:4318
See the host config options for equivalent host configuration CLI flags.
Log levels
The wasmCloud host supports the following log levels:
error
warn
info
(default)debug
trace
To override the log level, use the --log-level
host config argument.
Take care when enabling trace
or debug
level logs in a production environment. These log levels may contain sensitive information.
Structured logs
In a production environment, it's more common to emit logs in a structured format and aggregate logs from all hosts in a centralized location. Enabling OTEL signals automatically structures JSON logs for OTEL export, while local stderr
logs remain plaintext.
To enable structured log output without enabling OTEL signals, use the --enable-structured-logging
host config argument (or set the WASMCLOUD_STRUCTURED_LOGGING_ENABLED
environment variable). This will cause the host to emit logs as JSON, which are suitable for forwarding to a log aggregator.
{
"timestamp": "2024-01-09T17:54:59.113161Z",
"level": "INFO",
"fields": {
"message": "wasmCloud host started",
"host_id": "NDBYMWNPI3GSXBNM6H4WG6JTVB7K42KQWPOPICMIBVUXQL36ISJZHK4D"
},
"target": "wasmcloud_host::wasmbus"
}
Viewing logs with Grafana and Loki
A set of sample configurations and Docker Compose files are available to help launch a local observability environment. After following the instructions to launch a wasmCloud observability ecosystem, you can navigate to http://localhost:5050/explore, click the dropdown in the upper left, and select "Loki" to view logs.
Refer to the environment variables in the Docker Compose file for a complete example configuration. The example uses Grafana and Loki, but wasmCloud works with any OTEL-compatible backend.