Created
February 24, 2022 14:52
-
-
Save TonPC64/70e2890ba23712075d803dccd10a3f74 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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