【问题标题】:Distributed tracing with golang http.PostForm使用 golang http.PostForm 进行分布式跟踪
【发布时间】:2019-11-02 15:22:35
【问题描述】:

在我的项目中,我尝试使用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")
}

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

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

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

如何解决这个问题?

【问题讨论】:

    标签: go microservices trace opentracing distributed-tracing


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2021-05-20
      • 2019-12-24
      • 2019-10-24
      • 2020-06-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-09
      • 1970-01-01
      相关资源
      最近更新 更多