From dd11d5b81b82b3221ea306e52259d9cf477d7907 Mon Sep 17 00:00:00 2001 From: Francis Bogsanyi Date: Thu, 15 Feb 2024 14:29:06 -0500 Subject: [PATCH] fix: Replace Context stack on clear (#1598) * fix: Replace Context stack on clear * Document clear method --- api/lib/opentelemetry/context.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/api/lib/opentelemetry/context.rb b/api/lib/opentelemetry/context.rb index 42f12d3d7..05e96ed6b 100644 --- a/api/lib/opentelemetry/context.rb +++ b/api/lib/opentelemetry/context.rb @@ -113,8 +113,11 @@ 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 - stack.clear + Thread.current[STACK_KEY] = [] end def empty