Sha256: f7443afa98740010cd6d4d3665fb956404d0d29d9ff583e15f8232ee3c0ec75c

Contents?: true

Size: 1.72 KB

Versions: 11

Compression:

Stored size: 1.72 KB

Contents

# frozen_string_literal: true

# Copyright The OpenTelemetry Authors
#
# SPDX-License-Identifier: Apache-2.0
module OpenTelemetry
  module Instrumentation
    module ActiveRecord
      module Patches
        # Module to prepend to ActiveRecord::Base for instrumentating
        # insert/upsert class methods added in Rails 6.0
        module PersistenceInsertClassMethods
          def self.prepended(base)
            class << base
              prepend ClassMethods
            end
          end

          # Contains ActiveRecord::Persistence::ClassMethods to be patched
          module ClassMethods
            ruby2_keywords def insert(*args)
              tracer.in_span("#{self}.insert") do
                super(*args)
              end
            end

            ruby2_keywords def insert_all(*args)
              tracer.in_span("#{self}.insert_all") do
                super(*args)
              end
            end

            ruby2_keywords def insert!(*args)
              tracer.in_span("#{self}.insert!") do
                super(*args)
              end
            end

            ruby2_keywords def insert_all!(*args)
              tracer.in_span("#{self}.insert_all!") do
                super(*args)
              end
            end

            ruby2_keywords def upsert(*args)
              tracer.in_span("#{self}.upsert") do
                super(*args)
              end
            end

            ruby2_keywords def upsert_all(*args)
              tracer.in_span("#{self}.upsert_all") do
                super(*args)
              end
            end

            private

            def tracer
              ActiveRecord::Instrumentation.instance.tracer
            end
          end
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
opentelemetry-instrumentation-active_record-0.7.2 lib/opentelemetry/instrumentation/active_record/patches/persistence_insert_class_methods.rb
opentelemetry-instrumentation-active_record-0.7.1 lib/opentelemetry/instrumentation/active_record/patches/persistence_insert_class_methods.rb
opentelemetry-instrumentation-active_record-0.7.0 lib/opentelemetry/instrumentation/active_record/patches/persistence_insert_class_methods.rb
opentelemetry-instrumentation-active_record-0.6.3 lib/opentelemetry/instrumentation/active_record/patches/persistence_insert_class_methods.rb
opentelemetry-instrumentation-active_record-0.6.2 lib/opentelemetry/instrumentation/active_record/patches/persistence_insert_class_methods.rb
opentelemetry-instrumentation-active_record-0.6.1 lib/opentelemetry/instrumentation/active_record/patches/persistence_insert_class_methods.rb
opentelemetry-instrumentation-active_record-0.6.0 lib/opentelemetry/instrumentation/active_record/patches/persistence_insert_class_methods.rb
opentelemetry-instrumentation-active_record-0.5.0 lib/opentelemetry/instrumentation/active_record/patches/persistence_insert_class_methods.rb
opentelemetry-instrumentation-active_record-0.4.1 lib/opentelemetry/instrumentation/active_record/patches/persistence_insert_class_methods.rb
opentelemetry-instrumentation-active_record-0.4.0 lib/opentelemetry/instrumentation/active_record/patches/persistence_insert_class_methods.rb
opentelemetry-instrumentation-active_record-0.3.0 lib/opentelemetry/instrumentation/active_record/patches/persistence_insert_class_methods.rb