bc-lightstep-ruby 1.2.2 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bb51f610607ad4b815b647c6fa8f09dcd5125e6c27f33462ee2d91a25ba9c28f
4
- data.tar.gz: 34319a63089a907ddd8c15c55442965b42ab1c905f623c5531b8f541a8851685
3
+ metadata.gz: 664ccd6841a41bafc3f8a3f932968c6b8155593b88185fa06351f884a6170e18
4
+ data.tar.gz: f0d69178509b3f639efd203750ff314717b930fc9c22b0cfa915b296a7e2a53e
5
5
  SHA512:
6
- metadata.gz: 3ad475e7bf94c4c4d8de3328ea3944c7ccde4a2d1554f630c5d1410453646b2571dec5e2877ba673e99c764786d61efb5cb09ad4fec843e61182b795e3eddc97
7
- data.tar.gz: a5ca0c2fc284a898cb92b29c8bef18f0a237c5b305713b55d4ccf42a4fca0c164e17ceb403be716ce2e399045af5313144026b90f224c4f72305b5f7981ee7a4
6
+ metadata.gz: ad43fa6c9be415924b6731efe73fac8a96f4c85e5e9dcc92463175de55586fe0d478c8e6cfae4d95783f1699e75b560e1309903c7234647a2f78469759b6fcde
7
+ data.tar.gz: c7197599a7b8b22a9e6e90cf0b17b11ca35e902ced91726a8c4332dcb79eb186716623f34c94b45bacc5bc20422d00f84ac0866da0d9148f046b22d5a24fc31c
@@ -2,7 +2,9 @@ Changelog for the bc-lightstep-ruby gem.
2
2
 
3
3
  h3. Pending Release
4
4
 
5
+ h3. 1.3.0
5
6
 
7
+ - Adds automatic Redis instrumentation support
6
8
 
7
9
  h3. 1.2.2
8
10
 
data/README.md CHANGED
@@ -73,7 +73,12 @@ end
73
73
 
74
74
  Spans will be built with the external service name. It's generally _not_ a good idea to use the Faraday adapter
75
75
  with internal services that are also instrumented with LightStep - use the Faraday adapter on external services
76
- or systems outside of your instrumenting control.
76
+ or systems outside of your instrumenting control.
77
+
78
+ ### Redis
79
+
80
+ This gem will automatically detect and instrumnent Redis calls when they are made using the `Redis::Client` class.
81
+ It will set as tags on the span the host, port, db instance, and the command (but no arguments).
77
82
 
78
83
  ## License
79
84
 
@@ -23,6 +23,7 @@ require_relative 'lightstep/transport_factory'
23
23
  require_relative 'lightstep/transport'
24
24
  require_relative 'lightstep/rails_controller_instrumentation'
25
25
  require_relative 'lightstep/middleware/faraday'
26
+ require_relative 'lightstep/redis/tracer'
26
27
 
27
28
  ##
28
29
  # Main base module
@@ -44,6 +45,8 @@ module Bigcommerce
44
45
  ::LightStep.instance.max_span_records = ::Bigcommerce::Lightstep.max_buffered_spans
45
46
  ::LightStep.instance.max_log_records = ::Bigcommerce::Lightstep.max_log_records
46
47
  ::LightStep.instance.report_period_seconds = ::Bigcommerce::Lightstep.max_reporting_interval_seconds
48
+
49
+ ::Bigcommerce::Lightstep::Redis::Wrapper.patch if ::Bigcommerce::Lightstep.enabled
47
50
  end
48
51
  end
49
52
  end
@@ -0,0 +1,66 @@
1
+ # Copyright (c) 2018-present, BigCommerce Pty. Ltd. All rights reserved
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
4
+ # documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
5
+ # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
6
+ # persons to whom the Software is furnished to do so, subject to the following conditions:
7
+ #
8
+ # The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
9
+ # Software.
10
+ #
11
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
12
+ # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
13
+ # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
14
+ # OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
15
+ #
16
+ require_relative 'wrapper'
17
+
18
+ module Bigcommerce
19
+ module Lightstep
20
+ module Redis
21
+ ##
22
+ # Middleware tracer for Redis clients
23
+ #
24
+ class Tracer
25
+ ##
26
+ # @param [String] key
27
+ # @param [String] statement
28
+ # @param [String] instance
29
+ # @param [String] host
30
+ # @param [Integer] port
31
+ #
32
+ def trace(key:, statement:, instance:, host:, port:)
33
+ return yield unless tracer
34
+
35
+ tags = {
36
+ 'db.type' => 'redis',
37
+ 'db.statement' => statement.to_s.split(' ').first, # only take the command, not any arguments
38
+ 'db.instance' => instance,
39
+ 'db.host' => "redis://#{host}:#{port}",
40
+ 'span.kind' => 'client'
41
+ }
42
+
43
+ tracer.start_span(key) do |span|
44
+ tags.each do |k, v|
45
+ span.set_tag(k, v)
46
+ end
47
+ begin
48
+ resp = yield
49
+ rescue StandardError => _
50
+ span.set_tag('error', true)
51
+ raise # re-raise the error
52
+ end
53
+ resp
54
+ end
55
+ end
56
+
57
+ ##
58
+ # @return [::Bigcommerce::Lightstep::Tracer]
59
+ #
60
+ def tracer
61
+ @tracer ||= ::Bigcommerce::Lightstep::Tracer.instance
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,84 @@
1
+ # Copyright (c) 2018-present, BigCommerce Pty. Ltd. All rights reserved
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
4
+ # documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
5
+ # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
6
+ # persons to whom the Software is furnished to do so, subject to the following conditions:
7
+ #
8
+ # The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
9
+ # Software.
10
+ #
11
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
12
+ # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
13
+ # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
14
+ # OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
15
+ #
16
+ module Bigcommerce
17
+ module Lightstep
18
+ module Redis
19
+ ##
20
+ # Instrumentation wrapper for Redis
21
+ #
22
+ module Wrapper
23
+ class << self
24
+ def patch
25
+ require 'redis' # thread and fork safety
26
+ return if @wrapped
27
+
28
+ wrap unless @wrapped
29
+ @wrapped = true
30
+ rescue ::LoadError => _
31
+ @wrapped = false
32
+ # noop
33
+ end
34
+
35
+ private
36
+
37
+ def wrap
38
+ raise ::LoadError, 'Redis not loaded' unless defined?(::Redis::Client)
39
+
40
+ ::Redis::Client.class_eval do
41
+ alias_method :call_original, :call
42
+ alias_method :call_pipeline_original, :call_pipeline
43
+
44
+ def call(command)
45
+ return call_original(command) unless bc_lightstep_tracer
46
+
47
+ bc_lightstep_tracer.trace(
48
+ key: "redis.#{command[0]}",
49
+ statement: command.join(' '),
50
+ instance: db,
51
+ host: host,
52
+ port: port
53
+ ) do
54
+ call_original(command)
55
+ end
56
+ end
57
+
58
+ def call_pipeline(pipeline)
59
+ return call_pipeline_original(pipeline) unless bc_lightstep_tracer
60
+
61
+ bc_lightstep_tracer.trace(
62
+ key: 'redis.pipelined',
63
+ statement: commands.empty? ? '' : commands.map { |arr| arr.join(' ') }.join(', '),
64
+ instance: db,
65
+ host: host,
66
+ port: port
67
+ ) do
68
+ call_pipeline_original(pipeline)
69
+ end
70
+ end
71
+
72
+ ##
73
+ # @return [::Bigcommerce::Lightstep::Redis::Tracer]
74
+ #
75
+ def bc_lightstep_tracer
76
+ @bc_lightstep_tracer ||= ::Bigcommerce::Lightstep::Redis::Tracer.new
77
+ end
78
+ end
79
+ end
80
+ end
81
+ end
82
+ end
83
+ end
84
+ end
@@ -15,6 +15,6 @@
15
15
  #
16
16
  module Bigcommerce
17
17
  module Lightstep
18
- VERSION = '1.2.2'.freeze
18
+ VERSION = '1.3.0'.freeze
19
19
  end
20
20
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bc-lightstep-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.2
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shaun McCormick
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-03-25 00:00:00.000000000 Z
11
+ date: 2019-03-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -110,6 +110,8 @@ files:
110
110
  - lib/bigcommerce/lightstep/errors.rb
111
111
  - lib/bigcommerce/lightstep/middleware/faraday.rb
112
112
  - lib/bigcommerce/lightstep/rails_controller_instrumentation.rb
113
+ - lib/bigcommerce/lightstep/redis/tracer.rb
114
+ - lib/bigcommerce/lightstep/redis/wrapper.rb
113
115
  - lib/bigcommerce/lightstep/tracer.rb
114
116
  - lib/bigcommerce/lightstep/transport.rb
115
117
  - lib/bigcommerce/lightstep/transport_factory.rb