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

Freeze all range objects #1172

Open
hannahramadan opened this issue Sep 17, 2024 · 15 comments
Open

Freeze all range objects #1172

hannahramadan opened this issue Sep 17, 2024 · 15 comments
Assignees
Labels
good first issue Good for newcomers stale Marks an issue/PR stale

Comments

@hannahramadan
Copy link
Contributor

Freezing objects in Ruby provides several benefits including performance improvements and semantic clarity.

Since ranges are not frozen in Ruby by default, it would be nice to freeze ranges that appear through the codebase.

@Victorsesan
Copy link
Contributor

@kaylareopelle Is this still up for grabs?, can you assign me to give it a try thanks

@kaylareopelle
Copy link
Contributor

Hi @Victorsesan, it is! Just assigned you to the issue. Let us know if there's anything we can do to help 🙂

@Victorsesan
Copy link
Contributor

@kaylareopelle Cool thanks! Just wondering are the required ranges to be frozen that of Inclusive & Exclusive (100..399)? And can we create a different file in the lib directory to write a code to freeze the ranges in , also should we have the entire range as a single object frozen or have an implementation which creates individual frozen ranges?

@kaylareopelle
Copy link
Contributor

Hi @Victorsesan! Inclusive and exclusive ranges can both be frozen as part of this PR.

There's many approaches you could take to solve the problem!

For this scenario, my recommendation would be to create a constant equal to the range and replace the reference to the range within the code with the new constant.

For example, in the HTTPClient instrumentation, the annotate_with_span_response method uses a range, 100..399

def annotate_span_with_response!(span, response)
return unless response&.status_code
status_code = response.status_code.to_i
span.set_attribute('http.status_code', status_code)
span.status = OpenTelemetry::Trace::Status.error unless (100..399).cover?(status_code.to_i)
end

You could add a constant to the top of the OpenTelemetry::Instrumentation::HttpClient::Patches::Client class in the instrumentation/http_client/lib/opentelemetry/instrumentation/http_client/patches/client.rb file, maybe named something like NON_ERROR_STATUS_CODES that's equal to the range, and replace the reference to the range within the method to use the constant instead.

+        NON_ERROR_STATUS_CODES = 100..399

          def annotate_span_with_response!(span, response)
            return unless response&.status_code

            status_code = response.status_code.to_i

            span.set_attribute('http.status_code', status_code)
-           span.status = OpenTelemetry::Trace::Status.error unless (100.399).cover?(status_code.to_i)
+           span.status = OpenTelemetry::Trace::Status.error unless NON_ERROR_STATUS_CODES.cover?(status_code.to_i)
          end

@kaylareopelle
Copy link
Contributor

@Victorsesan - I found a good example of this in the Rack instrumentation:
https://github.com/open-telemetry/opentelemetry-ruby-contrib/blob/main/instrumentation/rack/lib/opentelemetry/instrumentation/rack/middlewares/event_handler.rb#L46

Victorsesan added a commit to Victorsesan/opentelemetry-ruby-contrib that referenced this issue Oct 19, 2024
Created a readable constant in 8 files to freeze ranges 100..399 .

Relate to open-telemetry#1172
@Victorsesan Victorsesan mentioned this issue Oct 19, 2024
@Victorsesan
Copy link
Contributor

@kaylareopelle Just tried this out! I'm not sure how it was directed to a different section for review 😅hopefully i didn't do something wrong . Anyways please check it out let me know what you think, i used a constant instead of a .freeze method as requested to make the code more readable. I'm very much open for any corrections or improvement if needed

@kaylareopelle
Copy link
Contributor

Hi @Victorsesan, thank you for opening the PR! The changes look like they're on the right track!

Our contributing guide has a few recommendations about making modifications that I would like you to follow before we move forward.

  1. Because we squash commits when we merge PRs in this repository, creating PRs off of your fork's main branch can cause problems. Would you mind closing your PR, creating a new branch, moving your changes to that branch, and opening a new PR from that branch?

  2. Also, we like to have our PR titles and commit messages follow the conventional commits format. Could you write the commit message on your new branch using a conventional commit style?

If you need more help with any of these steps, please let me know! 😄

@kaylareopelle
Copy link
Contributor

kaylareopelle commented Oct 28, 2024

Hi @Victorsesan! Thanks for your work on this! I'm going to respond to your latest comment on your old PR here. Until you open a new PR, let's communicate on this issue!

I'm sorry to hear you're having trouble with Bundler locally. Setting up Ruby on a local environment can be challenging.

To help get around this, we provide Docker containers through docker compose that can be used for development. Could you try following the instructions here and see if that helps? Keep in mind that on the latest version of the docker CLI, the command for compose is now docker compose, not docker-compose, so the instructions may be slightly outdated. Can you give that a try and let me know how it goes?

As far as the commit message goes, I think that looks pretty good!

@Victorsesan
Copy link
Contributor

@kaylareopelle This could work, thanks! I'm currently about to install the dependencies , but just wondering, since they didn't mention what type of service to run in the docker instructions, my guess was in the docker-compose.yml we have something like service: app: below so i tried

docker compose run app bundle install

and its been close to an hour now its still running, its been so long i feel like I'm running a bundle to build a docker app instead. Does it usually take this long, or more importantly did i run the right command? I'm just this close to get everything setup🚀

@kaylareopelle
Copy link
Contributor

Hi @Victorsesan, thanks for giving this a try! It shouldn't take an hour, though I suppose it could for the first time if the internet connection is slow.

As far as the command you shared, that should work, but it'll just run bundle install on the topmost Gemfile.

To test things for a specific instrumentation, I would recommend running docker compose run app instead. When Docker finishes loading, it'll put you into a bash session with all of the available services running, so you should be able to cd into a specific instrumentation and bundle/test things there.

@Victorsesan
Copy link
Contributor

@kaylareopelle Sadly went the same direction again just like the other we had before after many tries 🥲, just can't seem to pass the permission issue.
Screenshot 2024-11-01 030524
I even tried changing the permission with the commands in the last line but it still showed the same error like that above.

This was after i had successfully had docker compose run app completed and later on started the docker bundle exec rake test

Screenshot 2024-11-01 032026

@kaylareopelle
Copy link
Contributor

kaylareopelle commented Nov 1, 2024

I appreciate you continuing to give this a try, @Victorsesan! Thank you for the screenshots.

It looks like the bundle install --gemfile Gemfile command is being run in your main shell, rather than in a bash session inside the docker container. This may be why the path problems continue to happen.

You could try one of the following:

  1. If you use docker compose run app bundle exec rake test, all future commands should also begin with docker compose run app, to make sure they are executed inside the docker container rather than directly on your machine.

  2. Recommended If you run docker compose run app, you should see something like this after all the services spin up:

Screenshot 2024-11-01 at 2 55 10 PM

Running your commands within the /app$ prompt will run them within the docker container, which should give you access to bundler without permissions issues.

Also, to run the tests, you'll need to be in the directory for a specific instrumentation. Right now, it looks like the commands are being run from the topmost folder in the repository which does not have any tests.

If you take the second approach, within the docker container bash session, you could run the tests using:

<container_sha>: /app$ cd instrumentation/http_client
<container_sha>: /app/instrumentation/http_client$ bundle install
<container_sha>: /app/instrumentation/http_client$ bundle exec appraisal install # this is to install dependencies specific to the test suite
<container_sha>: /app/instrumentation/http_client$ bundle exec appraisal rake test

@Victorsesan
Copy link
Contributor

Finally i succeeded🎉!! @kaylareopelle , after days of trying with continuous fails and errors finally seeing this test pass feels like i just won a lottery fr
Screenshot 2024-11-02 003555

Alright then, hopefully that was a good test though 😅, i can't help but feel like something is off still with the Warnings and all, looking forward to know your take on this thanks . To the next step i will be opening my PR now with my new feature branch and add the commits as directed.

Also just wondering is it okay if we can update the contrib.md with some of the test process we've gone through which aren't documented yet? most especially a way to pass the permission errors which i have notice are found in all of the test , not only in docker but in robocop too. I will be happy to help add some few pointers and you review, but if not necessary fine still.

@kaylareopelle
Copy link
Contributor

Yay!! Congratulations! 🎉 🎉

Those warnings are related to the code within the HTTPClient gem itself, so we don't have control over them. The Ruby language is trying to be helpful and letting us know about the state of some variables that might have unexpected behavior.

Updating the documentation would be great! Feel free to open a PR or an issue to update the content to help others who encounter these problems in the future!

Victorsesan added a commit to Victorsesan/opentelemetry-ruby-contrib that referenced this issue Nov 9, 2024
Victorsesan added a commit to Victorsesan/opentelemetry-ruby-contrib that referenced this issue Nov 9, 2024
Victorsesan added a commit to Victorsesan/opentelemetry-ruby-contrib that referenced this issue Nov 17, 2024
arielvalentin added a commit that referenced this issue Nov 24, 2024
* Main
Created a readable constant in 8 files to freeze ranges 100..399 .

Relate to #1172

* refactor: Create a readable constant in 8 files to freeze ranges 100..399 .

Reviewed-by: kaylareopelle
Refs: #1172

* refactor: Fix rubocop ruby linter failures
Reviewed-by: kaylareopelle
Refs: #1172

* refactor: Fix rubocop ruby linter failures
Reviewed-by: kaylareopelle
Refs: #1172

---------

Co-authored-by: Kayla Reopelle <87386821+kaylareopelle@users.noreply.github.com>
Co-authored-by: Ariel Valentin <arielvalentin@users.noreply.github.com>
Copy link
Contributor

github-actions bot commented Dec 6, 2024

👋 This issue has been marked as stale because it has been open with no activity. You can: comment on the issue or remove the stale label to hold stale off for a while, add the keep label to hold stale off permanently, or do nothing. If you do nothing this issue will be closed eventually by the stale bot.

@github-actions github-actions bot added the stale Marks an issue/PR stale label Dec 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers stale Marks an issue/PR stale
Projects
None yet
Development

No branches or pull requests

3 participants