Skip to content

Instantly share code, notes, and snippets.

@TonPC64
Created February 24, 2022 14:52
Show Gist options
  • Save TonPC64/70e2890ba23712075d803dccd10a3f74 to your computer and use it in GitHub Desktop.
Save TonPC64/70e2890ba23712075d803dccd10a3f74 to your computer and use it in GitHub Desktop.
func init() {
config := sarama.NewConfig()
config.Version = sarama.V2_5_0_0
// So we can know the partition and offset of messages.
config.Producer.Return.Successes = true
var err error
producer, err = sarama.NewAsyncProducer([]string{"kafka:9092"}, config)
if err != nil {
log.Fatal().Err(err).Msg("Failed to start Sarama producer")
}
// Wrap instrumentation
producer = otelsarama.WrapAsyncProducer(config, producer)
// We will log to STDOUT if we're not able to produce messages.
go func() {
for err := range producer.Errors() {
fmt.Println("Failed to write message:", err)
}
}()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment