Sha256: 17de16afbb94cee30e334fadfbe141f13174b4401d6afb71f60cc36872af4465

Contents?: true

Size: 1.78 KB

Versions: 5

Compression:

Stored size: 1.78 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
            def insert(attributes, returning: nil, unique_by: nil)
              tracer.in_span("#{self}.insert") do
                super
              end
            end

            def insert_all(attributes, returning: nil, unique_by: nil)
              tracer.in_span("#{self}.insert_all") do
                super
              end
            end

            def insert!(attributes, returning: nil)
              tracer.in_span("#{self}.insert!") do
                super
              end
            end

            def insert_all!(attributes, returning: nil)
              tracer.in_span("#{self}.insert_all!") do
                super
              end
            end

            def upsert(attributes, returning: nil, unique_by: nil)
              tracer.in_span("#{self}.upsert") do
                super
              end
            end

            def upsert_all(attributes, returning: nil, unique_by: nil)
              tracer.in_span("#{self}.upsert_all") do
                super
              end
            end

            private

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

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
opentelemetry-instrumentation-active_record-0.2.2 lib/opentelemetry/instrumentation/active_record/patches/persistence_insert_class_methods.rb
opentelemetry-instrumentation-active_record-0.2.1 lib/opentelemetry/instrumentation/active_record/patches/persistence_insert_class_methods.rb
opentelemetry-instrumentation-active_record-0.2.0 lib/opentelemetry/instrumentation/active_record/patches/persistence_insert_class_methods.rb
opentelemetry-instrumentation-active_record-0.1.1 lib/opentelemetry/instrumentation/active_record/patches/persistence_insert_class_methods.rb
opentelemetry-instrumentation-active_record-0.1.0 lib/opentelemetry/instrumentation/active_record/patches/persistence_insert_class_methods.rb