OpenTelemetry ActiveStorage Instrumentation

The ActiveStorage instrumentation is a community-maintained instrumentation for the ActiveStorage portion of the Ruby on Rails web-application framework.

How do I get started?

Install the gem using:

# Install just the ActiveStorage instrumentation
gem install opentelemetry-instrumentation-active_storage
# Install the ActiveStorage instrumentation along with the rest of the Rails-related instrumentation
gem install opentelemetry-instrumentation-rails

Or, if you use bundler, include opentelemetry-instrumentation-active_storage in your Gemfile.

Usage

To use the instrumentation, call use with the name of the instrumentation:

OpenTelemetry::SDK.configure do |c|
  # Use only the ActiveStorage instrumentation
  c.use 'OpenTelemetry::Instrumentation::ActiveStorage'
  # Use the ActiveStorage instrumentation along with the rest of the Rails-related instrumentation
  c.use 'OpenTelemetry::Instrumentation::Rails'
end

Alternatively, you can also call use_all to install all the available instrumentation.

OpenTelemetry::SDK.configure do |c|
  c.use_all
end

Active Support Instrumentation

This instrumentation relies entirely on ActiveSupport::Notifications and registers a custom Subscriber that listens to relevant events to report as spans.

See the table below for details of what Rails Framework Hook Events are recorded by this instrumentation:

Event Name Creates Span? Notes
preview.active_storage :white_check_mark: Creates an internal span
transform.active_storage :white_check_mark: Creates an internal span
analyze.active_storage :white_check_mark: Creates an internal span
service_upload.active_storage :white_check_mark: Creates an internal span
service_streaming_download.active_storage :white_check_mark: Creates an internal span
service_download_chunk.active_storage :white_check_mark: Creates an internal span
service_download.active_storage :white_check_mark: Creates an internal span
service_delete.active_storage :white_check_mark: Creates an internal span
service_delete_prefixed.active_storage :white_check_mark: Creates an internal span
service_exist.active_storage :white_check_mark: Creates an internal span
service_url.active_storage :white_check_mark: Creates an internal span
service_update_metadata.active_storage :white_check_mark: Creates an internal span

Options

ActiveStorage instrumentation doesn't expose secure tokens and urls by default, but if they are needed, simply use :key and :url option:

OpenTelemetry::SDK.configure do |c|
  c.use 'OpenTelemetry::Instrumentation::ActiveStorage', { key: :include, url: :include }
end

Semantic Conventions

Internal spans are named using the name of the ActiveSupport event that was provided (e.g. service_upload.active_storage).

Attributes attached to each event payload are prefixed with active_storage. (e.g. active_storage.checksum).

Examples

Example usage can be seen in the ./example/trace_demonstration.rb file

How can I get involved?

The opentelemetry-instrumentation-active_storage gem source is on github, along with related gems including opentelemetry-api and opentelemetry-sdk.

The OpenTelemetry Ruby gems are maintained by the OpenTelemetry Ruby special interest group (SIG). You can get involved by joining us on our GitHub Discussions, Slack Channel or attending our weekly meeting. See the meeting calendar for dates and times. For more information on this and other language SIGs, see the OpenTelemetry community page.

License

The opentelemetry-instrumentation-active_storage gem is distributed under the Apache 2.0 license. See LICENSE for more information.