@@ -427,44 +427,20 @@ local function inject_core_spans(root_span_ctx, api_ctx, conf)
427427end
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
455430function _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
0 commit comments