Sha256: 485e0aa74989305a0993f7df85401fcba1b9b4a851c687d8dc6708d933137f27

Contents?: true

Size: 1.77 KB

Versions: 5

Compression:

Stored size: 1.77 KB

Contents

# frozen_string_literal: true

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

module OpenTelemetry
  module Instrumentation
    # Utility functions
    module Utils
      extend self

      STRING_PLACEHOLDER = ''.encode(::Encoding::UTF_8).freeze
      CMD_MAX_LEN = 500

      OPNAME_MAPPING = {
        'get' => 'get',
        'cas' => 'get',
        'set' => 'set',
        'add' => 'add',
        'replace' => 'replace',
        'delete' => 'delete',
        'incr' => 'incr',
        'decr' => 'decr',
        'flush' => 'flush',
        'write_noop' => 'noop',
        'version' => 'version',
        'send_multiget' => 'getkq',
        'append' => 'append',
        'prepend' => 'prepend',
        'stats' => 'stat',
        'reset_stats' => 'stat',
        'multi_set' => 'setq',
        'multi_add' => 'addq',
        'multi_replace' => 'replaceq',
        'multi_delete' => 'deleteq',
        'touch' => 'touch'
        # 'sasl_authentication' => 'auth_negotiation',
        # 'sasl_authentication' => 'auth_request',
      }.freeze

      def opname(operation, multi)
        lookup_name = multi ? "multi_#{operation}" : operation.to_s
        OPNAME_MAPPING[lookup_name] || operation.to_s
      end

      def format_command(operation, args)
        placeholder = "#{operation} BLOB (OMITTED)"
        command = [operation, *args].join(' ').strip
        command = OpenTelemetry::Common::Utilities.utf8_encode(command, binary: true, placeholder: placeholder)
        truncate(command, CMD_MAX_LEN)
      rescue StandardError => e
        OpenTelemetry.logger.debug("Error sanitizing Dalli operation: #{e}")
        placeholder
      end

      def truncate(string, size)
        string.size > size ? "#{string[0...size - 3]}..." : string
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
opentelemetry-instrumentation-dalli-0.15.0 lib/opentelemetry/instrumentation/dalli/utils.rb
opentelemetry-instrumentation-dalli-0.14.0 lib/opentelemetry/instrumentation/dalli/utils.rb
opentelemetry-instrumentation-dalli-0.13.0 lib/opentelemetry/instrumentation/dalli/utils.rb
opentelemetry-instrumentation-dalli-0.12.0 lib/opentelemetry/instrumentation/dalli/utils.rb
opentelemetry-instrumentation-dalli-0.11.0 lib/opentelemetry/instrumentation/dalli/utils.rb