Skip to content

fix docker container name extraction in fluent bit#270

Merged
Polliog merged 1 commit into
mainfrom
fix/fluent-bit-container-name-269
Jul 4, 2026
Merged

fix docker container name extraction in fluent bit#270
Polliog merged 1 commit into
mainfrom
fix/fluent-bit-container-name-269

Conversation

@Polliog

@Polliog Polliog commented Jul 4, 2026

Copy link
Copy Markdown
Collaborator

Fixes #269

Problem

The shipped Fluent Bit pipeline has a Copy container_name service filter, but nothing ever set container_name: extract_container_id.lua only extracted the container ID from the log filepath (/var/lib/docker/containers/<ID>/<ID>-json.log), and the container name simply is not part of that path. The copy was a silent no-op, so logs reached LogTide with no service field at all and only container_id/container_short_id in metadata, which is what showed up in the UI.

Fix

extract_container_id.lua now resolves the container name from the container's config.v2.json, which Docker keeps next to the log file and which is already available through the existing read-only /var/lib/docker/containers mount in both compose files (no compose changes needed):

  • the name is matched with an anchored pattern ("Name":"/<name>"); container names always carry the leading slash there, so volume mount Name keys in the same file cannot be picked up by mistake
  • results are cached per container ID, so the file is read once per container, not once per record
  • when config.v2.json is missing or unreadable, container_name falls back to the 12-char short ID, so service is always populated

Verification

Tested end-to-end against the real fluent/fluent-bit:4.2.2 image with the repo's parsers.conf, the production filter chain and a fake /var/lib/docker/containers tree (one container with a config.v2.json including a decoy volume Name, one without the file):

Before (current main): records had no service at all.

After:

{"service":"my-test-container","container_id":"aaaa...ffff","container_short_id":"aaaaaaaaaaaa","message":"hello from named container\n","level":"info",...}
{"service":"111111111111","container_id":"1111...6666","container_short_id":"111111111111","message":"hello from nameless container\n","level":"info",...}

container_name is still stripped from the final record by the existing record_modifier filter, and the backend ingest fallback chain (service || container_name || ... || 'unknown') is untouched.

@codecov

codecov Bot commented Jul 4, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@Polliog Polliog merged commit 5c80dc8 into main Jul 4, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Container name not displaying in logs

1 participant