diff --git a/apisix/plugins/zipkin.lua b/apisix/plugins/zipkin.lua index ab284cefe9fa7..51596d06c3f73 100644 --- a/apisix/plugins/zipkin.lua +++ b/apisix/plugins/zipkin.lua @@ -19,6 +19,8 @@ local new_tracer = require("opentracing.tracer").new local zipkin_codec = require("apisix.plugins.zipkin.codec") local new_random_sampler = require("apisix.plugins.zipkin.random_sampler").new local new_reporter = require("apisix.plugins.zipkin.reporter").new +local rand_bytes = require "resty.random".bytes +local to_hex = require "resty.string".to_hex local ngx = ngx local ngx_re = require("ngx.re") local pairs = pairs @@ -163,9 +165,9 @@ function _M.rewrite(plugin_conf, ctx) -- pass the trace ids even the sample is rejected -- see https://github.com/openzipkin/b3-propagation#why-send- -- trace-ids-with-a-reject-sampling-decision - core.request.set_header(ctx, "x-b3-traceid", trace_id) - core.request.set_header(ctx, "x-b3-parentspanid", parent_span_id) - core.request.set_header(ctx, "x-b3-spanid", request_span_id) + core.request.set_header(ctx, "x-b3-traceid", trace_id or to_hex(rand_bytes(16))) + core.request.set_header(ctx, "x-b3-parentspanid", parent_span_id or to_hex(rand_bytes(8))) + core.request.set_header(ctx, "x-b3-spanid", request_span_id or to_hex(rand_bytes(8))) return end