Skip to content

Commit d2bd719

Browse files
committed
f
1 parent 956935a commit d2bd719

2 files changed

Lines changed: 3 additions & 35 deletions

File tree

apisix/plugins/opentelemetry.lua

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -427,44 +427,20 @@ local function inject_core_spans(root_span_ctx, api_ctx, conf)
427427
end
428428

429429

430-
function _M.delayed_body_filter(conf, api_ctx)
431-
if api_ctx.otel_context_token and ngx.arg[2] then
432-
local ctx = context:current()
433-
ctx:detach(api_ctx.otel_context_token)
434-
api_ctx.otel_context_token = nil
435-
436-
-- get span from current context
437-
local span = ctx:span()
438-
local upstream_status = core.response.get_upstream_status(api_ctx)
439-
if upstream_status and upstream_status >= 500 then
440-
span:set_status(span_status.ERROR,
441-
"upstream response status: " .. upstream_status)
442-
end
443-
444-
span:set_attributes(attr.int("http.status_code", upstream_status))
445-
446-
inject_core_spans(ctx, api_ctx, conf)
447-
448-
span:finish()
449-
end
450-
end
451-
452-
453-
-- body_filter maybe not called because of empty http body response
454-
-- so we need to check if the span has finished in log phase
455430
function _M.log(conf, api_ctx)
456431
if api_ctx.otel_context_token then
457432
-- ctx:detach() is not necessary, because of ctx is stored in ngx.ctx
458433
local upstream_status = core.response.get_upstream_status(api_ctx)
459434

460435
-- get span from current context
461-
local span = context:current():span()
436+
local ctx = context:current()
437+
local span = ctx:span()
462438
if upstream_status and upstream_status >= 500 then
463439
span:set_status(span_status.ERROR,
464440
"upstream response status: " .. upstream_status)
465441
end
466442

467-
inject_core_spans(span, api_ctx, conf)
443+
inject_core_spans(ctx, api_ctx, conf)
468444

469445
span:finish()
470446
end

t/plugin/opentelemetry6.t

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -229,11 +229,3 @@ qr/.*apisix.phase.access.*/
229229
tail -n 12 ci/pod/otelcol-contrib/data-otlp.json
230230
--- response_body eval
231231
qr/.*apisix.plugins.phase.header_filter.*/
232-
233-
234-
235-
=== TEST 10: check apisix.phase.delayed_body_filter.opentelemetry span
236-
--- exec
237-
tail ci/pod/otelcol-contrib/data-otlp.json
238-
--- response_body eval
239-
qr/.*apisix.phase.delayed_body_filter.opentelemetry.*/

0 commit comments

Comments
 (0)