Created
February 24, 2022 14:54
-
-
Save TonPC64/845185a325c6fc451e942b1dcd5d6907 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 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