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.
Enable the wasmCloud host to emit logs as an OTEL signal with the OTEL_TRACES_EXPORTER
environment variable:
OTEL_TRACES_EXPORTER=otlp
In v0.82, this enables all supported OTEL signals—not just traces. (A more accurately descriptive environment variable and command line argument is to come in v1.0.)
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
These configurations can also be set with the --otel-traces-exporter
and --otel-exporter-otlp-endpoint
host config options.
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. 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 OTEL_
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.