使用golang http.PostForm进行分布式跟踪 [英] Distributed tracing with golang http.PostForm

查看:434
本文介绍了使用golang http.PostForm进行分布式跟踪的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

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

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

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

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

如何克服这个问题?

解决方案

我认为不能通过PostForm完成.您可能需要使用http.NewRequest创建POST请求,使用Inject标头中的跨度,并使用Client.Do发送请求.

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?

解决方案

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.

这篇关于使用golang http.PostForm进行分布式跟踪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆