Introducing a new way to review your PRs.

Read the announcement

basecamp / kamal

Deploy web apps anywhere.

View on GitHub

17 documents · Updated Nov 16, 2026

docs / operational-integrations

Operational integrations and observability

Kamal coordinates deployment work across remote hosts and makes that work visible to operators. It uses SSH-based command execution, host-aware output, persistent log sinks, and retry controls so that deployment actions remain traceable when hosts are slow, numerous, or briefly unavailable.

Operational model

Kamal runs deployment commands from a local control process while the work takes place on application, proxy, accessory, or builder hosts. The command layer selects the host and role context. The SSH and output layers then carry the action to the host and report its result through the configured operator channels.

The two focused guides explain these paths in more detail: remote execution covers host access and command flow, while telemetry and logging covers activity records and log destinations.

Remote command execution

Host access

SSH is the main boundary between the local deployment process and remote hosts. Kamal builds one connection policy from the configured user, port, keys, proxy, SSH config, and agent-forwarding settings, then gives that policy to the shared SSH command runner. The default path targets the root user on port 22, but the same boundary supports non-default users and network paths.

References: lib/…/ssh.rb• L8-75 lib/…/ssh.yml• L1-81 lib/…/commander.rb• L192-200

Command contexts

Commands can act on an existing application container or start a short-lived container for the requested work. Both paths execute on the selected host, which keeps remote work inside the deployment's role, network, environment, volume, and logging context instead of treating it as an unrelated shell action.

References: lib/…/execution.rb• L1-38 lib/…/base.rb• L13-15

Remote builders

Remote building extends the same host boundary to image creation. Kamal connects a local Docker context to the remote builder and uses Buildx so image work can run near the target registry or host without moving the full build process into the deployment machine.

References: lib/…/remote.rb• L1-74

Activity reporting

Command activity

Kamal treats each top-level modifying command as an activity run. The activity boundary carries the command, subcommand, destination, selected hosts, elapsed time, and failure details to output loggers. SSH command output is also tagged with its host, stream type, and severity so an operator can relate a line to the remote action that produced it.

References: lib/…/commander.rb• L153-167 lib/…/base_logger.rb• L3-29 lib/…/formatter.rb• L1-36

Log destinations

Configured output loggers receive the same activity stream through a broadcast fan-out. The file destination preserves a local record for later review. The OpenTelemetry destination sends structured records to an external collector and marks deployment commands with a run identity and status. This lets local troubleshooting and central monitoring use the same command activity without changing deployment behavior.

References: lib/…/output.rb• L1-33 lib/…/file_logger.rb• L1-51 lib/…/otel_logger.rb• L1-70

Telemetry delivery

The OpenTelemetry path treats output lines and lifecycle events as log records. It adds service, version, destination, host, stream, and severity context, then batches records for delivery to the configured logs endpoint. A background flush and a final shutdown flush reduce the chance that buffered activity is lost when a command ends.

References: lib/…/otel_shipper.rb• L7-88 lib/…/otel_shipper.rb• L119-170

Resilient deployment operation

Connection stability

Kamal limits the number of SSH connections that start at one time and keeps idle connections available during long pauses. It retries temporary DNS lookup failures with bounded backoff. These controls reduce connection storms and avoid treating short-lived name resolution problems as deployment failures.

References: lib/…/sshkit.rb• L1-25 lib/…/sshkit.yml• L1-31 lib/…/sshkit_with_ext.rb• L73-172

Parallel execution

Deployment actions can run across hosts and roles in parallel. The execution layer waits for every parallel task to finish and reports all host or role failures together, so one early error does not hide failures that occurred elsewhere in the same operation.

References: lib/…/sshkit_with_ext.rb• L175-209 lib/…/sshkit_with_ext.rb• L220-273

Failure isolation

Observability is useful even when its destination is unavailable. Local command output remains the primary operator path, while logger setup and OpenTelemetry shipping report their own errors without replacing the deployment command's result. The shipper also avoids repeating the same transport error for every failed send.

References: lib/…/commander.rb• L203-217 lib/…/otel_shipper.rb• L141-170

Integration boundaries

The operational integrations connect four concerns without merging their responsibilities:

  • Command ownership: command objects decide what work must run and on which host.
  • Transport ownership: SSHKit and SSH settings decide how the work reaches the host.
  • Activity ownership: the commander and formatter define the activity boundary and attach execution context.
  • Record ownership: file and OpenTelemetry loggers decide where activity records go.

This separation allows a deployment to change its access path or reporting sink while keeping the application and host actions the same.

Change checklist

When these files or sections are changed, remember to consider these:

  • Changes to activity payload names or lifecycle timing must stay aligned with both file naming and OpenTelemetry event attributes.
  • Changes to SSHKit command context must preserve host and stream context for remote output records.
  • Changes to parallel runner behavior must preserve aggregate failure reporting across all hosts and roles.
  • Changes to log shipping shutdown must keep the final buffered records available when a modifying command exits.
  • Changes to remote builder context names must keep builder inspection, creation, and removal pointed at the same remote endpoint.

Important failure modes

TriggerConsequenceGuard
A host cannot resolve during a connection burstRemote work can fail before the command startsBounded DNS retries with backoff and jitter
Too many SSH connections start at onceThe deployment can overload the resolver or target hostsA shared concurrent-start limit
One task fails during parallel executionOther host or role failures can be hidden by first-error handlingWait for all tasks and report the full failure set
The telemetry endpoint is unavailableCentral records are not deliveredKeep local output active and report the shipping error once
A modifying command exits with buffered telemetryRecent activity can be missing from the external recordStop the shipper and flush its buffer

Key files

FileWhy to read it
lib/…/commander.rbDefines the shared command lifecycle and connects SSHKit with output logging.
lib/…/sshkit_with_ext.rbShows the resilience and parallel-execution behavior around remote work.
lib/…/ssh.rbDefines the access boundary for remote hosts.
lib/…/formatter.rbShows how host, stream, and severity context enters activity records.
lib/…/otel_logger.rbShows how deployment lifecycle events map to central telemetry.
lib/…/otel_shipper.rbShows batching, context, delivery, and final flush behavior.
lib/…/execution.rbIllustrates how application commands run on remote hosts and in containers.
lib/…/remote.rbIllustrates the remote image-building integration.