bc-lightstep-ruby 1.3.0 → 1.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 664ccd6841a41bafc3f8a3f932968c6b8155593b88185fa06351f884a6170e18
4
- data.tar.gz: f0d69178509b3f639efd203750ff314717b930fc9c22b0cfa915b296a7e2a53e
3
+ metadata.gz: 39888ce33cb784b4e9bf294ef12948c14117a68eb0f19ed556c3d1bda47ca35b
4
+ data.tar.gz: a321672c7e044a5db91d6e58d051058acfaf347fabcb2d736fcac2d1024bad86
5
5
  SHA512:
6
- metadata.gz: ad43fa6c9be415924b6731efe73fac8a96f4c85e5e9dcc92463175de55586fe0d478c8e6cfae4d95783f1699e75b560e1309903c7234647a2f78469759b6fcde
7
- data.tar.gz: c7197599a7b8b22a9e6e90cf0b17b11ca35e902ced91726a8c4332dcb79eb186716623f34c94b45bacc5bc20422d00f84ac0866da0d9148f046b22d5a24fc31c
6
+ metadata.gz: '009121dcef8ced54b459af1a4f3349cd50d49e08d5274afe99c14092507c16f48f661fdba98366faf895556053ea13365aaa7eadbe3b6c7aae75e17097c38a41'
7
+ data.tar.gz: 714da396916d0486762a9e7246bab4e94054ffab51a9db4cd5d14eb07136e03dd74e79abb05023a374d4481fa2fff72fe3b6655d949850799b0cc6e92cf98ea2
@@ -2,6 +2,11 @@ Changelog for the bc-lightstep-ruby gem.
2
2
 
3
3
  h3. Pending Release
4
4
 
5
+ h3. 1.3.1
6
+
7
+ - Add various options to suppress redis trace spam
8
+ - Fix issue with pipeline commands in redis instrumentation
9
+
5
10
  h3. 1.3.0
6
11
 
7
12
  - Adds automatic Redis instrumentation support
data/README.md CHANGED
@@ -80,6 +80,12 @@ or systems outside of your instrumenting control.
80
80
  This gem will automatically detect and instrumnent Redis calls when they are made using the `Redis::Client` class.
81
81
  It will set as tags on the span the host, port, db instance, and the command (but no arguments).
82
82
 
83
+ Note that this will not record redis timings if they are a root span. This is to prevent trace spamming. You can
84
+ re-enable this by setting the `redis_allow_root_spans` configuration option to `true`.
85
+
86
+ It also excludes `ping` commands, and you can provide a custom list by setting the `redis_excluded_commands`
87
+ configuration option to an array of commands to exclude.
88
+
83
89
  ## License
84
90
 
85
91
  Copyright (c) 2018-present, BigCommerce Pty. Ltd. All rights reserved
@@ -38,6 +38,8 @@ module Bigcommerce
38
38
  max_buffered_spans: 1_000,
39
39
  max_log_records: 1_000,
40
40
  max_reporting_interval_seconds: 3.0,
41
+ redis_excluded_commands: %w(ping),
42
+ redis_allow_root_spans: false,
41
43
  enabled: true
42
44
  }.freeze
43
45
 
@@ -22,6 +22,23 @@ module Bigcommerce
22
22
  # Middleware tracer for Redis clients
23
23
  #
24
24
  class Tracer
25
+ attr_accessor :tracer
26
+
27
+ ##
28
+ # @param [Bigcommerce::Lightstep::Tracer] tracer
29
+ # @param [Array<String>] excluded_commands
30
+ # @param [Boolean] allow_root_spans
31
+ #
32
+ def initialize(
33
+ tracer: nil,
34
+ excluded_commands: nil,
35
+ allow_root_spans: nil
36
+ )
37
+ @tracer = tracer || ::Bigcommerce::Lightstep::Tracer.instance
38
+ @excluded_commands = excluded_commands || ::Bigcommerce::Lightstep.redis_excluded_commands
39
+ @allow_root_spans = allow_root_spans.nil? ? ::Bigcommerce::Lightstep.redis_allow_root_spans : allow_root_spans
40
+ end
41
+
25
42
  ##
26
43
  # @param [String] key
27
44
  # @param [String] statement
@@ -30,17 +47,26 @@ module Bigcommerce
30
47
  # @param [Integer] port
31
48
  #
32
49
  def trace(key:, statement:, instance:, host:, port:)
33
- return yield unless tracer
50
+ return yield unless @tracer
51
+
52
+ # only take the command, not any arguments
53
+ command = statement.to_s.split(' ').first
54
+
55
+ # skip excluded commands
56
+ return yield if excluded?(command.to_s)
57
+
58
+ # skip if not allowing root spans and there is no active span
59
+ return yield if !@allow_root_spans && !active_span?
34
60
 
35
61
  tags = {
36
62
  'db.type' => 'redis',
37
- 'db.statement' => statement.to_s.split(' ').first, # only take the command, not any arguments
63
+ 'db.statement' => command,
38
64
  'db.instance' => instance,
39
65
  'db.host' => "redis://#{host}:#{port}",
40
66
  'span.kind' => 'client'
41
67
  }
42
68
 
43
- tracer.start_span(key) do |span|
69
+ @tracer.start_span(key) do |span|
44
70
  tags.each do |k, v|
45
71
  span.set_tag(k, v)
46
72
  end
@@ -55,10 +81,18 @@ module Bigcommerce
55
81
  end
56
82
 
57
83
  ##
58
- # @return [::Bigcommerce::Lightstep::Tracer]
84
+ # @param [String] command
85
+ # @return [Boolean]
86
+ #
87
+ def excluded?(command)
88
+ @excluded_commands.include?(command.to_s)
89
+ end
90
+
91
+ ##
92
+ # @return [Boolean]
59
93
  #
60
- def tracer
61
- @tracer ||= ::Bigcommerce::Lightstep::Tracer.instance
94
+ def active_span?
95
+ tracer.respond_to?(:active_span) && tracer.active_span
62
96
  end
63
97
  end
64
98
  end
@@ -58,6 +58,7 @@ module Bigcommerce
58
58
  def call_pipeline(pipeline)
59
59
  return call_pipeline_original(pipeline) unless bc_lightstep_tracer
60
60
 
61
+ commands = pipeline.try(:commands) || []
61
62
  bc_lightstep_tracer.trace(
62
63
  key: 'redis.pipelined',
63
64
  statement: commands.empty? ? '' : commands.map { |arr| arr.join(' ') }.join(', '),
@@ -15,6 +15,6 @@
15
15
  #
16
16
  module Bigcommerce
17
17
  module Lightstep
18
- VERSION = '1.3.0'.freeze
18
+ VERSION = '1.3.1'.freeze
19
19
  end
20
20
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bc-lightstep-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shaun McCormick