Module: OpenTelemetry::Instrumentation::Redis::Patches::Client
- Defined in:
- lib/opentelemetry/instrumentation/redis/patches/client.rb
Overview
Module to prepend to Redis::Client for instrumentation
Instance Method Summary collapse
-
#process(commands) ⇒ Object
rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity.
Instance Method Details
#process(commands) ⇒ Object
rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/opentelemetry/instrumentation/redis/patches/client.rb', line 16 def process(commands) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity return super unless config[:trace_root_spans] || OpenTelemetry::Trace.current_span.context.valid? host = [:host] port = [:port] attributes = { 'db.system' => 'redis', 'net.peer.name' => host, 'net.peer.port' => port } attributes['db.redis.database_index'] = [:db] unless [:db].zero? attributes['peer.service'] = config[:peer_service] if config[:peer_service] attributes.merge!(OpenTelemetry::Instrumentation::Redis.attributes) unless config[:db_statement] == :omit parsed_commands = parse_commands(commands) parsed_commands = OpenTelemetry::Common::Utilities.truncate(parsed_commands, MAX_STATEMENT_LENGTH) parsed_commands = OpenTelemetry::Common::Utilities.utf8_encode(parsed_commands, binary: true) attributes['db.statement'] = parsed_commands end span_name = if commands.length == 1 commands[0][0].to_s.upcase else 'PIPELINED' end tracer.in_span(span_name, attributes: attributes, kind: :client) do |s| super(commands).tap do |reply| if reply.is_a?(::Redis::CommandError) s.record_exception(reply) s.status = Trace::Status.error(reply.) end end end end |