bc-lightstep-ruby 1.2.2 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +2 -0
- data/README.md +6 -1
- data/lib/bigcommerce/lightstep.rb +3 -0
- data/lib/bigcommerce/lightstep/redis/tracer.rb +66 -0
- data/lib/bigcommerce/lightstep/redis/wrapper.rb +84 -0
- data/lib/bigcommerce/lightstep/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 664ccd6841a41bafc3f8a3f932968c6b8155593b88185fa06351f884a6170e18
|
4
|
+
data.tar.gz: f0d69178509b3f639efd203750ff314717b930fc9c22b0cfa915b296a7e2a53e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ad43fa6c9be415924b6731efe73fac8a96f4c85e5e9dcc92463175de55586fe0d478c8e6cfae4d95783f1699e75b560e1309903c7234647a2f78469759b6fcde
|
7
|
+
data.tar.gz: c7197599a7b8b22a9e6e90cf0b17b11ca35e902ced91726a8c4332dcb79eb186716623f34c94b45bacc5bc20422d00f84ac0866da0d9148f046b22d5a24fc31c
|
data/CHANGELOG.md
CHANGED
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
|
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.
|
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-
|
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
|