Docker container logs

Collect the logs of every container on a Docker host and send them to Flowhawk, named by container.

Vector runs as one more container, reads the other containers' logs through the Docker socket, and posts them to Flowhawk. Your containers and their logging driver stay as they are.

What you get

  • Every container's logs in Logs, next to your traces and metrics, searchable with the same query language (severity>=WARN service=checkout "timeout"), grouped into patterns or followed live.
  • A log line that names a request path joins the business flow of that route, so a failing checkout shows these logs on the checkout flow's page.
  • A line that carries a trace id opens its trace.
  • Alert on any search with Alert on this, and let the agent read these logs when it investigates an incident.

Set it up

First create an ingest key: in the app, open Settings > API keys and pick Services. In the examples below, KEY stands for that key. Keep it out of your repository, like any other secret.

1. Write vector.toml

[sources.docker]
type = "docker_logs"

# Lines that are JSON become fields (level, message, trace_id...)
[transforms.parse]
type = "remap"
inputs = ["docker"]
source = '''
parsed, err = parse_json(.message)
if err == null && is_object(parsed) { . = merge(., object!(parsed)) }
'''

[sinks.flowhawk]
type = "http"
inputs = ["parse"]
uri = "https://api.flowhawk.dev/v1/logs/vector"
encoding.codec = "json"
auth.strategy = "bearer"
auth.token = "${FLOWHAWK_KEY}"

2. Run Vector next to your containers

docker run -d --name vector --restart unless-stopped \
  -e FLOWHAWK_KEY=KEY \
  -v /var/run/docker.sock:/var/run/docker.sock:ro \
  -v "$PWD/vector.toml:/etc/vector/vector.toml:ro" \
  timberio/vector:latest-alpine --config /etc/vector/vector.toml

With Docker Compose, add the same as a service. Each container's logs are named after the container, so name containers after the services in them (container_name: orders).

Check it arrived

Open Logs in the app and filter on the service. If nothing shows after a minute, Help and troubleshooting says why data can be refused (a wrong key, an empty balance) and how to see it.

Common questions

Can I skip some containers?

Yes. exclude_containers = ["vector"] or include_labels = ["logs=flowhawk"] in the source decides which are read.

What about container CPU and memory?

Those come from an OpenTelemetry Collector with the docker_stats receiver. Flowhawk has a ready-made Docker containers dashboard for them.

And traces?

Add OpenTelemetry to the services in the containers (language guides). Log lines that carry a trace id then open their trace.