首页 >> 中医推拿

nginx之前加入opentracing能力

发布时间:2025年10月22日 12:18

acing_module.so

load_module modules/ngx_http_opentracing_module.so;

其次,查找并装配jaeger plugin

opentracing_load_tracer /usr/local/lib/libjaegertracing_plugin.linux_amd64.so /etc/nginx/conf.d/jaeger-config.json;opentracing on; # 开业opentracing,默认为offopentracing_propagate_context; # 开业传达contextopentracing_operation_name nginx-$host; # 为请起个nameopentracing_tag request.id $request_id; # 分设span tag request.id,很难nginx 1.11以上

其中专门分设了一个request.id的tag,这个request.id串紧紧从nginx到code的所有请,不便检索请

仍要,附加一个jaeger的装配,localAgentHostPort很难装配变为jaeger-agent所在host:port

{ "service_name": "nginx", "diabled": false, "reporter": { "logSpans": true, "localAgentHostPort": "jaeger:6831" }, "sampler": { "type": "const", "param": "1" }}

2. server.conf

upstream api{ server 127.0.0.1:8080;}server{ listen *:80 default_server; server_name xx.test; opentracing_location_operation_name $request; opentracing_propagate_context; proxy_set_header X-Request-Id $request_id; proxy_set_Header Host $host; proxy_http_version 1.1; location ~ ^/api/ { proxy_pass ; }}

请注意三条装配分别分设了location name、开业传达context、分设header X-Request-Id为 $request_id

opentracing_location_operation_name $request;opentracing_propagate_context;proxy_set_header X-Request-Id $request_id;

3. code路中opentracing

import (.....opentracing "github.com/opentracing/opentracing-go""github.com/opentracing/opentracing-go/ext")func (c *AlertManagerController) Webhook() { spanCtx, _ := opentracing.GlobalTracer().Extract(opentracing.HTTPHeaders, opentracing.HTTPHeadersCarrier(c.Ctx.Request.Header)) span := opentracing.GlobalTracer().StartSpan("Webhook", ext.RPCServerOption(spanCtx)) // 关联为nginx的child uuid := c.Ctx.Input.Header("X-Request-Id") span.SetTag("request.id", uuid) // 分设request tag span.SetBaggageItem("request.id", uuid) // 向后续请转至request.id span.LogKV("request.body", string(c.Ctx.Input.RequestBody)) ......} 为什么不用nginx 1.2以上?

nginx opentracing require nginx 1.9.13+

request_id require nginx 1.11.0

nginx 偶数版本是stable

附模块上传定址

ngx_http_opentracing_module.so

jaeger plugin

详见。

长春治疗皮肤病最好的医院
沈阳治疗精神心理正规医院
沧州精神心理专科医院
甲流引起的咳嗽吃什么药
健康警示
急性支气管炎咳嗽厉害怎么缓解
尿混浊
疱疹性口炎

上一篇: 君联资本独家海外投资,卓凯生物完成数千万元B+轮融资

下一篇: 葱用好了是个“麒麟”

友情链接