Sha256: 5af93f7677955f172f054941e9db97f7a3015d21917a3689d56b18b5d1e339a9

Contents?: true

Size: 1.58 KB

Versions: 11

Compression:

Stored size: 1.58 KB

Contents

# frozen_string_literal: true

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

require 'opentelemetry'
require 'opentelemetry-instrumentation-base'

module OpenTelemetry
  module Instrumentation
    # Contains the OpenTelemetry instrumentation for the Pg gem
    module PG
      extend self

      CURRENT_ATTRIBUTES_KEY = Context.create_key('pg-attributes-hash')

      private_constant :CURRENT_ATTRIBUTES_KEY

      # Returns the attributes hash representing the postgres client context found
      # in the optional context or the current context if none is provided.
      #
      # @param [optional Context] context The context to lookup the current
      #   attributes hash. Defaults to Context.current
      def attributes(context = nil)
        context ||= Context.current
        context.value(CURRENT_ATTRIBUTES_KEY) || {}
      end

      # Activates/deactivates the merged attributes hash within the current Context,
      # which makes the "current attributes hash" available implicitly.
      #
      # On exit, the attributes hash that was active before calling this method
      # will be reactivated.
      #
      # @param [Span] span the span to activate
      # @yield [Hash, Context] yields attributes hash and a context containing the
      #   attributes hash to the block.
      def with_attributes(attributes_hash)
        attributes_hash = attributes.merge(attributes_hash)
        Context.with_value(CURRENT_ATTRIBUTES_KEY, attributes_hash) { |c, h| yield h, c }
      end
    end
  end
end

require_relative 'pg/instrumentation'
require_relative 'pg/version'

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
opentelemetry-instrumentation-pg-0.29.2 lib/opentelemetry/instrumentation/pg.rb
opentelemetry-instrumentation-pg-0.29.1 lib/opentelemetry/instrumentation/pg.rb
opentelemetry-instrumentation-pg-0.29.0 lib/opentelemetry/instrumentation/pg.rb
opentelemetry-instrumentation-pg-0.28.0 lib/opentelemetry/instrumentation/pg.rb
opentelemetry-instrumentation-pg-0.27.4 lib/opentelemetry/instrumentation/pg.rb
opentelemetry-instrumentation-pg-0.27.2 lib/opentelemetry/instrumentation/pg.rb
opentelemetry-instrumentation-pg-0.27.1 lib/opentelemetry/instrumentation/pg.rb
opentelemetry-instrumentation-pg-0.27.0 lib/opentelemetry/instrumentation/pg.rb
opentelemetry-instrumentation-pg-0.26.1 lib/opentelemetry/instrumentation/pg.rb
opentelemetry-instrumentation-pg-0.26.0 lib/opentelemetry/instrumentation/pg.rb
opentelemetry-instrumentation-pg-0.25.3 lib/opentelemetry/instrumentation/pg.rb