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

Fix for compatibility issue with Async 2.6.2 #2083

Merged
merged 8 commits into from Jun 16, 2023

Conversation

tannalynn
Copy link
Contributor

@tannalynn tannalynn commented Jun 15, 2023

The issue was that we were capturing *args and passing them on for our Fiber instrumentation. Actually though, you can't actually pass arguments to Fiber.new the same way you can as with Thread.new (you would accomplish it like fiber.resume(args)). This wasn't causing any issues on it's own, however Async released a new version with fiber-annotation, that defines the Fiber initialize method as accepting only **kwargs, and not *args.

lib/fiber/annotation.rb

def initialize(annotation: nil, **options, &block)
	@annotation = annotation
	super(**options, &block)
end

In older Fiber versions, it seems there are no params you can pass to Fiber.new, but in newer ruby versions, there are keyword arguments that it accepts. Since we still support older ruby versions, we will define our fiber instrumentation initialize method differently depending on ruby version. This will allow our instrumentation to work on all supported ruby versions, and will not cause errors when using Async 2.6.2.

closes #2062

  • I also made the way we pass args to thread.new more correct with how it should be working
  • I also discovered our thread multiverse suite wasn't actually running any tests because if the string we pass to gemfile is empty, we just don't do anything. So i added a comment in the string.
  • I also added tests for checking to make sure args are being correctly passed for both fiber and thread

@tannalynn tannalynn marked this pull request as ready for review June 15, 2023 22:17
Comment on lines +77 to +87
def test_thread_instrumentation_args_preserved
Thread.new('arg 1', 2) do |arg1, arg2|
assert_equal ['arg 1', 2], [arg1, arg2]
end.join
end

def test_fiber_instrumentation_args_preserved
Fiber.new do |arg1, arg2|
assert_equal ['arg 1', 2], [arg1, arg2]
end.resume('arg 1', 2)
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the agent running during these test cases?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the other tests in the files are making sure the agent is recording stuff and nesting spans correctly, so the agent is running and the instrumentation is installed. I didn't add a transaction to these tests since I didn't need to assert anything about a transaction and only cared about making sure the instrumentation was passing the args properly.

traced_block = add_thread_tracing(*args, &block)
initialize_with_newrelic_tracing { initialize_without_new_relic(*args, &traced_block) }
if RUBY_VERSION < '2.7.0'
def initialize(*args, &block)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think *args should be *_args here to convey that we don't make use of it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh right! you mentioned that earlier and I totally blanked on it, my bad. thanks for the reminder.
updated in ec8a03b

fallwith
fallwith previously approved these changes Jun 15, 2023
Copy link
Contributor

@kaylareopelle kaylareopelle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

@@ -4,4 +4,6 @@

instrumentation_methods :chain, :prepend

gemfile nil
gemfile <<~RB
# this can't be empty or the tests won't run
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ooo good to know. Were they not running before?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

apparently not! I know they ran at some point in the past, because they did when i was working on them, but I think i ended up switching to passing nil to gemfile as an afterthought before merging in that PR iirc, because we thought that would work fine, so that would have have broken it.

@github-actions
Copy link

SimpleCov Report

Coverage Threshold
Line 94.14% 94%
Branch 85.59% 85%

@tannalynn tannalynn merged commit ba5a5ae into dev Jun 16, 2023
26 checks passed
@isaacbowen
Copy link

@tannalynn can y'all get this out in a patch release soon? this is preventing us from using Async. :)

@tannalynn tannalynn deleted the 2062_fiber_instrumentation_initialize branch June 23, 2023 19:38
@tannalynn
Copy link
Contributor Author

This fix will be included in 9.3.0, which we plan on releasing next week. I'll let you know when it's available once it's been published. Thank you!

@tannalynn
Copy link
Contributor Author

@isaacbowen 9.3.0, which includes this fix, has been released! You should be able to use it now, please let me know if you have any other issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Async 2.6.0 & fiber-annotation
5 participants