Sha256: b9fe0976fffc9eb15ad4077c42b71a029a0101e5b83c31cf04bec4810f3f5eeb

Contents?: true

Size: 1.83 KB

Versions: 6

Compression:

Stored size: 1.83 KB

Contents

# frozen_string_literal: true

# Copyright The OpenTelemetry Authors
#
# SPDX-License-Identifier: Apache-2.0

module OpenTelemetry
  module Instrumentation
    module PG
      # The Instrumentation class contains logic to detect and install the Pg instrumentation
      class Instrumentation < OpenTelemetry::Instrumentation::Base
        MINIMUM_VERSION = Gem::Version.new('1.1.0')

        install do |config|
          if config[:enable_sql_obfuscation]
            config[:db_statement] = :obfuscate
            OpenTelemetry.logger.warn(
              'Instrumentation pg configuration option enable_sql_obfuscation has been deprecated,' \
              'use db_statement option instead'
            )
          end

          unless config[:enable_statement_attribute]
            config[:db_statement] = :omit
            OpenTelemetry.logger.warn(
              'Instrumentation pg configuration option enable_statement_attribute has been deprecated,' \
              'use db_statement option instead'
            )
          end

          require_dependencies
          patch_client
        end

        present do
          defined?(::PG)
        end

        compatible do
          gem_version > Gem::Version.new(MINIMUM_VERSION)
        end

        option :peer_service, default: nil, validate: :string
        option :enable_sql_obfuscation, default: false, validate: :boolean
        option :enable_statement_attribute, default: true, validate: :boolean
        option :db_statement, default: :include, validate: %I[omit include obfuscate]

        private

        def gem_version
          Gem::Version.new(::PG::VERSION)
        end

        def require_dependencies
          require_relative 'patches/connection'
        end

        def patch_client
          ::PG::Connection.prepend(Patches::Connection)
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
opentelemetry-instrumentation-pg-0.22.3 lib/opentelemetry/instrumentation/pg/instrumentation.rb
opentelemetry-instrumentation-pg-0.22.2 lib/opentelemetry/instrumentation/pg/instrumentation.rb
opentelemetry-instrumentation-pg-0.22.1 lib/opentelemetry/instrumentation/pg/instrumentation.rb
opentelemetry-instrumentation-pg-0.22.0 lib/opentelemetry/instrumentation/pg/instrumentation.rb
opentelemetry-instrumentation-pg-0.21.0 lib/opentelemetry/instrumentation/pg/instrumentation.rb
opentelemetry-instrumentation-pg-0.20.0 lib/opentelemetry/instrumentation/pg/instrumentation.rb