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

refactor: Freeze all range objects #1172 #1222

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

Victorsesan
Copy link

@Victorsesan Victorsesan commented Nov 2, 2024

Ref #1172

Victorsesan and others added 3 commits October 19, 2024 04:25
Created a readable constant in 8 files to freeze ranges 100..399 .

Relate to open-telemetry#1172
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.

@open-telemetry/ruby-contrib-approvers now that I'm looking at this I'm wondering if there is an opportunity to extract status setter helper method rather than defining a range per http instrumentation and implementing the same logic in each instrumentation separately.

Something like this

Semconv::Http::Client.set_status(span, http_status_code)

Which would then set the span status based on the http status code falling in the range of bad client status code.

That would reduce the number of places we would need to update when satisfying the specification.

Maybe that could be a follow up PR and this perf refactoring is a first step?

@kaylareopelle
Copy link
Contributor

@open-telemetry/ruby-contrib-approvers now that I'm looking at this I'm wondering if there is an opportunity to extract status setter helper method rather than defining a range per http instrumentation and implementing the same logic in each instrumentation separately.

Something like this

Semconv::Http::Client.set_status(span, http_status_code)

Which would then set the span status based on the http status code falling in the range of bad client status code.

That would reduce the number of places we would need to update when satisfying the specification.

Maybe that could be a follow up PR and this perf refactoring is a first step?

@arielvalentin - I like that idea! My vote would be to keep this refactoring as a first step and open that up in a follow-up PR.

@kaylareopelle kaylareopelle changed the title Freeze all range objects #1172 refactor: Freeze all range objects #1172 Nov 5, 2024
@kaylareopelle
Copy link
Contributor

Hi @Victorsesan! Thanks for re-opening this PR!

It looks like there are a few rubocop (Ruby linter) failures on your changes.

The general message is:

Running RuboCop...
RuboCop failed!
Inspecting 17 files
.........C.......

Offenses:

lib/opentelemetry/instrumentation/http/patches/client.rb:14:39: C: [Correctable] Style/RedundantFreeze: Do not freeze immutable objects, as freezing them has no effect.
          HTTP_STATUS_SUCCESS_RANGE = (100..399).freeze

I think the solution is to remove .freeze since the constant makes the range immutable.

If you'd like to run rubocop locally to test yourself, you can do so using:

docker compose run app
<container_sha>: /app$ cd instrumentation/http_client
<container_sha>: /app/instrumentation/http_client$ bundle install
<container_sha>: /app/instrumentation/http_client$ bundle exec rubocop

@Victorsesan
Copy link
Author

Victorsesan commented Nov 9, 2024

Thanks very much for reviewing @kaylareopelle . I have taken a look at the failures again from my end and have them sorted. Some end-of-line characters & carriage return test failures were also found which i converted with dos2unix and ran bundle exec rubocop --autocorrect on them to ensure all the offense in some files were fixed, so we can have some few modification/corrections shown in some files after the test was carried out. Hopefully it was for the best , but if these additional fix aren't needed i will have them regress asap.
Edit: Also very much open to help with any suggestions if needed. Thanks for your time

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.

3 participants