Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ActiveSupport::TaggedLogging does not persist context in a Fiber #37535

Closed
rafadc opened this issue Oct 23, 2019 · 5 comments
Closed

ActiveSupport::TaggedLogging does not persist context in a Fiber #37535

rafadc opened this issue Oct 23, 2019 · 5 comments
Labels

Comments

@rafadc
Copy link

rafadc commented Oct 23, 2019

Steps to reproduce

In a new Rails application in the console just type:

logger = ActiveSupport::TaggedLogging.new(Logger.new(STDOUT))
logger.tagged('TAG') { Fiber.new{logger.info 'Stuff'}.resume }

This is similar (but not equal) to: #28156 In that issue the conversation is around threads.

Expected behavior

That should output:

[TAG] Stuff

Actual behavior

The output is

Stuff

and the tags are lost

Comments

The behaviour for threads is tested in: https://github.com/rails/rails/blob/v6.0.0/activesupport/test/tagged_logging_test.rb#L75-L84

but there is no information for Fibers. The current implementation does not pass the tags for threads (and probably it is not easy to do) but making it work for Fibers probably should be just changing this method

def current_tags
# We use our object ID here to avoid conflicting with other instances
thread_key = @thread_key ||= "activesupport_tagged_logging_tags:#{object_id}"
Thread.current[thread_key] ||= []
end
to use Thread.current.current_variable_set and Thread.current.current_variable_getinstead because:

Thread.current[:fiber_local_var] = 'Result'
Fiber.new do
  puts Thread.current[:fiber_local_var]
end.resume
# => <Empty output>

Thread.current.thread_variable_set(:thread_local_var, 'Result')
Fiber.new do
  puts Thread.current.thread_variable_get(:thread_local_var)
end.resume
# => "Result"

I can create the PR myself but I'd first love to know if what I am saying makes sense or you explicitly don't want this to work for Fibers. In such case I can PR a test that intentionally excludes Fibers so it is explicit.

System configuration

Rails version: 6.0.0

Ruby version: 2.6.2p47

Thanks a lot!

@rails-bot
Copy link

rails-bot bot commented Jan 21, 2020

This issue has been automatically marked as stale because it has not been commented on for at least three months.
The resources of the Rails team are limited, and so we are asking for your help.
If you can still reproduce this error on the 6-0-stable branch or on master, please reply with all of the information you have about it in order to keep the issue open.
Thank you for all your contributions.

@rafadc
Copy link
Author

rafadc commented Jan 21, 2020

The issue is still relevant in Rails 6.0.2.1

@rails-bot rails-bot bot removed the stale label Jan 21, 2020
@rails-bot
Copy link

rails-bot bot commented Apr 20, 2020

This issue has been automatically marked as stale because it has not been commented on for at least three months.
The resources of the Rails team are limited, and so we are asking for your help.
If you can still reproduce this error on the 6-0-stable branch or on master, please reply with all of the information you have about it in order to keep the issue open.
Thank you for all your contributions.

@rails-bot rails-bot bot added the stale label Apr 20, 2020
@leehambley
Copy link

The issue is still relevant in 6.0.2.2

@rails-bot rails-bot bot removed the stale label Apr 21, 2020
@rails-bot
Copy link

rails-bot bot commented Jul 20, 2020

This issue has been automatically marked as stale because it has not been commented on for at least three months.
The resources of the Rails team are limited, and so we are asking for your help.
If you can still reproduce this error on the 6-0-stable branch or on master, please reply with all of the information you have about it in order to keep the issue open.
Thank you for all your contributions.

@rails-bot rails-bot bot added the stale label Jul 20, 2020
@rails-bot rails-bot bot closed this as completed Jul 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants