Sha256: f8788dde15396c6edba23474551f6675699ccd56306b42c86c06b965669c7fd8

Contents?: true

Size: 1.47 KB

Versions: 18

Compression:

Stored size: 1.47 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 instrumentation
        module PersistenceClassMethods
          def self.prepended(base)
            class << base
              prepend ClassMethods
            end
          end

          # Contains ActiveRecord::Persistence::ClassMethods to be patched
          module ClassMethods
            def create(attributes = nil, &block)
              tracer.in_span("#{self}.create") do
                super
              end
            end

            def create!(attributes = nil, &block)
              tracer.in_span("#{self}.create!") do
                super
              end
            end

            def update(id = :all, attributes) # rubocop:disable Style/OptionalArguments
              tracer.in_span("#{self}.update") do
                super
              end
            end

            def destroy(id)
              tracer.in_span("#{self}.destroy") do
                super
              end
            end

            def delete(id_or_array)
              tracer.in_span("#{self}.delete") do
                super
              end
            end

            private

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

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
opentelemetry-instrumentation-active_record-0.8.1 lib/opentelemetry/instrumentation/active_record/patches/persistence_class_methods.rb
opentelemetry-instrumentation-active_record-0.8.0 lib/opentelemetry/instrumentation/active_record/patches/persistence_class_methods.rb
opentelemetry-instrumentation-active_record-0.7.4 lib/opentelemetry/instrumentation/active_record/patches/persistence_class_methods.rb
opentelemetry-instrumentation-active_record-0.7.3 lib/opentelemetry/instrumentation/active_record/patches/persistence_class_methods.rb
opentelemetry-instrumentation-active_record-0.7.2 lib/opentelemetry/instrumentation/active_record/patches/persistence_class_methods.rb
opentelemetry-instrumentation-active_record-0.7.1 lib/opentelemetry/instrumentation/active_record/patches/persistence_class_methods.rb
opentelemetry-instrumentation-active_record-0.7.0 lib/opentelemetry/instrumentation/active_record/patches/persistence_class_methods.rb
opentelemetry-instrumentation-active_record-0.6.3 lib/opentelemetry/instrumentation/active_record/patches/persistence_class_methods.rb
opentelemetry-instrumentation-active_record-0.6.2 lib/opentelemetry/instrumentation/active_record/patches/persistence_class_methods.rb
opentelemetry-instrumentation-active_record-0.6.1 lib/opentelemetry/instrumentation/active_record/patches/persistence_class_methods.rb
opentelemetry-instrumentation-active_record-0.6.0 lib/opentelemetry/instrumentation/active_record/patches/persistence_class_methods.rb
opentelemetry-instrumentation-active_record-0.5.0 lib/opentelemetry/instrumentation/active_record/patches/persistence_class_methods.rb
opentelemetry-instrumentation-active_record-0.4.1 lib/opentelemetry/instrumentation/active_record/patches/persistence_class_methods.rb
opentelemetry-instrumentation-active_record-0.4.0 lib/opentelemetry/instrumentation/active_record/patches/persistence_class_methods.rb
opentelemetry-instrumentation-active_record-0.3.0 lib/opentelemetry/instrumentation/active_record/patches/persistence_class_methods.rb
opentelemetry-instrumentation-active_record-0.2.2 lib/opentelemetry/instrumentation/active_record/patches/persistence_class_methods.rb
opentelemetry-instrumentation-active_record-0.2.1 lib/opentelemetry/instrumentation/active_record/patches/persistence_class_methods.rb
opentelemetry-instrumentation-active_record-0.2.0 lib/opentelemetry/instrumentation/active_record/patches/persistence_class_methods.rb