Distributed tracing with golang http.PostForm

倖福魔咒の 提交于 2020-01-30 11:05:55

问题


In my project, I try to implement distributed tracing using opentracing.

My microservice has following structure.

-- API-Gateway
       |_ User-Service
       |_ Notification 

In my API-gateway, I start and in API gateway, I use a to a function to start tracing, code is taken from Setting up your tracer

in main():

gatewayTracer := &apiTracer{tracer: startTracing("API Gateway")}

http.HandleFunc("/getemail", gatewayTracer.validatemail)

func (apitracer apiTracer) validatemail(res http.ResponseWriter, req *http.Request) {

    validateEmailSpan := apitracer.tracer.StartSpan("Validate Email")
}

I call to my User-service from validateemail() using http.PostForm().

_, err := http.PostForm("http://user:7071/checkemail", url.Values{"uuid": {uuid}, "email": {email}})

Here uuid is for separate task, not for tracing. I can not post this Span to the next service using PostForm().

How to overcome this issue?


回答1:


I don't think it can be done from PostForm. You would need to use http.NewRequest to create the POST request, Inject the span in headers and use Client.Do to send the request.



来源:https://stackoverflow.com/questions/58672447/distributed-tracing-with-golang-http-postform

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!