Skip to content

Commit

Permalink
fix(zipkin): send trace IDs with a reject sampling decision
Browse files Browse the repository at this point in the history
  • Loading branch information
Gallardot committed Oct 17, 2022
1 parent 8f39062 commit e90330b
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions apisix/plugins/zipkin.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit e90330b

Please sign in to comment.