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: Pass block explicitly in define_method calls for PG instrumentation query methods #574

Conversation

Capncavedan
Copy link
Contributor

@Capncavedan Capncavedan commented Jul 20, 2023

#570

"As a result of the fact blocks are captured by closures they cannot be passed implicitly to methods created with define_method; they must instead be passed explicitly using the define_method(meth) { |args, &block| ... } syntax."
from https://banisterfiend.wordpress.com/2010/11/06/behavior-of-yield-in-define_method/

This PR changes the "exec-ish" and "exec-prepared-ish" methods to all optionally handle an explicit block, with a new separate test file specifically for these PG::Connection patches.

This PR does not change the "prepare-ish" methods as those don't seem to return anything anyway.

…uery methods

open-telemetry#570

"As a result of the fact blocks are captured by closures they cannot be passed
implicitly to methods created with define_method; they must instead be passed
explicitly using the define_method(meth) { |args, &block| ... } syntax."
from https://banisterfiend.wordpress.com/2010/11/06/behavior-of-yield-in-define_method/
@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Jul 20, 2023

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: Capncavedan / name: Dan Buettner (42e9c9a)
  • ✅ login: arielvalentin / name: Ariel Valentin (2ae6f37, 81f09eb)

@arielvalentin
Copy link
Collaborator

@Capncavedan thanks again for your help!

Please review and sign the Easy CLA so that we may start the PR review process.

@Capncavedan
Copy link
Contributor Author

@arielvalentin done

@arielvalentin
Copy link
Collaborator

Thank you. Did you happen to have the ability to test this in a sample app?

If so would you be able to share some screen shots of the fix in action?

@Capncavedan
Copy link
Contributor Author

@arielvalentin Only in the repro script so far. This bug manifested up in a background process of ours, and we patched it to process its Postgres queries differently.

Apologies if this is already clear - the bug isn't affecting telemetry, rather one specific way of issuing Postgres queries using the PG gem.

@arielvalentin arielvalentin changed the title Pass block explicitly in define_method calls for PG instrumentation query methods fix: Pass block explicitly in define_method calls for PG instrumentation query methods Jul 21, 2023
Copy link
Collaborator

@arielvalentin arielvalentin left a comment

Choose a reason for hiding this comment

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

Thank you for this contribution!

Please update your commit messages to use conventional commits: https://github.com/open-telemetry/opentelemetry-ruby-contrib/blob/main/CONTRIBUTING.md#use-conventional-commit-messages

require_relative '../../../../../lib/opentelemetry/instrumentation/pg'
require_relative '../../../../../lib/opentelemetry/instrumentation/pg/patches/connection'

describe OpenTelemetry::Instrumentation::PG::Patches do
Copy link
Collaborator

Choose a reason for hiding this comment

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

✨ Thank you for adding tests for this!

@arielvalentin arielvalentin added the help wanted Extra attention is needed label Jul 25, 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.

This looks good to me once require 'active_record' is removed from the tests.

@Capncavedan
Copy link
Contributor Author

Capncavedan commented Jul 25, 2023 via email

@arielvalentin
Copy link
Collaborator

@Capncavedan enjoy your holiday! I have committed the suggestion knowing you are ok with it via the GitHub PR suggestion feature.

Copy link
Contributor

@plantfansam plantfansam left a comment

Choose a reason for hiding this comment

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

I think this makes sense! Thank you for the tests ❤️

@arielvalentin arielvalentin merged commit 84f7b64 into open-telemetry:main Jul 28, 2023
Copy link
Collaborator

@arielvalentin arielvalentin left a comment

Choose a reason for hiding this comment

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

Forgot to leave my review. I did some exploratory testing using the example/pg.rb script and things look good!

Thanks for your contribution. I will get a release out shortly.

@Capncavedan
Copy link
Contributor Author

Thanks @arielvalentin !

@Capncavedan Capncavedan deleted the patch-block-syntax-result-match-dot-method-result branch August 9, 2023 16:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants