bc-lightstep-ruby 1.4.0 → 1.5.0

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: 75614155acef737a30e80669b9decb41b2289f18f1519c049732bcdb78f034d4
4
- data.tar.gz: 4b937baecd5fdb865b462a5a5ff92d30f9f88e4f1c9f555c994c5c61fdcec76d
3
+ metadata.gz: '08af660ec2183d4ec8eaff0050ce5d6476a7147b108d4ca69dfcec92f68c99e3'
4
+ data.tar.gz: d6ccbfa3aece6cc5b339ff0e45e05e078d822ec4f42e5d4894fee48ce66f0129
5
5
  SHA512:
6
- metadata.gz: d1e310ce0281e96dc8bdbe176cbf88a1d43067e90313f53933e163cc5bf53c30cc1275b27b8f3eede24de85d5c834e888a9e399d5ef344869ba44176face4373
7
- data.tar.gz: d64dc9e30cddbc9dd9e0bedb56d738738f1a709b21e9e26190ea530114eae9748310738e07238e796b2a8c5bd69c24c6fe3e53e204512b06a3ce1201c354f640
6
+ metadata.gz: 4e4232a04e274587f4c04f4544b6926e039ec8b1619bc0cb82405fdf46764f3da8433340aac51afba064426342a7bb64f5c1be271f6758a262a6afd72e5cd305
7
+ data.tar.gz: c4a7bc4b47f07343ba1cc2131ea508c1bcd43b4b24c45e410700d51f4485a5334e1051d885ba2d64027b45f777299b201116eb8206eb31809121c6be533aed18
data/CHANGELOG.md CHANGED
@@ -2,6 +2,10 @@ Changelog for the bc-lightstep-ruby gem.
2
2
 
3
3
  h3. Pending Release
4
4
 
5
+ h3. 1.5.0
6
+
7
+ - Add interceptors that allow for global injection of tags into spans
8
+
5
9
  h3. 1.4.0
6
10
 
7
11
  - Add `frozen_string_literal: true` to all files
@@ -19,6 +19,7 @@ require 'lightstep'
19
19
  require 'faraday'
20
20
  require_relative 'lightstep/version'
21
21
  require_relative 'lightstep/errors'
22
+ require_relative 'lightstep/interceptors/registry'
22
23
  require_relative 'lightstep/configuration'
23
24
  require_relative 'lightstep/tracer'
24
25
  require_relative 'lightstep/transport_factory'
@@ -27,6 +27,7 @@ module Bigcommerce
27
27
  controller_trace_prefix: 'controllers.',
28
28
  access_token: '',
29
29
  host: 'lightstep-collector.linkerd',
30
+ interceptors: nil,
30
31
  port: 4140,
31
32
  ssl_verify_peer: true,
32
33
  open_timeout: 20,
@@ -106,6 +107,7 @@ module Bigcommerce
106
107
  self.verbosity = ENV.fetch('LIGHTSTEP_VERBOSITY', 1).to_i
107
108
  self.logger = defined?(Rails) ? Rails.logger : Logger.new(STDOUT)
108
109
  self.enabled = ENV.fetch('LIGHTSTEP_ENABLED', 1).to_i.positive?
110
+ self.interceptors = ::Bigcommerce::Lightstep::Interceptors::Registry.new
109
111
  end
110
112
 
111
113
  ##
@@ -0,0 +1,36 @@
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
+ # Hydrates span tags with specified ENV vars
23
+ #
24
+ class Base
25
+ def initialize(*); end
26
+
27
+ ##
28
+ # @param [::LightStep::Span] span
29
+ #
30
+ def call(*)
31
+ raise NotImplementedError, 'Please implement .call on your subclassed interceptor'
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,74 @@
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
+ # Hydrates span tags with specified ENV vars
23
+ #
24
+ class Env < Base
25
+ PRESET_NOMAD = {
26
+ 'container.cpu': 'NOMAD_CPU_LIMIT',
27
+ 'container.mem': 'NOMAD_MEMORY_LIMIT',
28
+ 'git.sha': 'NOMAD_META_SHA',
29
+ 'nomad.task_name': 'NOMAD_TASK_NAME',
30
+ 'provider.region': 'NOMAD_REGION',
31
+ 'provider.datacenter': 'NOMAD_DC'
32
+ }.freeze
33
+
34
+ ##
35
+ # @param [Hash] keys A hash of span->env key mappings
36
+ # @param [ENV] env The ENV class to get variables from
37
+ # @param [Array<Symbol>] presets Specify presets that automatically setup keys
38
+ #
39
+ def initialize(keys: nil, env: nil, presets: [])
40
+ @keys = keys || {}
41
+ @presets = presets || []
42
+ @env = env || ENV
43
+ augment_keys_with_presets!
44
+ end
45
+
46
+ ##
47
+ # @param [::LightStep::Span] span
48
+ #
49
+ def call(span:)
50
+ @keys.each do |span_key, env_key|
51
+ value = @env.fetch(env_key.to_s, nil)
52
+ span.set_tag(span_key.to_s.downcase.tr('-', '_').strip, value.nil? ? '' : value)
53
+ end
54
+
55
+ yield span
56
+ end
57
+
58
+ private
59
+
60
+ ##
61
+ # Augment keys based on presets
62
+ #
63
+ def augment_keys_with_presets!
64
+ @presets.each do |preset|
65
+ case preset
66
+ when :nomad
67
+ @keys.merge!(PRESET_NOMAD)
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,125 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright (c) 2019-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
+ # Thread-safe registry for interceptors
23
+ #
24
+ class Registry
25
+ def initialize
26
+ @registry = []
27
+ end
28
+
29
+ ##
30
+ # Add to the thread-safe registry
31
+ #
32
+ # @param [Class] klass The class to add
33
+ # @param [Hash] options A hash of options to pass into the class during initialization
34
+ #
35
+ def use(klass, options = {})
36
+ registry_mutex do
37
+ @registry << {
38
+ klass: klass,
39
+ options: options
40
+ }
41
+ end
42
+ end
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
+ ##
63
+ # Clear the registry
64
+ #
65
+ def clear
66
+ registry_mutex do
67
+ @registry = []
68
+ end
69
+ end
70
+
71
+ ##
72
+ # @return [Integer] The number of items currently loaded
73
+ #
74
+ def count
75
+ registry_mutex do
76
+ @registry ||= []
77
+ @registry.count
78
+ end
79
+ end
80
+
81
+ ##
82
+ # Return a list of the classes in the registry in their execution order
83
+ #
84
+ # @return [Array<Class>]
85
+ #
86
+ def list
87
+ registry_mutex do
88
+ @registry.map { |h| h[:klass] }
89
+ end
90
+ end
91
+
92
+ ##
93
+ # Load and return all items
94
+ #
95
+ # @return [Array<Object>]
96
+ #
97
+ def all
98
+ is = []
99
+ registry_mutex do
100
+ @registry.each do |o|
101
+ is << o[:klass].new(o[:options])
102
+ end
103
+ end
104
+ is
105
+ end
106
+
107
+ private
108
+
109
+ ##
110
+ # Handle mutations to the registry in a thread-safe manner
111
+ #
112
+ def registry_mutex(&block)
113
+ @registry_mutex ||= begin
114
+ require 'monitor'
115
+ Monitor.new
116
+ end
117
+ @registry_mutex.synchronize(&block)
118
+ end
119
+ end
120
+ end
121
+ end
122
+ end
123
+
124
+ require_relative 'base'
125
+ require_relative 'env'
@@ -23,7 +23,9 @@ module Bigcommerce
23
23
  class Tracer
24
24
  private
25
25
 
26
- def initialize; end
26
+ def initialize
27
+ @interceptors = Bigcommerce::Lightstep.interceptors || Bigcommerce::Lightstep::Interceptors::Registry.new
28
+ end
27
29
 
28
30
  public
29
31
 
@@ -66,7 +68,9 @@ module Bigcommerce
66
68
  # run the process
67
69
  result = nil
68
70
  begin
69
- result = yield span
71
+ @interceptors.intercept(span) do |inner_span|
72
+ result = yield inner_span
73
+ end
70
74
  rescue StandardError
71
75
  span.set_tag('error', true)
72
76
  raise
@@ -17,6 +17,6 @@
17
17
  #
18
18
  module Bigcommerce
19
19
  module Lightstep
20
- VERSION = '1.4.0'
20
+ VERSION = '1.5.0'
21
21
  end
22
22
  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.0
4
+ version: 1.5.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-05-01 00:00:00.000000000 Z
11
+ date: 2019-08-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -114,6 +114,9 @@ files:
114
114
  - lib/bigcommerce/lightstep.rb
115
115
  - lib/bigcommerce/lightstep/configuration.rb
116
116
  - lib/bigcommerce/lightstep/errors.rb
117
+ - lib/bigcommerce/lightstep/interceptors/base.rb
118
+ - lib/bigcommerce/lightstep/interceptors/env.rb
119
+ - lib/bigcommerce/lightstep/interceptors/registry.rb
117
120
  - lib/bigcommerce/lightstep/middleware/faraday.rb
118
121
  - lib/bigcommerce/lightstep/rails_controller_instrumentation.rb
119
122
  - lib/bigcommerce/lightstep/redis/tracer.rb
@@ -141,7 +144,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
141
144
  - !ruby/object:Gem::Version
142
145
  version: '0'
143
146
  requirements: []
144
- rubygems_version: 3.0.2
147
+ rubyforge_project:
148
+ rubygems_version: 2.7.9
145
149
  signing_key:
146
150
  specification_version: 4
147
151
  summary: Gem for lightstep distributed tracing