bc-lightstep-ruby 1.5.2 → 1.6.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 +5 -0
- data/README.md +38 -0
- data/lib/bigcommerce/lightstep/interceptors/env.rb +31 -3
- data/lib/bigcommerce/lightstep/interceptors/registry.rb +7 -7
- data/lib/bigcommerce/lightstep/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7589e9edaad478590eb9d013c737a3ea8a49f20ee84edfcb4ee8e6af9900a068
|
4
|
+
data.tar.gz: fb544f39b1f223111ab96c47839fd4706d0e1c0772b737add936b21a83f82cd6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4bd6e24028f387fe63d59a23d4adee468a60fa2493a4614975159f3498ea9331d71fb55cc9db8727f06cfdfaaa5890a70e50d199247997abba5f2db1f8c034df
|
7
|
+
data.tar.gz: 534f92acb60ee987cbc852d845a6b8b1cd65e96e9876818f848bfae5d90220f5b0faf8d8465f1f25087528fee615c91dea557a90f19a8e96e0694a37b3e9f4ac
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,11 @@ Changelog for the bc-lightstep-ruby gem.
|
|
2
2
|
|
3
3
|
h3. Pending Release
|
4
4
|
|
5
|
+
h3. 1.6.0
|
6
|
+
|
7
|
+
- Allow for instantiation of interceptors at initialization time
|
8
|
+
- Pre-build tag values for ENV interceptor at initialization to reduce CPU usage per-span
|
9
|
+
|
5
10
|
h3. 1.5.2
|
6
11
|
|
7
12
|
- Add rspec helper for testing custom lightstep spans
|
data/README.md
CHANGED
@@ -102,6 +102,44 @@ it 'should create a lightstep span' do
|
|
102
102
|
end
|
103
103
|
```
|
104
104
|
|
105
|
+
## Global Interceptors
|
106
|
+
|
107
|
+
This library has global interceptor support that will allow access to each span as it is built. This allows you to
|
108
|
+
dynamically inject tags or alter spans as they are collected. You can configure interceptors via an initializer:
|
109
|
+
|
110
|
+
```ruby
|
111
|
+
Bigcommerce::Lightstep.configure do |c|
|
112
|
+
c.interceptors.use(MyInterceptor, an_option: 123)
|
113
|
+
# or, alternatively:
|
114
|
+
c.interceptors.use(MyInterceptor.new(an_option: 123))
|
115
|
+
end
|
116
|
+
```
|
117
|
+
|
118
|
+
It's important to note that this is a CPU-intensive operation as interceptors will be run for every `start_span` tag,
|
119
|
+
so don't build interceptors that require lots of processing power or that would impact latencies.
|
120
|
+
|
121
|
+
### ENV Interceptor
|
122
|
+
|
123
|
+
Provided out of the box is an interceptor to automatically inject ENV vars into span tags. You can configure like so:
|
124
|
+
|
125
|
+
```ruby
|
126
|
+
|
127
|
+
Bigcommerce::Lightstep.configure do |c|
|
128
|
+
c.interceptors.use(::Bigcommerce::Lightstep::Interceptors::Env.new(
|
129
|
+
keys: {
|
130
|
+
version: 'VERSION'
|
131
|
+
},
|
132
|
+
presets: [:nomad, :hostname]
|
133
|
+
))
|
134
|
+
end
|
135
|
+
```
|
136
|
+
|
137
|
+
The `keys` argument allows you to pass a `span tag => ENV key` mapping that will assign those ENV vars to spans. The
|
138
|
+
`presets` argument comes with a bunch of preset mappings you can use rather than manually mapping them yourself.
|
139
|
+
|
140
|
+
Note that this interceptor _must_ be instantiated in configuration, rather than passing the class and options,
|
141
|
+
as it needs to pre-materialize the ENV values to reduce CPU usage.
|
142
|
+
|
105
143
|
## License
|
106
144
|
|
107
145
|
Copyright (c) 2018-present, BigCommerce Pty. Ltd. All rights reserved
|
@@ -45,15 +45,17 @@ module Bigcommerce
|
|
45
45
|
@presets = presets || []
|
46
46
|
@env = env || ENV
|
47
47
|
augment_keys_with_presets!
|
48
|
+
collect_values!
|
48
49
|
end
|
49
50
|
|
50
51
|
##
|
51
52
|
# @param [::LightStep::Span] span
|
52
53
|
#
|
53
54
|
def call(span:)
|
54
|
-
|
55
|
-
|
56
|
-
|
55
|
+
value_mutex do
|
56
|
+
@values.each do |span_key, value|
|
57
|
+
span.set_tag(span_key, value)
|
58
|
+
end
|
57
59
|
end
|
58
60
|
|
59
61
|
yield span
|
@@ -61,6 +63,21 @@ module Bigcommerce
|
|
61
63
|
|
62
64
|
private
|
63
65
|
|
66
|
+
##
|
67
|
+
# Pre-collect values at start
|
68
|
+
#
|
69
|
+
def collect_values!
|
70
|
+
value_mutex do
|
71
|
+
@values = {}
|
72
|
+
@keys.each do |span_key, env_key|
|
73
|
+
value = @env.fetch(env_key.to_s, nil)
|
74
|
+
value = value.nil? ? '' : value
|
75
|
+
@values[span_key.to_s.downcase.tr('-', '_').strip] = value
|
76
|
+
end
|
77
|
+
@values
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
64
81
|
##
|
65
82
|
# Augment keys based on presets
|
66
83
|
#
|
@@ -74,6 +91,17 @@ module Bigcommerce
|
|
74
91
|
end
|
75
92
|
end
|
76
93
|
end
|
94
|
+
|
95
|
+
##
|
96
|
+
# Handle access to values in a thread-safe manner
|
97
|
+
#
|
98
|
+
def value_mutex(&block)
|
99
|
+
@value_mutex ||= begin
|
100
|
+
require 'monitor'
|
101
|
+
Monitor.new
|
102
|
+
end
|
103
|
+
@value_mutex.synchronize(&block)
|
104
|
+
end
|
77
105
|
end
|
78
106
|
end
|
79
107
|
end
|
@@ -29,8 +29,8 @@ module Bigcommerce
|
|
29
29
|
##
|
30
30
|
# Add to the thread-safe registry
|
31
31
|
#
|
32
|
-
# @param [Class] klass The class to add
|
33
|
-
# @param [Hash] options A hash of options to pass into the class during initialization
|
32
|
+
# @param [Class|Object] klass The class to add or object to register.
|
33
|
+
# @param [Hash] options (Optional) A hash of options to pass into the class during initialization
|
34
34
|
#
|
35
35
|
def use(klass, options = {})
|
36
36
|
registry_mutex do
|
@@ -85,7 +85,9 @@ module Bigcommerce
|
|
85
85
|
#
|
86
86
|
def list
|
87
87
|
registry_mutex do
|
88
|
-
@registry.map
|
88
|
+
@registry.map do |h|
|
89
|
+
h[:klass].instance_of?(Class) ? h[:klass] : h[:klass].class
|
90
|
+
end
|
89
91
|
end
|
90
92
|
end
|
91
93
|
|
@@ -95,13 +97,11 @@ module Bigcommerce
|
|
95
97
|
# @return [Array<Object>]
|
96
98
|
#
|
97
99
|
def all
|
98
|
-
is = []
|
99
100
|
registry_mutex do
|
100
|
-
@registry.
|
101
|
-
|
101
|
+
@registry.map do |o|
|
102
|
+
o[:klass].is_a?(Class) ? o[:klass].new(o[:options]) : o[:klass]
|
102
103
|
end
|
103
104
|
end
|
104
|
-
is
|
105
105
|
end
|
106
106
|
|
107
107
|
private
|
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.6.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-08-
|
11
|
+
date: 2019-08-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|