Sha256: a845b2fe178c081ce004203c8cd12819f32fe83f1650b69677d1679d5f11a53f

Contents?: true

Size: 1.34 KB

Versions: 17

Compression:

Stored size: 1.34 KB

Contents

# frozen_string_literal: true

module WCC::Contentful
  module Instrumentation
    extend ActiveSupport::Concern

    def _instrumentation_event_prefix
      @_instrumentation_event_prefix ||=
        # WCC::Contentful => contentful.wcc
        '.' + (is_a?(Class) || is_a?(Module) ? self : self.class) # rubocop:disable Style/StringConcatenation
          .name.parameterize.split('-').reverse.join('.')
    end

    attr_writer :_instrumentation

    def _instrumentation
      # look for per-instance instrumentation then try class level
      @_instrumentation || self.class._instrumentation
    end

    included do
      protected

      def _instrument(name, payload = {}, &block)
        name += _instrumentation_event_prefix
        _instrumentation&.instrument(name, payload, &block)
      end
    end

    class_methods do
      attr_writer :_instrumentation

      def _instrumentation
        @_instrumentation ||
          # try looking up the class heierarchy
          superclass.try(:_instrumentation) ||
          # default to global
          WCC::Contentful::Services.instance&.instrumentation ||
          ActiveSupport::Notifications
      end
    end

    class << self
      def instrument(name, payload = {}, &block)
        WCC::Contentful::Services.instance
          .instrumentation.instrument(name, payload, &block)
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
wcc-contentful-1.7.2 lib/wcc/contentful/instrumentation.rb
wcc-contentful-1.7.1 lib/wcc/contentful/instrumentation.rb
wcc-contentful-1.7.0 lib/wcc/contentful/instrumentation.rb
wcc-contentful-1.6.2 lib/wcc/contentful/instrumentation.rb
wcc-contentful-1.6.1 lib/wcc/contentful/instrumentation.rb
wcc-contentful-1.6.0 lib/wcc/contentful/instrumentation.rb
wcc-contentful-1.5.1 lib/wcc/contentful/instrumentation.rb
wcc-contentful-1.5.0 lib/wcc/contentful/instrumentation.rb
wcc-contentful-1.5.0.rc1 lib/wcc/contentful/instrumentation.rb
wcc-contentful-1.4.0 lib/wcc/contentful/instrumentation.rb
wcc-contentful-1.4.0.rc3 lib/wcc/contentful/instrumentation.rb
wcc-contentful-1.4.0.rc2 lib/wcc/contentful/instrumentation.rb
wcc-contentful-1.3.2 lib/wcc/contentful/instrumentation.rb
wcc-contentful-1.4.0.rc1 lib/wcc/contentful/instrumentation.rb
wcc-contentful-1.3.1 lib/wcc/contentful/instrumentation.rb
wcc-contentful-1.3.0 lib/wcc/contentful/instrumentation.rb
wcc-contentful-1.2.1 lib/wcc/contentful/instrumentation.rb