Skip to content

Commit

Permalink
test(tracing): Add instana header support in propagation
Browse files Browse the repository at this point in the history
  • Loading branch information
SuzyWangIBMer committed Jan 31, 2025
1 parent adfb4cb commit bd004e8
Show file tree
Hide file tree
Showing 3 changed files with 221 additions and 7 deletions.
108 changes: 108 additions & 0 deletions spec/01-unit/26-observability/02-propagation_strategies_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1637,6 +1637,114 @@ local test_data = { {
},
err = "gcp injector context is invalid: field span_id not found in context"
} }
}, {
extractor = "instana",
injector = "instana",
headers_data = { {
description = "base case",
extract = true,
inject = true,
trace_id = trace_id_16,
headers = {
["x-instana-t"] = trace_id_16,
["x-instana-s"] = span_id_8_1,
["x-instana-l"] = "1",
},
ctx = {
trace_id = trace_id_16,
span_id = span_id_8_1,
should_sample = true,
trace_id_original_size = 16,
}
}, {
description = "sampled = false",
extract = true,
inject = true,
trace_id = trace_id_16,
headers = {
["x-instana-t"] = trace_id_16,
["x-instana-s"] = span_id_8_1,
["x-instana-l"] = "0",
},
ctx = {
trace_id = trace_id_16,
span_id = span_id_8_1,
should_sample = false,
trace_id_original_size = 16,
}
}, {
description = "8B trace id",
extract = true,
inject = true,
trace_id = trace_id_8,
headers = {
["x-instana-t"] = trace_id_8,
["x-instana-s"] = span_id_8_1,
["x-instana-l"] = "0",
},
ctx = {
trace_id = padding_prefix .. trace_id_8,
span_id = span_id_8_1,
should_sample = false,
trace_id_original_size = 8,
}
}, {
description = "big 16B trace ID",
inject = true,
trace_id = big_trace_id_16,
headers = {
["x-instana-t"] = big_trace_id_16,
["x-instana-s"] = span_id_8_1,
},
ctx = {
trace_id = big_trace_id_16,
span_id = span_id_8_1,
}
}, {
description = "invalid flag",
extractor = true,
trace_id = trace_id_16,
headers = {
["x-instana-t"] = trace_id_16,
["x-instana-s"] = span_id_8_1,
["x-instana-l"] = "5",
},
ctx = {
trace_id = big_trace_id_16,
span_id = span_id_8_1,
should_sample = true,
}
},{ -- extraction error cases
description = "invalid trace ID (non hex)",
extract = true,
trace_id = "abcdefghijklmnop",
headers = {
["x-instana-t"] = "abcdefghijklmnop",
["x-instana-s"] = span_id_8_1,
},
err = "x-instana-t header invalid; ignoring."
}, {
description = "invalid trace ID (too long)",
extract = true,
headers = {
["x-instana-t"] = too_long_id,
},
err = "x-instana-t header invalid; ignoring."
}, {
description = "invalid trace ID (too short)",
extract = true,
headers = {
["x-instana-t"] = "abc",
},
err = "x-instana-t header invalid; ignoring."
}, {
description = "empty header",
extract = true,
headers = {
["x-instana-t"] = "",
},
err = "x-instana-t header invalid; ignoring."
},}
} }


Expand Down
69 changes: 66 additions & 3 deletions spec/03-plugins/34-zipkin/zipkin_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ local http_route_host = "http-route"
local http_route_ignore_host = "http-route-ignore"
local http_route_w3c_host = "http-route-w3c"
local http_route_dd_host = "http-route-dd"
local http_route_ins_host = "http-route-ins"
local http_route_clear_host = "http-clear-route"
local http_route_no_preserve_host = "http-no-preserve-route"

Expand Down Expand Up @@ -671,6 +672,21 @@ local function setup_zipkin_old_propagation(bp, service, traceid_byte_count)
default_header_type = "datadog",
}
})

-- header_type = "instana"
bp.plugins:insert({
name = "zipkin",
route = {id = bp.routes:insert({
service = service,
hosts = { http_route_ins_host },
}).id},
config = {
sample_ratio = 1,
http_endpoint = fmt("http://%s:%d/api/v2/spans", ZIPKIN_HOST, ZIPKIN_PORT),
header_type = "instana",
default_header_type = "instana",
}
})
end

local function setup_zipkin_new_propagation(bp, service, traceid_byte_count)
Expand All @@ -687,7 +703,7 @@ local function setup_zipkin_new_propagation(bp, service, traceid_byte_count)
{ name = "static", value = "ok" },
},
propagation = {
extract = { "b3", "w3c", "jaeger", "ot", "datadog", "aws", "gcp" },
extract = { "b3", "w3c", "jaeger", "ot", "datadog", "aws", "gcp", "instana" },
inject = { "preserve" },
default_format = "b3-single",
},
Expand Down Expand Up @@ -723,7 +739,7 @@ local function setup_zipkin_new_propagation(bp, service, traceid_byte_count)
sample_ratio = 1,
http_endpoint = fmt("http://%s:%d/api/v2/spans", ZIPKIN_HOST, ZIPKIN_PORT),
propagation = {
extract = { "b3", "w3c", "jaeger", "ot", "datadog", "aws", "gcp" },
extract = { "b3", "w3c", "jaeger", "ot", "datadog", "aws", "gcp", "instana" },
inject = { "preserve", "w3c" },
default_format = "b3-single",
},
Expand All @@ -741,13 +757,31 @@ local function setup_zipkin_new_propagation(bp, service, traceid_byte_count)
sample_ratio = 1,
http_endpoint = fmt("http://%s:%d/api/v2/spans", ZIPKIN_HOST, ZIPKIN_PORT),
propagation = {
extract = { "b3", "w3c", "jaeger", "ot", "aws", "datadog", "gcp" },
extract = { "b3", "w3c", "jaeger", "ot", "aws", "datadog", "gcp", "instana" },
inject = { "preserve", "datadog" },
default_format = "datadog",
},
}
})

-- header_type = "instana"
bp.plugins:insert({
name = "zipkin",
route = {id = bp.routes:insert({
service = service,
hosts = { http_route_ins_host },
}).id},
config = {
sample_ratio = 1,
http_endpoint = fmt("http://%s:%d/api/v2/spans", ZIPKIN_HOST, ZIPKIN_PORT),
propagation = {
extract = { "b3", "w3c", "jaeger", "ot", "aws", "datadog", "gcp", "instana" },
inject = { "preserve", "instana" },
default_format = "instana",
},
}
})

-- available with new configuration only:
-- no preserve
bp.plugins:insert({
Expand Down Expand Up @@ -1579,6 +1613,35 @@ describe("http integration tests with zipkin server [#"
end)
end)

describe("propagates instana tracing headers", function()
it("with instana headers in client request", function()
local trace_id = gen_trace_id(16)
local span_id = gen_span_id()
local r = proxy_client:get("/", {
headers = {
["x-instana-t"] = trace_id,
["x-instana-s"] = span_id,
host = http_route_host,
},
})
local body = assert.response(r).has.status(200)
local json = cjson.decode(body)

assert.equals(trace_id, json.headers["x-instana-t"])
end)

it("without instana headers in client request", function()
local r = proxy_client:get("/", {
headers = { host = http_route_ins_host },
})
local body = assert.response(r).has.status(200)
local json = cjson.decode(body)

assert.is_not_nil(json.headers["x-instana-t"])
assert.is_not_nil(json.headers["x-instana-s"])
end)
end)

if propagation_config == "new" then
it("clears non-propagated headers when configured to do so", function()
local trace_id = gen_trace_id(16)
Expand Down
51 changes: 47 additions & 4 deletions spec/03-plugins/37-opentelemetry/03-propagation_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ local http_route_ignore_host = "http-route-ignore"
local http_route_w3c_host = "http-route-w3c"
local http_route_dd_host = "http-route-dd"
local http_route_b3_single_host = "http-route-b3-single"
local http_route_ins_host = "http-route-ins"
local http_route_clear_host = "http-clear-route"
local http_route_no_preserve_host = "http-no-preserve-route"

Expand Down Expand Up @@ -124,6 +125,18 @@ local function setup_otel_old_propagation(bp, service)
header_type = "b3-single",
}
})

bp.plugins:insert({
name = "opentelemetry",
route = {id = bp.routes:insert({
service = service,
hosts = { http_route_ins_host },
}).id},
config = {
traces_endpoint = "http://localhost:8080/v1/traces",
header_type = "instana",
}
})
end

-- same configurations as "setup_otel_old_propagation", using the new
Expand All @@ -138,7 +151,7 @@ local function setup_otel_new_propagation(bp, service)
config = {
traces_endpoint = "http://localhost:8080/v1/traces",
propagation = {
extract = { "b3", "w3c", "jaeger", "ot", "datadog", "aws", "gcp" },
extract = { "b3", "w3c", "jaeger", "ot", "datadog", "aws", "gcp", "instana" },
inject = { "preserve" },
default_format = "w3c",
}
Expand Down Expand Up @@ -170,7 +183,7 @@ local function setup_otel_new_propagation(bp, service)
config = {
traces_endpoint = "http://localhost:8080/v1/traces",
propagation = {
extract = { "b3", "w3c", "jaeger", "ot", "datadog", "aws", "gcp" },
extract = { "b3", "w3c", "jaeger", "ot", "datadog", "aws", "gcp", "instana" },
inject = { "preserve", "w3c" },
default_format = "w3c",
}
Expand All @@ -186,7 +199,7 @@ local function setup_otel_new_propagation(bp, service)
config = {
traces_endpoint = "http://localhost:8080/v1/traces",
propagation = {
extract = { "b3", "w3c", "jaeger", "ot", "datadog", "aws", "gcp" },
extract = { "b3", "w3c", "jaeger", "ot", "datadog", "aws", "gcp", "instana" },
inject = { "preserve", "datadog" },
default_format = "datadog",
}
Expand All @@ -202,13 +215,28 @@ local function setup_otel_new_propagation(bp, service)
config = {
traces_endpoint = "http://localhost:8080/v1/traces",
propagation = {
extract = { "b3", "w3c", "jaeger", "ot", "datadog", "aws", "gcp" },
extract = { "b3", "w3c", "jaeger", "ot", "datadog", "aws", "gcp", "instana" },
inject = { "preserve", "b3-single" },
default_format = "w3c",
}
}
})

bp.plugins:insert({
name = "opentelemetry",
route = {id = bp.routes:insert({
service = service,
hosts = { http_route_ins_host },
}).id},
config = {
traces_endpoint = "http://localhost:8080/v1/traces",
propagation = {
extract = { "b3", "w3c", "jaeger", "ot", "datadog", "aws", "gcp", "instana" },
inject = { "preserve", "instana" },
default_format = "instana",
}
}
})
-- available with new configuration only:
-- no preserve
bp.plugins:insert({
Expand Down Expand Up @@ -511,6 +539,21 @@ describe("propagation tests #" .. strategy ..
assert.equals(trace_id, json.headers["ot-tracer-traceid"])
end)

it("propagates instana headers", function()
local trace_id = gen_trace_id()
local span_id = gen_span_id()
local r = proxy_client:get("/", {
headers = {
["x-instana-t"] = trace_id,
["x-instana-s"] = span_id,
host = http_route_ins_host,
},
})
local body = assert.response(r).has.status(200)
local json = cjson.decode(body)

assert.equals(trace_id, json.headers["x-instana-t"])
end)

describe("propagates datadog tracing headers", function()
it("with datadog headers in client request", function()
Expand Down

0 comments on commit bd004e8

Please sign in to comment.