Sha256: 050df97c6f1484aa0c371d6915eee4f730f382324e9e1a46e9e16a5e6a3764a4

Contents?: true

Size: 1.21 KB

Versions: 24

Compression:

Stored size: 1.21 KB

Contents

# frozen_string_literal: true

require 'elastic_apm/sql_summarizer'

module ElasticAPM
  # @api private
  module Spies
    # @api private
    class SequelSpy
      TYPE = 'db.sequel.sql'

      def self.summarizer
        @summarizer ||= SqlSummarizer.new
      end

      def self.build_context(sql, opts)
        Span::Context.new(
          db: { statement: sql, type: 'sql', user: opts[:user] }
        )
      end

      # rubocop:disable Metrics/MethodLength
      def install
        require 'sequel/database/logging'

        ::Sequel::Database.class_eval do
          alias log_connection_yield_without_apm log_connection_yield

          def log_connection_yield(sql, *args, &block)
            unless ElasticAPM.current_transaction
              return log_connection_yield_without_apm(sql, *args, &block)
            end

            summarizer = ElasticAPM::Spies::SequelSpy.summarizer
            name = summarizer.summarize sql
            context = ElasticAPM::Spies::SequelSpy.build_context(sql, opts)

            ElasticAPM.with_span(name, TYPE, context: context, &block)
          end
        end
      end
      # rubocop:enable Metrics/MethodLength
    end

    register 'Sequel', 'sequel', SequelSpy.new
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
elastic-apm-3.2.0 lib/elastic_apm/spies/sequel.rb
elastic-apm-3.1.0 lib/elastic_apm/spies/sequel.rb
elastic-apm-3.0.0 lib/elastic_apm/spies/sequel.rb
elastic-apm-2.12.0 lib/elastic_apm/spies/sequel.rb
elastic-apm-2.11.0 lib/elastic_apm/spies/sequel.rb
elastic-apm-2.10.1 lib/elastic_apm/spies/sequel.rb
elastic-apm-2.10.0 lib/elastic_apm/spies/sequel.rb
elastic-apm-2.9.1 lib/elastic_apm/spies/sequel.rb
elastic-apm-2.9.0 lib/elastic_apm/spies/sequel.rb
elastic-apm-2.8.1 lib/elastic_apm/spies/sequel.rb
elastic-apm-2.8.0 lib/elastic_apm/spies/sequel.rb
elastic-apm-2.7.0 lib/elastic_apm/spies/sequel.rb
elastic-apm-2.6.1 lib/elastic_apm/spies/sequel.rb
elastic-apm-2.6.0 lib/elastic_apm/spies/sequel.rb
elastic-apm-2.5.0 lib/elastic_apm/spies/sequel.rb
elastic-apm-2.4.0 lib/elastic_apm/spies/sequel.rb
elastic-apm-2.3.1 lib/elastic_apm/spies/sequel.rb
elastic-apm-2.3.0 lib/elastic_apm/spies/sequel.rb
elastic-apm-2.2.0 lib/elastic_apm/spies/sequel.rb
elastic-apm-2.1.2 lib/elastic_apm/spies/sequel.rb