Sha256: 69bbd6c13e0b9fc9e82eb6698a284b2bd267a5d63d30960154a1c1f604e20720

Contents?: true

Size: 1023 Bytes

Versions: 7

Compression:

Stored size: 1023 Bytes

Contents

# frozen_string_literal: true

module Labkit
  module Tracing
    module Rails
      module ActiveRecord
        # For more information on the payloads: https://guides.rubyonrails.org/active_support_instrumentation.html
        class SqlInstrumenter < Labkit::Tracing::AbstractInstrumenter
          OPERATION_NAME_PREFIX = "active_record:"
          DEFAULT_OPERATION_NAME = "sqlquery"

          def span_name(payload)
            OPERATION_NAME_PREFIX + (payload[:name].presence || DEFAULT_OPERATION_NAME)
          end

          def tags(payload)
            sql = Labkit::Logging::Sanitizer.sanitize_sql(payload[:sql]) if Labkit::Tracing.sampled? && payload[:sql]
            {
              "component" => COMPONENT_TAG,
              "span.kind" => "client",
              "db.type" => "sql",
              "db.connection_id" => payload[:connection_id],
              "db.cached" => payload[:cached] || false,
              "db.statement" => sql,
            }
          end
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
gitlab-labkit-0.18.0 lib/labkit/tracing/rails/active_record/sql_instrumenter.rb
gitlab-labkit-0.17.1 lib/labkit/tracing/rails/active_record/sql_instrumenter.rb
gitlab-labkit-0.16.2 lib/labkit/tracing/rails/active_record/sql_instrumenter.rb
gitlab-labkit-0.16.1 lib/labkit/tracing/rails/active_record/sql_instrumenter.rb
gitlab-labkit-0.16.0 lib/labkit/tracing/rails/active_record/sql_instrumenter.rb
gitlab-labkit-0.15.0 lib/labkit/tracing/rails/active_record/sql_instrumenter.rb
gitlab-labkit-0.14.0 lib/labkit/tracing/rails/active_record/sql_instrumenter.rb