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

feat: Strip Rails (.:format) suffix from http.route #1375

Merged
merged 4 commits into from
Jan 30, 2025

Conversation

akahn
Copy link
Contributor

@akahn akahn commented Jan 29, 2025

In our OpenTelemetry spans, all http.route values end in (.:format). This is unsightly and does not help when diagnosing an issue using traces. It also stands out as different from the http.route produced by other language's OTel SDKs, which only include parts of the URL path itself.

With this change, we strip this suffix from http.route, just like we are already doing for the span name.

Copy link

linux-foundation-easycla bot commented Jan 29, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

@akahn akahn changed the title Strip Rails (.:format) suffix from http.route Strip Rails (.:format) suffix from http.route Jan 29, 2025
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.

I have left a request to use chomp as opposed to gsub to achieve this.

Please also make sure to review the contributing guide that requests you use conventional commit format for the PR title and individual commits.

I am also surprised that tests passed for this!

If you are able to help us track down why there were no test failures or updates accompanied with this change that would be grately appreciated.

@akahn
Copy link
Contributor Author

akahn commented Jan 29, 2025

Thanks for the review, @arielvalentin!

Happy to make that change, and make sure there is test coverage for attributes. I tried to run the tests according to the instructions in the README but got the error below. Is there a particular version of Ruby I need to be running? Any help would be appreciated.

❯ bundle exec rake
/Users/alex.kahn/Codes/opentelemetry-ruby-contrib/instrumentation/action_pack/test/test_helper.rb:7: warning: logger was loaded from the standard library, but will no longer be part of the default gems starting from Ruby 3.5.0.
You can add logger to your Gemfile or gemspec to silence this warning.
/Users/alex.kahn/.gem/ruby/3.4.1/gems/pry-0.14.2/lib/pry/command_state.rb:3: warning: ostruct was loaded from the standard library, but will no longer be part of the default gems starting from Ruby 3.5.0.
You can add ostruct to your Gemfile or gemspec to silence this warning.
/Users/alex.kahn/.rubies/ruby-3.4.1/lib/ruby/3.4.0/readline.rb:4: warning: reline was loaded from the standard library, but will no longer be part of the default gems starting from Ruby 3.5.0.
You can add reline to your Gemfile or gemspec to silence this warning.
/Users/alex.kahn/.gem/ruby/3.4.1/gems/byebug-11.1.3/lib/byebug/commands/irb.rb:4: warning: irb was loaded from the standard library, but will no longer be part of the default gems starting from Ruby 3.5.0.
You can add irb to your Gemfile or gemspec to silence this warning.
/Users/alex.kahn/.rubies/ruby-3.4.1/lib/ruby/3.4.0/bundled_gems.rb:82:in 'Kernel.require': cannot load such file -- rack/test (LoadError)
	from /Users/alex.kahn/.rubies/ruby-3.4.1/lib/ruby/3.4.0/bundled_gems.rb:82:in 'block (2 levels) in Kernel#replace_require'
	from /Users/alex.kahn/Codes/opentelemetry-ruby-contrib/instrumentation/action_pack/test/test_helper.rb:13:in '<top (required)>'
	from /Users/alex.kahn/.rubies/ruby-3.4.1/lib/ruby/3.4.0/bundled_gems.rb:82:in 'Kernel.require'
	from /Users/alex.kahn/.rubies/ruby-3.4.1/lib/ruby/3.4.0/bundled_gems.rb:82:in 'block (2 levels) in Kernel#replace_require'
	from /Users/alex.kahn/Codes/opentelemetry-ruby-contrib/instrumentation/action_pack/test/opentelemetry/instrumentation/action_pack/handlers/action_controller_test.rb:7:in '<top (required)>'
	from /Users/alex.kahn/.rubies/ruby-3.4.1/lib/ruby/3.4.0/bundled_gems.rb:82:in 'Kernel.require'
	from /Users/alex.kahn/.rubies/ruby-3.4.1/lib/ruby/3.4.0/bundled_gems.rb:82:in 'block (2 levels) in Kernel#replace_require'
	from /Users/alex.kahn/.rubies/ruby-3.4.1/lib/ruby/gems/3.4.0/gems/rake-13.2.1/lib/rake/rake_test_loader.rb:21:in 'block in <main>'
	from /Users/alex.kahn/.rubies/ruby-3.4.1/lib/ruby/gems/3.4.0/gems/rake-13.2.1/lib/rake/rake_test_loader.rb:6:in 'Array#select'
	from /Users/alex.kahn/.rubies/ruby-3.4.1/lib/ruby/gems/3.4.0/gems/rake-13.2.1/lib/rake/rake_test_loader.rb:6:in '<main>'
rake aborted!
Command failed with status (1)
/Users/alex.kahn/.gem/ruby/3.4.1/bin/bundle:25:in 'Kernel#load'
/Users/alex.kahn/.gem/ruby/3.4.1/bin/bundle:25:in '<main>'
Tasks: TOP => default => test
(See full trace by running task with --trace)

@arielvalentin
Copy link
Collaborator

Time to update the README! 😿

The gems are executed using appraisal so try this instead:

bundle exec appraisal rake test

That will end up running several versions of Rails that we aim to support. If you want to focus on a specific version check out the appraisal docs for more info.

Thanks again for your help.

@akahn
Copy link
Contributor Author

akahn commented Jan 29, 2025

After running bundle exec appraisal to install the various Rails versions, I ran bundle exec appraisal rake test and got this error:

❯ bundle exec appraisal rake
>> BUNDLE_GEMFILE=/Users/alex.kahn/Codes/opentelemetry-ruby-contrib/instrumentation/action_pack/gemfiles/action_pack_7.0.0.gemfile bundle exec rake
/Users/alex.kahn/Codes/opentelemetry-ruby-contrib/instrumentation/action_pack/test/test_helper.rb:7: warning: logger was loaded from the standard library, but will no longer be part of the default gems starting from Ruby 3.5.0.
You can add logger to your Gemfile or gemspec to silence this warning.
/Users/alex.kahn/.gem/ruby/3.4.1/gems/activesupport-7.0.8.7/lib/active_support/core_ext/object/json.rb:229: warning: method redefined; discarding old as_json
/Users/alex.kahn/.rubies/ruby-3.4.1/lib/ruby/3.4.0/ipaddr.rb:231: warning: previous definition of as_json was here
/Users/alex.kahn/.gem/ruby/3.4.1/gems/activesupport-7.0.8.7/lib/active_support/notifications/fanout.rb:3: warning: mutex_m was loaded from the standard library, but is not part of the default gems starting from Ruby 3.4.0.
You can add mutex_m to your Gemfile or gemspec to silence this warning.
/Users/alex.kahn/.rubies/ruby-3.4.1/lib/ruby/3.4.0/bundled_gems.rb:82:in 'Kernel.require': cannot load such file -- mutex_m (LoadError)

I tried adding mutex_m as a dependency in the test section of the Gemfile, but got the same error. Any ideas?

@akahn akahn changed the title Strip Rails (.:format) suffix from http.route chore: Strip Rails (.:format) suffix from http.route Jan 29, 2025
@akahn akahn force-pushed the strip-rails-format-suffix branch from ee144f7 to 7b796a6 Compare January 29, 2025 19:26
@arielvalentin
Copy link
Collaborator

@akahn I have to admit, I am a little perplexed.

What version of Ruby and Bundler are you running?

@akahn
Copy link
Contributor Author

akahn commented Jan 29, 2025

❯ ruby -v
ruby 3.4.1 (2024-12-25 revision 48d4efcb85) +PRISM [arm64-darwin24]

❯ bundler -v
Bundler version 2.6.2

❯ env | grep RUBY
RUBY_ROOT=/Users/alex.kahn/.rubies/ruby-3.4.1
RUBYOPT=
RUBY_ENGINE=ruby
RUBY_VERSION=3.4.1

❯ env | grep GEM
GEM_ROOT=/Users/alex.kahn/.rubies/ruby-3.4.1/lib/ruby/gems/3.4.0
GEM_HOME=/Users/alex.kahn/.gem/ruby/3.4.1
GEM_PATH=/Users/alex.kahn/.gem/ruby/3.4.1:/Users/alex.kahn/.rubies/ruby-3.4.1/lib/ruby/gems/3.4.0

Edit: I've downgraded to Ruby 3.3.4, and now have this working.

@akahn
Copy link
Contributor Author

akahn commented Jan 29, 2025

If you are able to help us track down why there were no test failures or updates accompanied with this change that would be grately appreciated.

This is because there are no tests for the http.route attribute.

I've tried adding them but it seems that bundle exec appraisal rake test is only running tests with Rails 7.0.8.7, so the request.respond_to?(:route_uri_pattern) check never passes (and thus http.route isn't added at all). I'm printing Rails.version as the tests run in order to confirm this. Is it just an issue on my end, or do you get the same result?

@akahn
Copy link
Contributor Author

akahn commented Jan 29, 2025

I took a look at what the GitHub actions were doing and did the same by manually setting BUNDLE_GEMFILE before running the tests. (I had assumed that bundle exec appraisal rake test would run the test suite across all the relevant Rails versions, but maybe that's not quite right.) Anyways, I added a simple test case for http.route removing the format suffix.

@akahn akahn force-pushed the strip-rails-format-suffix branch from 91472bc to e89fe75 Compare January 29, 2025 23:40
@kaylareopelle
Copy link
Contributor

I had assumed that bundle exec appraisal rake test would run the test suite across all the relevant Rails versions, but maybe that's not quite right.

@akahn - I'm surprised that bundle exec appraisal rake test isn't running all the appraisals for you. That's working for me locally on Ruby 3.3.0.

All I ran from inside instrumentation/rails was:

bundle # to install the gemspec dependencies
bundle exec appraisal install
bundle exec appraisal rake test

I think it might be an issue on your machine, but I'm curious if others are running into the same problem.

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.

@arielvalentin @akahn, since this PR changes the value of an attribute, I'm leaning toward the conventional commit prefix being a feat instead of a chore. What do you think? Should this initiate a release?

@arielvalentin
Copy link
Collaborator

@arielvalentin @akahn, since this PR changes the value of an attribute, I'm leaning toward the conventional commit prefix being a feat instead of a chore. What do you think? Should this initiate a release?

I agree.

@arielvalentin
Copy link
Collaborator

I took a look at what the GitHub actions were doing and did the same by manually setting BUNDLE_GEMFILE before running the tests. (I had assumed that bundle exec appraisal rake test would run the test suite across all the relevant Rails versions, but maybe that's not quite right.) Anyways, I added a simple test case for http.route removing the format suffix.

The error is happening in Ruby 3.4 but our test matrix isn't up to date yet.

I have a separate PR to add test coverage here: #1347

For now I recommend running the tests with Ruby 3.3 if possible to get them running in your development environment.

@akahn akahn force-pushed the strip-rails-format-suffix branch from e89fe75 to ed04a56 Compare January 30, 2025 01:20
@akahn akahn changed the title chore: Strip Rails (.:format) suffix from http.route feat: Strip Rails (.:format) suffix from http.route Jan 30, 2025
@akahn akahn force-pushed the strip-rails-format-suffix branch from ed04a56 to 4fffe3a Compare January 30, 2025 01:22
@akahn
Copy link
Contributor Author

akahn commented Jan 30, 2025

Thanks for all the guidance. I've renamed the commit and PR to be feat.

@@ -58,6 +58,14 @@
_(span.attributes['code.function']).must_equal 'ok'
end

it 'strips (:format) from http.route' do
Copy link
Collaborator

Choose a reason for hiding this comment

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

this test can probably be consolidated with another one but I see why being explicit here is helpful.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks. I noticed the tests were a bit disjointed, but I thought I would leave that to the maintainers or someone more familiar with the project, and to a future PR.

There's an existing describe block for span naming, broken down by Rails version. Maybe there could be another one for span attributes, broken down by Rails version, that this could go in. Alternatively, there could be separate top-level blocks for Rails versions, each with naming and span sections within.

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.

Thanks, @akahn!

@kaylareopelle kaylareopelle merged commit 1e9853a into open-telemetry:main Jan 30, 2025
59 checks passed
@github-actions github-actions bot mentioned this pull request Jan 30, 2025
@akahn
Copy link
Contributor Author

akahn commented Jan 30, 2025

My pleasure @kaylareopelle. What is the release schedule for this gem? My team would love to get this running in our production app.

@akahn akahn deleted the strip-rails-format-suffix branch January 30, 2025 19:55
@kaylareopelle
Copy link
Contributor

Hi @akahn! We generally release on Tuesdays near the time of our SIG meeting. Unless someone can fit it in sooner, expect a new release then.

@kaylareopelle
Copy link
Contributor

Hi @akahn - This code has been released! You can access it through:

  • opentelemetry-instrumentation-action_pack 0.12.0
  • opentelemetry-instrumentation-rails 0.36.0
  • opentelemetry-instrumentation-all 0.73.0

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