From 54dce992a0cc66b3675db0650ec0fe15a34d68cf Mon Sep 17 00:00:00 2001 From: Francis Bogsanyi Date: Thu, 15 Feb 2024 10:12:15 -0500 Subject: [PATCH 1/2] fix: Replace Context stack on clear --- api/lib/opentelemetry/context.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/lib/opentelemetry/context.rb b/api/lib/opentelemetry/context.rb index 42f12d3d7..8730d1c2f 100644 --- a/api/lib/opentelemetry/context.rb +++ b/api/lib/opentelemetry/context.rb @@ -114,7 +114,7 @@ def value(key) end def clear - stack.clear + Thread.current[STACK_KEY] = [] end def empty From fb43d28da19e485619a83be8961bf33a0e4d3034 Mon Sep 17 00:00:00 2001 From: Francis Bogsanyi Date: Thu, 15 Feb 2024 10:19:01 -0500 Subject: [PATCH 2/2] Document clear method --- api/lib/opentelemetry/context.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/api/lib/opentelemetry/context.rb b/api/lib/opentelemetry/context.rb index 8730d1c2f..05e96ed6b 100644 --- a/api/lib/opentelemetry/context.rb +++ b/api/lib/opentelemetry/context.rb @@ -113,6 +113,9 @@ def value(key) current.value(key) end + # Clears the fiber-local Context stack. This allocates a new array for the + # stack, which is important in some use-cases to avoid sharing the backing + # array between fibers. def clear Thread.current[STACK_KEY] = [] end