Telemetry and logging
Kamal turns deployment command output into readable terminal feedback and optional records for later use. It can keep one log file per command, send structured records to an OpenTelemetry endpoint, and control the Docker log driver used by deployed containers.
Output and logging boundary
The output system reports what Kamal is doing during a command. The logging system controls how the application containers write their own logs. This boundary lets an engineer inspect deployment progress without confusing it with runtime logs from the deployed service.
Command output
Kamal keeps the normal terminal view as the main output and can broadcast the same formatted messages to configured output loggers. Messages include command context such as the target host, stream type, and severity when that context exists. Output logging starts around the outer command operation and closes when that operation ends. operational integrations describes how this output fits with other external systems.
The main flow is:
flowchart LR
A[Deployment command] --> B[Formatted terminal output]
B --> C{Configured output loggers}
C --> D[Local file]
C --> E[OpenTelemetry endpoint]
References: lib/…/commander.rb• L153-216 lib/…/formatter.rb• L1-35 lib/…/output.rb• L1-33
Container logging
The logging setting selects the Docker logging driver and its options for application containers. Kamal can apply the setting globally or merge a role-specific setting with the global one. If no setting is given, it uses a bounded default size so container logs do not grow without limit. See service configuration for the wider configuration model.
References: lib/…/logging.rb• L1-31 lib/…/logging.yml• L1-21 lib/…/role.rb• L21-67
Output destinations
The output setting enables one or more destinations for Kamal command output. Each destination receives the same formatted stream, so a deployment can remain visible in the terminal while also creating a local record or sending events to an operations platform.
File logs
The file logger writes output to a local directory. It creates a separate file for each top-level command and names the file with the time, destination, and command. On completion it records either the run time or the failure, then reports the file path to the user. This gives an operator a durable record without requiring a remote service.
References: lib/…/file_logger.rb• L1-51 lib/…/output.yml• L19-25
OpenTelemetry logs
The OpenTelemetry logger sends command output and lifecycle events to an OpenTelemetry-compatible OTLP HTTP endpoint. Stream records carry the source host, stream type, and severity when available. A run also emits start, complete, or failed events. Deployment commands add a deployment ID, name, status, run time, and error details so an operations system can group progress and outcome.
The logger uses tags such as service, version, performer, and destination as shared record context. It sends records in batches and flushes them on a short interval or when the logger closes. A shipping error is reported to standard error, while the command output path remains separate from the telemetry path. See remote execution for the host-side command work that produces this stream.
References: lib/…/otel_logger.rb• L1-70 lib/…/otel_shipper.rb• L7-88 lib/…/otel_shipper.rb• L111-170 lib/…/tags.rb• L3-39 lib/…/output.yml• L8-17
Telemetry lifecycle
Telemetry follows the lifecycle of the outer Kamal operation. At start, each configured logger opens its record scope. During the operation, formatted command messages flow to the terminal and the selected destinations. At finish, the logger records success or failure and closes its resources.
For deployment commands, OpenTelemetry adds deployment fields. Other commands still produce command and stream records, but they do not receive deployment status fields. This distinction keeps operational events useful without labeling every Kamal action as a deployment.
References: lib/…/commander.rb• L153-167 lib/…/base_logger.rb• L1-29 lib/…/otel_logger.rb• L25-69
Configuration relationships
The two configuration areas serve different audiences and run at different points in the system:
| Setting | Scope | Result |
|---|---|---|
logging | Deployed container runtime | Selects the Docker log driver and its limits or options. |
output.file | Kamal command execution | Saves formatted command output on the local machine. |
output.otel | Kamal command execution | Ships formatted output and lifecycle events to an OTLP HTTP receiver. |
The integration test configuration enables both output destinations. This is a useful model when local troubleshooting and central operations search must show the same deployment run.
References: lib/…/configuration.yml• L212-222 test/…/deploy.yml• L24-35 lib/…/output.rb• L4-19
Change checklist
When these files or sections are changed, remember to consider these:
- Keep the output logger names and required settings aligned with the destination examples. Unknown output names are ignored and missing endpoint or path values prevent that logger from being built.
- Preserve the command lifecycle around
modify.kamal. File completion and OpenTelemetry start or finish events depend on the same outer operation boundary. - Keep host, stream, and severity context attached to formatted output. Removing that context reduces the value of records in a central telemetry system.
- Keep OpenTelemetry attribute names stable when changing deployment tags. Dashboards and alerts may use the service, version, performer, destination, and deployment status fields.
- Keep Docker
loggingsettings separate from Kamaloutputsettings. Changing one does not change the other.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| A file destination has no path | The file logger cannot be created. | Provide output.file.path. |
| An OpenTelemetry destination has no endpoint | The OpenTelemetry logger cannot be created. | Provide output.otel.endpoint. |
| The telemetry receiver is unreachable or returns an error | Shipping fails and one error is written to standard error; the local command stream still has its normal path. | Monitor the receiver and keep a file destination when durable local evidence is needed. |
| A command ends while output is still buffered | Recent telemetry can be lost if the shipper is not closed and flushed. | Keep the command lifecycle and logger shutdown intact. |
| Container log limits are changed without checking the selected Docker driver | Runtime logs may be rejected, rotate differently, or grow beyond the intended bound. | Validate driver options against the Docker logging driver in use. |
Key files
| File | Why to read it |
|---|---|
| lib/…/commander.rb | Shows when output logging starts, how destinations are connected, and when they close. |
| lib/…/formatter.rb | Shows how terminal output gains host, stream, and severity context. |
| lib/…/file_logger.rb | Shows the local record lifecycle and completion behavior. |
| lib/…/otel_logger.rb | Shows the operational events and deployment fields exposed to telemetry. |
| lib/…/otel_shipper.rb | Shows batching, OTLP delivery, context fields, and shipping errors. |
| lib/…/logging.rb | Shows the separate Docker container logging contract. |
| lib/…/output.yml | Shows the user-facing output destination choices. |