Skip to content

feat(output): add custom headers support to kafka - #898

Open
senthilsam wants to merge 1 commit into
openconfig:mainfrom
senthilsam:feat/add_kafka_headers
Open

feat(output): add custom headers support to kafka#898
senthilsam wants to merge 1 commit into
openconfig:mainfrom
senthilsam:feat/add_kafka_headers

Conversation

@senthilsam

Copy link
Copy Markdown
Contributor

Added support to add custom headers to kafka message

kafka:
  add-headers:
    dc: 'nl-01'  

@senthilsam
senthilsam force-pushed the feat/add_kafka_headers branch from 3714d5b to 5258504 Compare July 25, 2026 11:25

@karimra karimra left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

please add docs for the added config knob

Comment on lines +715 to +718
headers = append(headers, sarama.RecordHeader{
Key: []byte("sub"),
Value: []byte(m.GetMeta()["subscription-name"]),
})

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This is added unconditionally, either remove it or gate it behind a config knob.

Topic: topic,
Value: sarama.ByteEncoder(b),
Headers: headers,
Timestamp: time.Now(),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Timestamp is not required, it is broker assigned and unrelated to the stated PR scope.
Create another PR to add it if required (behind a config knob)

Comment on lines +708 to +713
for k, v := range cfg.AddHeaders {
headers = append(headers, sarama.RecordHeader{
Key: []byte(k),
Value: []byte(v),
})
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Duplicated code in sync and async producers. Good to create a helper and call in both locations.
Static headers don't need to be computed for every message. Compute once, store as part of dynConfig.

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.

2 participants