Sha256: 72a9945cc9c72b2d9c65766087d3a661f8ddc19395490973553769235fed61ca

Contents?: true

Size: 1.24 KB

Versions: 8

Compression:

Stored size: 1.24 KB

Contents

# frozen_string_literal: true

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

module OpenTelemetry
  module Instrumentation
    module Grape
      # The Instrumentation class contains logic to detect and install the Grape instrumentation
      class Instrumentation < OpenTelemetry::Instrumentation::Base
        # Minimum Grape version needed for compatibility with this instrumentation
        MINIMUM_VERSION = Gem::Version.new('1.2.0')

        install do |_config|
          install_rack_instrumentation
          require_dependencies
          subscribe
        end

        present do
          defined?(::Grape)
        end

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

        option :ignored_events, default: [], validate: :array

        private

        def gem_version
          Gem::Version.new(::Grape::VERSION)
        end

        def install_rack_instrumentation
          OpenTelemetry::Instrumentation::Rack::Instrumentation.instance.install({})
        end

        def require_dependencies
          require_relative 'subscriber'
        end

        def subscribe
          Subscriber.subscribe
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
opentelemetry-instrumentation-grape-0.1.7 lib/opentelemetry/instrumentation/grape/instrumentation.rb
opentelemetry-instrumentation-grape-0.1.6 lib/opentelemetry/instrumentation/grape/instrumentation.rb
opentelemetry-instrumentation-grape-0.1.5 lib/opentelemetry/instrumentation/grape/instrumentation.rb
opentelemetry-instrumentation-grape-0.1.4 lib/opentelemetry/instrumentation/grape/instrumentation.rb
opentelemetry-instrumentation-grape-0.1.3 lib/opentelemetry/instrumentation/grape/instrumentation.rb
opentelemetry-instrumentation-grape-0.1.2 lib/opentelemetry/instrumentation/grape/instrumentation.rb
opentelemetry-instrumentation-grape-0.1.1 lib/opentelemetry/instrumentation/grape/instrumentation.rb
opentelemetry-instrumentation-grape-0.1.0 lib/opentelemetry/instrumentation/grape/instrumentation.rb