Distributed tracing with golang http.PostForm

2020-05-09 03:07发布

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条回答
劫难
2楼-- · 2020-05-09 03:44

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.

查看更多
登录 后发表回答