使用golang http.PostForm进行分布式跟踪

问题描述 投票:0回答:1

在我的项目中,我尝试使用opentracing实现分布式跟踪。

我的微服务具有以下结构。

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

在我的API网关中,我启动并在API网关中,我使用到一个函数来开始跟踪,代码取自Setting up your tracer

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")
}

我使用validateemail()http.PostForm()调用我的用户服务。

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

此处uuid用于单独的任务,而不用于跟踪。我无法使用Span将此PostForm()发布到下一个服务。

如何克服这个问题?

go microservices trace opentracing distributed-tracing
1个回答
0
投票

我不认为可以从PostForm完成。您将需要使用http.NewRequest创建POST请求,Inject标头中的跨度,然后使用Client.Do发送请求。

© www.soinside.com 2019 - 2024. All rights reserved.