Sha256: 3b6bad7511bcf4338296552cdcdac749c3aa39b05bf4ca5cb4c7e72c29b11b64

Contents?: true

Size: 1.59 KB

Versions: 2

Compression:

Stored size: 1.59 KB

Contents

# frozen_string_literal: true

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

module OpenTelemetry
  module Adapters
    module Redis
      module Patches
        # Module to prepend to Redis::Client for instrumentation
        module Client
          def call(*args, &block)
            response = nil

            tracer.in_span(
              Utils.format_command(args),
              attributes: client_attributes.merge(
                'db.statement' => Utils.format_statement(args)
              ),
              kind: :client
            ) do
              response = super(*args, &block)
            end

            response
          end

          def call_pipeline(*args, &block)
            response = nil

            tracer.in_span(
              'pipeline',
              attributes: client_attributes.merge(
                'db.statement' => Utils.format_pipeline_statement(args)
              ),
              kind: :client
            ) do
              response = super(*args, &block)
            end

            response
          end

          private

          def client_attributes
            host = options[:host]
            port = options[:port]

            {
              'component' => 'redis',
              'db.type' => 'redis',
              'db.instance' => options[:db].to_s,
              'db.url' => "redis://#{host}:#{port}",
              'net.peer.name' => host,
              'net.peer.port' => port
            }
          end

          def tracer
            Redis::Adapter.instance.tracer
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
opentelemetry-adapters-redis-0.4.0 lib/opentelemetry/adapters/redis/patches/client.rb
opentelemetry-adapters-redis-0.3.0 lib/opentelemetry/adapters/redis/patches/client.rb