From 86f4ac7356a7d8ec74bfa1596fd252155005d0a4 Mon Sep 17 00:00:00 2001 From: Arjun Rajappa Date: Thu, 9 Jul 2026 03:12:58 +0530 Subject: [PATCH] fix(rack): always detach OTel context token after request was previously called inside , which is only invoked when is true. When tracing is disabled or suppressed, the token attached in was never detached, leaving the OTel context stack in a corrupted state for subsequent requests on the same thread. Move the detach call directly into the block of so it runs unconditionally, matching the lifecycle of . Signed-off-by: Arjun Rajappa --- lib/instana/instrumentation/rack.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/instana/instrumentation/rack.rb b/lib/instana/instrumentation/rack.rb index e0007a8e..90293d5e 100644 --- a/lib/instana/instrumentation/rack.rb +++ b/lib/instana/instrumentation/rack.rb @@ -34,6 +34,7 @@ def call(env) raise ensure finalize_trace(current_span, kvs, headers, trace_context) if ::Instana.tracer.tracing? + OpenTelemetry::Context.detach(@trace_token) if @trace_token end private @@ -123,7 +124,6 @@ def merge_response_headers(kvs, headers) def finalize_trace(current_span, kvs, headers, trace_context) set_response_headers(headers, trace_context) if headers current_span.add_attributes(kvs) - OpenTelemetry::Context.detach(@trace_token) if @trace_token current_span.finish end