Sha256: 19f325379c459161a031344f11cfd205f241d1a773ca7a0daad68baae9f49b52

Contents?: true

Size: 1.23 KB

Versions: 10

Compression:

Stored size: 1.23 KB

Contents

# frozen_string_literal: true

# Copyright The OpenTelemetry Authors
#
# SPDX-License-Identifier: Apache-2.0

module OpenTelemetry
  module Instrumentation
    module ActiveModelSerializers
      # Instrumentation class that detects and installs the ActiveModelSerializers instrumentation
      class Instrumentation < OpenTelemetry::Instrumentation::Base
        MINIMUM_VERSION = Gem::Version.new('0.10.0')

        install do |_config|
          require_dependencies
          register_event_handler
        end

        present do
          !defined?(::ActiveModelSerializers).nil?
        end

        compatible do
          !defined?(::ActiveSupport::Notifications).nil? && gem_version >= MINIMUM_VERSION
        end

        private

        def gem_version
          Gem.loaded_specs['active_model_serializers'].version
        end

        def require_dependencies
          require_relative 'event_handler'
        end

        def register_event_handler
          ActiveSupport::Notifications.subscribe(event_name) do |_name, start, finish, _id, payload|
            EventHandler.handle(start, finish, payload)
          end
        end

        def event_name
          'render.active_model_serializers'
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
opentelemetry-instrumentation-active_model_serializers-0.18.4 lib/opentelemetry/instrumentation/active_model_serializers/instrumentation.rb
opentelemetry-instrumentation-active_model_serializers-0.18.3 lib/opentelemetry/instrumentation/active_model_serializers/instrumentation.rb
opentelemetry-instrumentation-active_model_serializers-0.18.2 lib/opentelemetry/instrumentation/active_model_serializers/instrumentation.rb
opentelemetry-instrumentation-active_model_serializers-0.18.1 lib/opentelemetry/instrumentation/active_model_serializers/instrumentation.rb
opentelemetry-instrumentation-active_model_serializers-0.18.0 lib/opentelemetry/instrumentation/active_model_serializers/instrumentation.rb
opentelemetry-instrumentation-active_model_serializers-0.17.0 lib/opentelemetry/instrumentation/active_model_serializers/instrumentation.rb
opentelemetry-instrumentation-active_model_serializers-0.16.0 lib/opentelemetry/instrumentation/active_model_serializers/instrumentation.rb
opentelemetry-instrumentation-active_model_serializers-0.15.0 lib/opentelemetry/instrumentation/active_model_serializers/instrumentation.rb
opentelemetry-instrumentation-active_model_serializers-0.14.0 lib/opentelemetry/instrumentation/active_model_serializers/instrumentation.rb
opentelemetry-instrumentation-active_model_serializers-0.13.0 lib/opentelemetry/instrumentation/active_model_serializers/instrumentation.rb