bc-lightstep-ruby 1.6.0 → 1.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/lib/bigcommerce/lightstep.rb +1 -0
- data/lib/bigcommerce/lightstep/interceptors/context.rb +61 -0
- data/lib/bigcommerce/lightstep/interceptors/env.rb +7 -1
- data/lib/bigcommerce/lightstep/interceptors/registry.rb +0 -18
- data/lib/bigcommerce/lightstep/tracer.rb +18 -9
- data/lib/bigcommerce/lightstep/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9b7c7f73bcd9b15e33f59fab40d2f60124d83747547f2cdde65b49f7325b844e
|
4
|
+
data.tar.gz: fc8eca4e8a2d9eb94731c6388ac8354ce96bb6e66af5e2407e10db5182d9631b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: befcf28e38ee07348960d9458d4f2d933e95e418b80c6f330d818dd45fa05406bef2da7a8a4402ff34a6e2e31d8bab07e1e84a1d02cf5579e2727f6721749553
|
7
|
+
data.tar.gz: 74b3b64044faaf7dfe0a153828856f60ecc09c078354122c1ac8b5104f0f345aa2b8ffede65ce5eca1f68cb9b9bb88bd9baa26c54be304fdc9472b2109f59f11
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,13 @@ Changelog for the bc-lightstep-ruby gem.
|
|
2
2
|
|
3
3
|
h3. Pending Release
|
4
4
|
|
5
|
+
h3. 1.6.1
|
6
|
+
|
7
|
+
- Add interception context for thread-safe interception per trace
|
8
|
+
- Fix issue when there are no interceptors configured
|
9
|
+
- Fix issue where there is more than one interceptor configured
|
10
|
+
- Only pass env tags if root span for service
|
11
|
+
|
5
12
|
h3. 1.6.0
|
6
13
|
|
7
14
|
- Allow for instantiation of interceptors at initialization time
|
@@ -20,6 +20,7 @@ require 'faraday'
|
|
20
20
|
require_relative 'lightstep/version'
|
21
21
|
require_relative 'lightstep/errors'
|
22
22
|
require_relative 'lightstep/interceptors/registry'
|
23
|
+
require_relative 'lightstep/interceptors/context'
|
23
24
|
require_relative 'lightstep/configuration'
|
24
25
|
require_relative 'lightstep/tracer'
|
25
26
|
require_relative 'lightstep/transport_factory'
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright (c) 2018-present, BigCommerce Pty. Ltd. All rights reserved
|
4
|
+
#
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
|
6
|
+
# documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
|
7
|
+
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
|
8
|
+
# persons to whom the Software is furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
|
11
|
+
# Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
|
14
|
+
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
15
|
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
16
|
+
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
17
|
+
#
|
18
|
+
module Bigcommerce
|
19
|
+
module Lightstep
|
20
|
+
module Interceptors
|
21
|
+
##
|
22
|
+
# Runs interceptors in a given context
|
23
|
+
#
|
24
|
+
class Context
|
25
|
+
##
|
26
|
+
# Initialize the interception context
|
27
|
+
#
|
28
|
+
# @param [Array<Bigcommerce::Lightstep::Interceptors::Base>] interceptors
|
29
|
+
# @param [::Logger] logger
|
30
|
+
#
|
31
|
+
def initialize(interceptors: nil, logger: nil)
|
32
|
+
@interceptors = interceptors || ::Bigcommerce::Lightstep.interceptors.all
|
33
|
+
@logger = logger || ::Bigcommerce::Lightstep.logger
|
34
|
+
end
|
35
|
+
|
36
|
+
##
|
37
|
+
# Intercept a trace with all interceptors
|
38
|
+
#
|
39
|
+
# @param [::LightStep::Span] span
|
40
|
+
#
|
41
|
+
def intercept(span)
|
42
|
+
return yield span if @interceptors.none?
|
43
|
+
|
44
|
+
interceptor = @interceptors.pop
|
45
|
+
|
46
|
+
return yield span unless interceptor
|
47
|
+
|
48
|
+
@logger.debug "[bigcommerce-lightstep] Intercepting request with interceptor: #{interceptor.class}"
|
49
|
+
|
50
|
+
interceptor.call(span: span) do |yielded_span|
|
51
|
+
if @interceptors.any?
|
52
|
+
intercept(yielded_span) { yield yielded_span }
|
53
|
+
else
|
54
|
+
yield yielded_span
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -32,7 +32,7 @@ module Bigcommerce
|
|
32
32
|
}.freeze
|
33
33
|
|
34
34
|
PRESET_HOSTNAME = {
|
35
|
-
'hostname': 'HOSTNAME'
|
35
|
+
'hostname': 'HOSTNAME'
|
36
36
|
}.freeze
|
37
37
|
|
38
38
|
##
|
@@ -52,6 +52,8 @@ module Bigcommerce
|
|
52
52
|
# @param [::LightStep::Span] span
|
53
53
|
#
|
54
54
|
def call(span:)
|
55
|
+
return yield span unless root_span?(span)
|
56
|
+
|
55
57
|
value_mutex do
|
56
58
|
@values.each do |span_key, value|
|
57
59
|
span.set_tag(span_key, value)
|
@@ -63,6 +65,10 @@ module Bigcommerce
|
|
63
65
|
|
64
66
|
private
|
65
67
|
|
68
|
+
def root_span?(span)
|
69
|
+
span.instance_variable_get(:@root_span) == true
|
70
|
+
end
|
71
|
+
|
66
72
|
##
|
67
73
|
# Pre-collect values at start
|
68
74
|
#
|
@@ -41,24 +41,6 @@ module Bigcommerce
|
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
|
-
##
|
45
|
-
# Intercept a trace with all interceptors
|
46
|
-
#
|
47
|
-
def intercept(span)
|
48
|
-
interceptors = all
|
49
|
-
interceptor = interceptors.pop
|
50
|
-
|
51
|
-
return yield unless interceptor
|
52
|
-
|
53
|
-
interceptor.call(span: span) do |yielded_span|
|
54
|
-
if interceptors.any?
|
55
|
-
intercept(yielded_span) { yield yielded_span }
|
56
|
-
else
|
57
|
-
yield yielded_span
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
44
|
##
|
63
45
|
# Clear the registry
|
64
46
|
#
|
@@ -21,14 +21,6 @@ module Bigcommerce
|
|
21
21
|
# Global tracer
|
22
22
|
#
|
23
23
|
class Tracer
|
24
|
-
private
|
25
|
-
|
26
|
-
def initialize
|
27
|
-
@interceptors = Bigcommerce::Lightstep.interceptors || Bigcommerce::Lightstep::Interceptors::Registry.new
|
28
|
-
end
|
29
|
-
|
30
|
-
public
|
31
|
-
|
32
24
|
include Singleton
|
33
25
|
|
34
26
|
##
|
@@ -62,13 +54,15 @@ module Bigcommerce
|
|
62
54
|
# create new span
|
63
55
|
span = ::LightStep.start_span(name, child_of: current_parent, start_time: start_time, tags: tags)
|
64
56
|
|
57
|
+
mark_root_span(span) if active_span.nil?
|
58
|
+
|
65
59
|
# set it as the active span
|
66
60
|
self.active_span = span
|
67
61
|
|
68
62
|
# run the process
|
69
63
|
result = nil
|
70
64
|
begin
|
71
|
-
|
65
|
+
build_context.intercept(span) do |inner_span|
|
72
66
|
result = yield inner_span
|
73
67
|
end
|
74
68
|
rescue StandardError
|
@@ -118,6 +112,13 @@ module Bigcommerce
|
|
118
112
|
|
119
113
|
private
|
120
114
|
|
115
|
+
##
|
116
|
+
# @return [::Bigcommerce::Lightstep::Interceptors::Context]
|
117
|
+
#
|
118
|
+
def build_context
|
119
|
+
::Bigcommerce::Lightstep::Interceptors::Context.new
|
120
|
+
end
|
121
|
+
|
121
122
|
##
|
122
123
|
# Determine the active parent
|
123
124
|
#
|
@@ -146,6 +147,14 @@ module Bigcommerce
|
|
146
147
|
def tracer
|
147
148
|
LightStep.instance
|
148
149
|
end
|
150
|
+
|
151
|
+
##
|
152
|
+
# Because LightStep doesn't allow changing the span return class, or adding any arbitrary attributes, we need
|
153
|
+
# to do this here to mark what is the "root" span in a service.
|
154
|
+
#
|
155
|
+
def mark_root_span(span)
|
156
|
+
span.instance_variable_set(:@root_span, true)
|
157
|
+
end
|
149
158
|
end
|
150
159
|
end
|
151
160
|
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.6.
|
4
|
+
version: 1.6.1
|
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-08-
|
11
|
+
date: 2019-08-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -115,6 +115,7 @@ files:
|
|
115
115
|
- lib/bigcommerce/lightstep/configuration.rb
|
116
116
|
- lib/bigcommerce/lightstep/errors.rb
|
117
117
|
- lib/bigcommerce/lightstep/interceptors/base.rb
|
118
|
+
- lib/bigcommerce/lightstep/interceptors/context.rb
|
118
119
|
- lib/bigcommerce/lightstep/interceptors/env.rb
|
119
120
|
- lib/bigcommerce/lightstep/interceptors/registry.rb
|
120
121
|
- lib/bigcommerce/lightstep/middleware/faraday.rb
|
@@ -145,8 +146,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
145
146
|
- !ruby/object:Gem::Version
|
146
147
|
version: '0'
|
147
148
|
requirements: []
|
148
|
-
|
149
|
-
rubygems_version: 2.7.9
|
149
|
+
rubygems_version: 3.0.6
|
150
150
|
signing_key:
|
151
151
|
specification_version: 4
|
152
152
|
summary: Gem for lightstep distributed tracing
|