Skip to content

Instantly share code, notes, and snippets.

@TonPC64
Created February 24, 2022 14:54
Show Gist options
  • Save TonPC64/845185a325c6fc451e942b1dcd5d6907 to your computer and use it in GitHub Desktop.
Save TonPC64/845185a325c6fc451e942b1dcd5d6907 to your computer and use it in GitHub Desktop.
func handler(c *gin.Context) {
tracer := otel.GetTracerProvider().Tracer("gin-hander")
ctx, span := tracer.Start(c.Request.Context(), "handler-span")
defer span.End()
fmt.Println(c.Request.Header)
rand.Seed(time.Now().Unix())
msg := sarama.ProducerMessage{
Topic: "example-topic",
Key: sarama.StringEncoder("random_number"),
Value: sarama.StringEncoder(fmt.Sprintf("%d", rand.Intn(1000))),
}
otel.GetTextMapPropagator().Inject(ctx, otelsarama.NewProducerMessageCarrier(&msg))
producer.Input() <- &msg
successMsg := <-producer.Successes()
fmt.Println("Successful to write message, offset:", successMsg.Offset)
c.JSON(http.StatusOK, gin.H{
"message": http.StatusText(http.StatusOK),
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment