bc-lightstep-ruby 2.4.0 → 2.4.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 +4 -0
- data/README.md +40 -1
- data/lib/bigcommerce/lightstep/traceable.rb +12 -3
- data/lib/bigcommerce/lightstep/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dea96b1f8199a7f6f69a07e76849d5d1fffaa6a2875abb428766cd34717e230b
|
4
|
+
data.tar.gz: e3f42dcd9d466d5cb20b3aefe7d0a63fb18fc4e9004d534214e1cc8a67533454
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c6a1267f116201b2f1f40d115c0fec8cd38b5b9b954a364bb21f73aa5651b1eee1734e1a00fd3543d6b933b7a90206f1f88e90786dd60c15c1e2862e4edd8d0b
|
7
|
+
data.tar.gz: dc9124a5acfa9872af9fa5208fc858dee5041737e8c9c8c898ea618363f8f23c74d6507ffe17421fb9327734f687c2403136b30bc2afad7fccefca8b57f6e517
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -114,7 +114,7 @@ class MyService
|
|
114
114
|
include ::Bigcommerce::Lightstep::Traceable
|
115
115
|
|
116
116
|
trace :call, 'operation.do-my-thing' do |span:, product:, options:|
|
117
|
-
span.set_tag('
|
117
|
+
span.set_tag('product_id', product.id)
|
118
118
|
end
|
119
119
|
# or, with no block:
|
120
120
|
trace :call, 'operation.do-my-thing'
|
@@ -125,6 +125,45 @@ class MyService
|
|
125
125
|
end
|
126
126
|
```
|
127
127
|
|
128
|
+
#### Tracing Positional Argument Methods
|
129
|
+
|
130
|
+
For positional argument methods, the behavior is a bit different. In your trace call, if tracing a method with
|
131
|
+
positional arguments, you'll need to have the block arguments be positional as well:
|
132
|
+
|
133
|
+
```ruby
|
134
|
+
class MyService
|
135
|
+
include ::Bigcommerce::Lightstep::Traceable
|
136
|
+
|
137
|
+
trace :positional, 'operation.do-my-thing' do |span, product, options|
|
138
|
+
span.set_tag('product_id', product.id)
|
139
|
+
end
|
140
|
+
def positional(product, options = {})
|
141
|
+
# ...
|
142
|
+
end
|
143
|
+
end
|
144
|
+
```
|
145
|
+
|
146
|
+
Note that any default values in the argument will not carry over into the trace block. Secondly, with positional
|
147
|
+
argument methods that have only a _single_ hash argument, since this library has no way to detect in that case if it
|
148
|
+
is keyword-arguments or a single hash argument, the library will simply add the `span` to the hash itself, and you'll
|
149
|
+
need to adjust the trace block accordingly:
|
150
|
+
|
151
|
+
```ruby
|
152
|
+
|
153
|
+
class MyService
|
154
|
+
include ::Bigcommerce::Lightstep::Traceable
|
155
|
+
|
156
|
+
trace :positional_single_hash_arg, 'operation.do-my-thing' do |my_hash|
|
157
|
+
my_hash[:span].set_tag('product_id', my_hash[:product_id])
|
158
|
+
end
|
159
|
+
def positional_single_hash_arg(my_hash)
|
160
|
+
# ...
|
161
|
+
end
|
162
|
+
end
|
163
|
+
```
|
164
|
+
|
165
|
+
It is recommended for this reason - and others - to never use single-hash positional arguments in Ruby.
|
166
|
+
|
128
167
|
## RSpec
|
129
168
|
|
130
169
|
This library comes with a built-in matcher for testing span blocks. In your rspec config:
|
@@ -41,13 +41,22 @@ module Bigcommerce
|
|
41
41
|
def trace(method_name, operation_name, tags: nil, &span_block)
|
42
42
|
method_name = method_name.to_sym
|
43
43
|
mod = Module.new
|
44
|
-
mod.define_method(method_name) do
|
44
|
+
mod.define_method(method_name) do |*args, &block|
|
45
45
|
tracer = ::Bigcommerce::Lightstep::Tracer.instance
|
46
46
|
tracer.start_span(operation_name) do |span|
|
47
47
|
tags&.each { |k, v| span.set_tag(k.to_s, v) }
|
48
|
-
span_block&.send(:call, **args.merge(span: span))
|
49
48
|
begin
|
50
|
-
|
49
|
+
arg1 = args.first
|
50
|
+
# method has keyword argument signature (or single-hash positional argument)
|
51
|
+
if arg1.is_a?(Hash) && args.count == 1
|
52
|
+
# add span as a kwarg
|
53
|
+
span_block&.send(:call, **arg1.merge(span: span))
|
54
|
+
super(**arg1, &block)
|
55
|
+
else
|
56
|
+
# method has positional argument signature, so just add span to front
|
57
|
+
span_block&.send(:call, *([span] + args))
|
58
|
+
super(*args, &block)
|
59
|
+
end
|
51
60
|
rescue StandardError => e
|
52
61
|
span.set_tag('error', true)
|
53
62
|
span.set_tag('error.message', e.message)
|