Skip to content

out_kafka: add support for dynamic/static headers#1341

Open
DIFRIN wants to merge 1 commit intofluent:masterfrom
DIFRIN:output-kafka-add_headers
Open

out_kafka: add support for dynamic/static headers#1341
DIFRIN wants to merge 1 commit intofluent:masterfrom
DIFRIN:output-kafka-add_headers

Conversation

@DIFRIN
Copy link

@DIFRIN DIFRIN commented Mar 15, 2024

Add support for dynamic or static header for the kafka output plugin

Example:
'docker run --rm --network kafka_default -e value_test='${text}' -it fluent/fluent-bit-local:latest -i dummy -p dummy='{"text": "hello world"}' -p samples=1 -o kafka -p brokers=kafka:9092 -p topics=test_fluentbit -p header="key2 <text>" -vvv'

Gives
kafka-console-consumer --topic test_fluentbit --bootstrap-server kafka:9092 --property print.headers=true
key2:hello world {"@timestamp":1710505560.027627,"text":"hello world"}

Summary by CodeRabbit

  • New Features

    • Added Message headers for Kafka output: multiple header entries, static literal values, and dynamic values from log record fields; missing or non-string referenced fields are skipped with a warning; static and dynamic headers may be mixed.
  • Documentation

    • New Message headers section with YAML and conf examples and behavior notes; updated Kafka configuration examples to use brokers instead of host.

@lecaros
Copy link
Contributor

lecaros commented Apr 17, 2024

Hi @DIFRIN,
please sort the DCO issue.

@lecaros lecaros added waiting-for-user Waiting for user/contributors feedback or requested changes dco DCO failing waiting-on-code-merge labels Apr 17, 2024
@DIFRIN DIFRIN force-pushed the output-kafka-add_headers branch from 59f5378 to 3dec0b6 Compare May 29, 2024 19:25
@DIFRIN DIFRIN requested review from a team as code owners May 29, 2024 19:25
@DIFRIN
Copy link
Author

DIFRIN commented May 29, 2024

Hi @lecaros

DCO ok. Can you please review my merge request at fluent-bit repo

@lecaros lecaros added conflict Waiting on conflict to be resolved by contributor and removed dco DCO failing labels Aug 16, 2024
@eschabell
Copy link
Collaborator

@DIFRIN can you please resolve the conflicts here? I've nudged you on the code PR for the same conflict resolution task fluent/fluent-bit#8583. Both needed to merge.

@eschabell eschabell self-assigned this Oct 21, 2025
@esmerel
Copy link
Contributor

esmerel commented Oct 21, 2025

The conflicts were due to formatting changes for style, I went ahead and fixed the conflicts in the interest of keeping things moving.

There's one addition to the table that should be doublechecked by a dev-type person.

@patrick-stephens
Copy link
Contributor

I think we're still waiting on the code merge

@eschabell eschabell removed waiting-for-user Waiting for user/contributors feedback or requested changes conflict Waiting on conflict to be resolved by contributor labels Nov 4, 2025
@DIFRIN DIFRIN force-pushed the output-kafka-add_headers branch from e0be478 to f41317f Compare February 28, 2026 18:32
@DIFRIN DIFRIN requested a review from eschabell as a code owner February 28, 2026 18:32
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 28, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e016d17 and fe3dc5a.

📒 Files selected for processing (1)
  • pipeline/outputs/kafka.md
🚧 Files skipped from review as they are similar to previous changes (1)
  • pipeline/outputs/kafka.md

📝 Walkthrough

Walkthrough

Adds documentation for a new Kafka output header option allowing multiple static or dynamic message headers (dynamic values via $field); documents skip-and-warn behavior for missing/non-string fields, updates examples to use brokers, and adds YAML/fluent-bit.conf header examples.

Changes

Cohort / File(s) Summary
Kafka documentation
pipeline/outputs/kafka.md
Introduces a header configuration option and a new "Message headers" block with static and dynamic header examples (YAML and fluent-bit.conf); documents validation (skip + warning) for missing/non-string fields; updates examples to use brokers and clarifies mixing static/dynamic headers.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐇 I hop through logs to stitch each thread,
Static keys and fields I softly spread.
If a value's lost, I pause and warn,
Then bounce along at rosy dawn.
🥕📬

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: adding support for dynamic and static headers to the Kafka output plugin, which is the primary focus of the documentation additions.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
pipeline/outputs/kafka.md (1)

57-57: ⚠️ Potential issue | 🟡 Minor

Pre-existing typo: Incorrect IP address format.

The IP address 192.1681.3:9092 is missing a period and should be 192.168.1.3:9092. This same typo also appears at line 265. While these are example IPs, the inconsistency with the correct format used elsewhere in the document (lines 18, 39, 72, 109, 125, etc.) should be corrected.

📝 Suggested fix
-      host: 192.1681.3:9092
+      host: 192.168.1.3:9092

Also apply the same fix at line 265.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@pipeline/outputs/kafka.md` at line 57, Update the malformed host entries
where the IP is written as "192.1681.3:9092" to the correct dotted form
"192.168.1.3:9092"; specifically change the occurrences matching the string
"host: 192.1681.3:9092" (found around the currently flagged line and again at
the other occurrence) so they match the correct format used elsewhere in the
document.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@pipeline/outputs/kafka.md`:
- Line 57: Update the malformed host entries where the IP is written as
"192.1681.3:9092" to the correct dotted form "192.168.1.3:9092"; specifically
change the occurrences matching the string "host: 192.1681.3:9092" (found around
the currently flagged line and again at the other occurrence) so they match the
correct format used elsewhere in the document.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between dc38f3c and f41317f.

📒 Files selected for processing (1)
  • pipeline/outputs/kafka.md

Copy link
Collaborator

@eschabell eschabell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One issue I inline commented on @DIFRIN, almost there!

@eschabell eschabell added waiting-on-review Waiting on a review from mainteners lint-vale-issues labels Mar 1, 2026
@eschabell
Copy link
Collaborator

@DIFRIN also note the lint error for use of is not instead of isn't.

@DIFRIN DIFRIN force-pushed the output-kafka-add_headers branch from f41317f to 1bfcc57 Compare March 1, 2026 20:30
@DIFRIN DIFRIN requested a review from eschabell March 1, 2026 20:57
@eschabell
Copy link
Collaborator

@DIFRIN looks like you missed the lint issues: is not and can not fixes have been suggested in the inline code view by rabbitai.

@DIFRIN DIFRIN force-pushed the output-kafka-add_headers branch from 1bfcc57 to e016d17 Compare March 3, 2026 12:14
@DIFRIN
Copy link
Author

DIFRIN commented Mar 3, 2026

@eschabell Thanks for pointing that out. The suggested lint fixes have now been applied

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@pipeline/outputs/kafka.md`:
- Line 57: Replace the incorrect YAML key "host" with the documented "brokers"
in the Kafka examples (update occurrences of host: 192.168.1.3:9092 to use
brokers instead), and ensure the value format matches other examples (e.g.,
brokers: ["192.168.1.3:9092"] or brokers: 192.168.1.3:9092 depending on the
surrounding examples). Update both occurrences that currently use the "host" key
so they align with the rest of the docs.
- Around line 111-112: The YAML uses duplicate mapping keys "header"
(specifically the entries 'X-Environment production' and 'X-TraceId $trace_id'),
which is invalid; change this to a single "header" key with an array value (or a
single comma-separated header string if the Kafka plugin supports it) so both
'X-Environment production' and 'X-TraceId $trace_id' are preserved under the
same header key.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1bfcc57 and e016d17.

📒 Files selected for processing (1)
  • pipeline/outputs/kafka.md

Document the new 'header' configuration option added to the Kafka
output plugin, which allows attaching custom headers to produced
messages.

Add a row to the parameter table describing the 'header' key, and
add a new 'Message headers' section under 'Get started' with examples
for both static headers (literal values) and dynamic headers (values
resolved from log record fields using the '$field_name' syntax).

Signed-off-by: difrin <frindi.abderrahmane.ied@gmail.com>
@DIFRIN DIFRIN force-pushed the output-kafka-add_headers branch from e016d17 to fe3dc5a Compare March 3, 2026 12:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants