-
Notifications
You must be signed in to change notification settings - Fork 181
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: Add ActiveStorage instrumentation #1313
base: main
Are you sure you want to change the base?
feat: Add ActiveStorage instrumentation #1313
Conversation
7a91acc
to
641f823
Compare
721c056
to
5959af8
Compare
5959af8
to
cf7ee82
Compare
@@ -27,6 +27,7 @@ Gem::Specification.new do |spec| | |||
spec.required_ruby_version = '>= 3.0' | |||
|
|||
spec.add_dependency 'opentelemetry-instrumentation-active_model_serializers', '~> 0.21.0' | |||
spec.add_dependency 'opentelemetry-instrumentation-active_storage', '~> 0.0.0' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's best to include this instrumentation to -all and -rails once this pr gets merged and released (other part of code that is related to this applies)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that's a good call. However, if this is added to -rails, I don't think it also has to be added to -all, because -all requires -rails.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make sense. In d6979a7 , I removed -active_storage from -all .
I'll create another PR to -active_storage this to -rails after this PR is relesed.
when /^7\./ | ||
ActiveStorage::Current.url_options = { host: 'http://example.com' } | ||
when /^8\./ | ||
ActiveStorage::Current.url_options = { host: 'http://example.com' } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: why they need to be on separate line?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your advice, I fixed unnecessary conditions in bfae8c7 !
module OpenTelemetry | ||
module Instrumentation | ||
module ActiveStorage | ||
VERSION = '0.0.0' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's make it '0.1.0' as initial release version.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed the version in d6979a7
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, @ymtdzzz! I'm looking forward to OTel to offering ActiveStorage support.
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
%w[6.1.0 7.0.0 7.1.0].each do |version| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
%w[6.1.0 7.0.0 7.1.0].each do |version| | |
%w[7.0.0 7.1.0].each do |version| |
We recently removed support for Rails 6.1. See: #1231
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for pointing that out! I fixed in c6ea05f
module OpenTelemetry | ||
module Instrumentation | ||
module ActiveStorage | ||
# The {OpenTelemetry::Instrumentation::ActiveStorage::Instrumentation} class contains logic to detect and install the ActiveStorage instrumentation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent docs! Thank you!!
# }) | ||
# end | ||
class Instrumentation < OpenTelemetry::Instrumentation::Base | ||
MINIMUM_VERSION = Gem::Version.new('6.1.0') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like I mentioned above, our new minimum Rails version is 7.0 :)
MINIMUM_VERSION = Gem::Version.new('6.1.0') | |
MINIMUM_VERSION = Gem::Version.new('7.0.0') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is also fixed in c6ea05f
# ## Configuration keys and options | ||
# | ||
# ### `:disallowed_notification_payload_keys` | ||
# |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like the default is missing on just this config:
# | |
# | |
# - `array` **default** `[]` | |
# |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, fixed in 613e1b6
spec.add_development_dependency 'opentelemetry-sdk', '~> 1.1' | ||
spec.add_development_dependency 'opentelemetry-test-helpers', '~> 0.3' | ||
spec.add_development_dependency 'rake', '~> 13.0' | ||
spec.add_development_dependency 'rubocop', '~> 1.69.1' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're about to merge a PR that'll bump Rubocop to 1.70.0:
spec.add_development_dependency 'rubocop', '~> 1.69.1' | |
spec.add_development_dependency 'rubocop', '~> 1.70.0' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for letting me know, I've matched the version with other packages!
b98fadf
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
ENV['RAILS_ENV'] = 'test' | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We recently had to add explicit requires to 'logger'
in the test helpers for some Rails-related libraries to avoid uninitialized constant errors: #1345
Rails added logger
as a dependency in Rails 7.1 and above, but since we still support 7.0, we need to require it here.
require 'logger' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That makes sense, I added explicit logger
require. da97949
when /^6\.1/ | ||
ActiveStorage::Current.host = 'http://example.com' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cleanup related to dropping 6.1 support:
when /^6\.1/ | |
ActiveStorage::Current.host = 'http://example.com' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks, this is also fixed in c6ea05f !
@@ -27,6 +27,7 @@ Gem::Specification.new do |spec| | |||
spec.required_ruby_version = '>= 3.0' | |||
|
|||
spec.add_dependency 'opentelemetry-instrumentation-active_model_serializers', '~> 0.21.0' | |||
spec.add_dependency 'opentelemetry-instrumentation-active_storage', '~> 0.0.0' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that's a good call. However, if this is added to -rails, I don't think it also has to be added to -all, because -all requires -rails.
- name: Install ImageMagick for active_storage testing | ||
if: "${{ inputs.gem == 'opentelemetry-instrumentation-active_storage' }}" | ||
shell: bash | ||
run: sudo apt update && sudo apt install -y imagemagick |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for adding this service here! We also have a docker-compose.yml
to allow developers to run services locally. Would you mind adding ImageMagick to that file too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As you said, the test for ActiveStorage instrumentation did not pass due to the lack of ImageMagick inside the container. So I added it to the Dockerfile
and confirmed that the test passed. ed63c88
❯ docker compose run app /bin/ash
/app $ cd instrumentation/active_storage/
/app/instrumentation/active_storage $ bundle install
/app/instrumentation/active_storage $ bundle exec appraisal install
/app/instrumentation/active_storage $ bundle exec appraisal rake test
...
# Running:
..........................
Finished in 0.976136s, 26.6356 runs/s, 101.4203 assertions/s.
26 runs, 99 assertions, 0 failures, 0 errors, 0 skips
…th other packages
…ve active_storage from all
Description
Adding support for instrumenting ActiveStorage using ActiveSupport::Notification.
related: #1307
Test
Example script
With other instrumentations in your Rails app
Without ActiveStorage instrumentation
With ActiveStorage instrumentation