Class: Bigcommerce::Lightstep::Redis::Tracer
- Inherits:
-
Object
- Object
- Bigcommerce::Lightstep::Redis::Tracer
- Defined in:
- lib/bigcommerce/lightstep/redis/tracer.rb
Overview
Middleware tracer for Redis clients
Instance Attribute Summary collapse
-
#tracer ⇒ Object
Returns the value of attribute tracer.
Instance Method Summary collapse
- #active_span? ⇒ Boolean
- #excluded?(command) ⇒ Boolean
-
#initialize(tracer: nil, excluded_commands: nil, allow_root_spans: nil) ⇒ Tracer
constructor
A new instance of Tracer.
- #trace(key:, statement:, instance:, host:, port:) ⇒ Object
Constructor Details
#initialize(tracer: nil, excluded_commands: nil, allow_root_spans: nil) ⇒ Tracer
Returns a new instance of Tracer.
32 33 34 35 36 37 38 39 40 |
# File 'lib/bigcommerce/lightstep/redis/tracer.rb', line 32 def initialize( tracer: nil, excluded_commands: nil, allow_root_spans: nil ) @tracer = tracer || ::Bigcommerce::Lightstep::Tracer.instance @excluded_commands = excluded_commands || ::Bigcommerce::Lightstep.redis_excluded_commands @allow_root_spans = allow_root_spans.nil? ? ::Bigcommerce::Lightstep.redis_allow_root_spans : allow_root_spans end |
Instance Attribute Details
#tracer ⇒ Object
Returns the value of attribute tracer.
25 26 27 |
# File 'lib/bigcommerce/lightstep/redis/tracer.rb', line 25 def tracer @tracer end |
Instance Method Details
#active_span? ⇒ Boolean
94 95 96 |
# File 'lib/bigcommerce/lightstep/redis/tracer.rb', line 94 def active_span? tracer.respond_to?(:active_span) && tracer.active_span end |
#excluded?(command) ⇒ Boolean
87 88 89 |
# File 'lib/bigcommerce/lightstep/redis/tracer.rb', line 87 def excluded?(command) @excluded_commands.include?(command.to_s) end |
#trace(key:, statement:, instance:, host:, port:) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/bigcommerce/lightstep/redis/tracer.rb', line 49 def trace(key:, statement:, instance:, host:, port:) return yield unless @tracer # only take the command, not any arguments command = statement.to_s.split(' ').first # skip excluded commands return yield if excluded?(command.to_s) # skip if not allowing root spans and there is no active span return yield if !@allow_root_spans && !active_span? = { 'db.type' => 'redis', 'db.statement' => command, 'db.instance' => instance, 'db.host' => "redis://#{host}:#{port}", 'span.kind' => 'client' } @tracer.start_span(key) do |span| .each do |k, v| span.set_tag(k, v) end begin resp = yield rescue StandardError => _ span.set_tag('error', true) raise # re-raise the error end resp end end |