Skip to content

Commit

Permalink
Fix specs by checking if AS properly isolates global state
Browse files Browse the repository at this point in the history
  • Loading branch information
flash-gordon committed Mar 6, 2024
1 parent 3ab6e77 commit 5fa52b4
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions lib/dry/effects/extensions/active_support/tagged_logging.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,18 @@

require "active_support/tagged_logging"

ActiveSupport::TaggedLogging::Formatter.prepend(Module.new {
def current_tags
thread_key = @thread_key ||= "activesupport_tagged_logging_tags:#{object_id}"
unless Thread.current.thread_variable_get(thread_key)
Thread.current.thread_variable_set(thread_key, [])
begin
require "active_support/isolated_execution_state"

# it's not needed when state is already isolated
rescue LoadError
ActiveSupport::TaggedLogging::Formatter.prepend(Module.new {
def current_tags
thread_key = @thread_key ||= "activesupport_tagged_logging_tags:#{object_id}"
unless Thread.current.thread_variable_get(thread_key)
Thread.current.thread_variable_set(thread_key, [])
end
Thread.current.thread_variable_get(thread_key)
end
Thread.current.thread_variable_get(thread_key)
end
})
})
end

0 comments on commit 5fa52b4

Please sign in to comment.