Skip to content

Auto subscribe to notifications #2375

Description

@thompson-tomo

The active support gem is currently lacking the ability to auto subscribe to notifications, this should be changed to bring it in alignment with other gems.

For reference the example shows the process as:

tracer = OpenTelemetry.tracer_provider.tracer('my_app_or_gem', '0.1.0')
OpenTelemetry::Instrumentation::ActiveSupport.subscribe(tracer, 'bar.foo')
ActiveSupport::Notifications.instrument('bar.foo', extra: 'context')

This should be consolidated down to just

ActiveSupport::Notifications.instrument('bar.foo', extra: 'context')

And to do so we should extend the install to encompass

module OpenTelemetry
  module Instrumentation
    module ActiveSupport
      class Instrumentation < OpenTelemetry::Instrumentation::Base
        install do |_config|
          tracer = OpenTelemetry.tracer_provider.tracer(
            'opentelemetry-instrumentation-activesupport',
            VERSION
          )

          ::OpenTelemetry::Instrumentation::ActiveSupport.subscribe(
            tracer,
            /.*/ # or specific patterns
          )
        end
      end
    end
  end
end

To ensure ease of convenience, we should use an include pattern of * & an exclude of the notifications used by other otel gems.

Metadata

Metadata

Assignees

No one assigned

    Fields

    No fields configured for Feature.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions