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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c51308f745da6f5f2054977944d4d833c1be333d084cf9b929c6160cc9bdd9e8
4
- data.tar.gz: 7dacfc839a37d78d7088ef9d6a4eb24e412fc8742a40ccdfac67eb64aa54629a
3
+ metadata.gz: dea96b1f8199a7f6f69a07e76849d5d1fffaa6a2875abb428766cd34717e230b
4
+ data.tar.gz: e3f42dcd9d466d5cb20b3aefe7d0a63fb18fc4e9004d534214e1cc8a67533454
5
5
  SHA512:
6
- metadata.gz: 0b7451b70f574837c7758c32d2cef0c8a1d076931618524aa2e330c69a6bd4d520242a843432415bcba3987026c7c3ea65f0a3234075797864b6979b6512f777
7
- data.tar.gz: 985b16c6abbe8513a829bd74d3928d42c252ea14719aadb964115aaa351e3c7d3c2e0457902c4f53cee1f4d634027ca3951fc3616b469a16a5beb6ea227f969c
6
+ metadata.gz: c6a1267f116201b2f1f40d115c0fec8cd38b5b9b954a364bb21f73aa5651b1eee1734e1a00fd3543d6b933b7a90206f1f88e90786dd60c15c1e2862e4edd8d0b
7
+ data.tar.gz: dc9124a5acfa9872af9fa5208fc858dee5041737e8c9c8c898ea618363f8f23c74d6507ffe17421fb9327734f687c2403136b30bc2afad7fccefca8b57f6e517
data/CHANGELOG.md CHANGED
@@ -2,6 +2,10 @@ Changelog for the bc-lightstep-ruby gem.
2
2
 
3
3
  ### Pending Release
4
4
 
5
+ ### 2.4.1
6
+
7
+ * Support positional argument methods when using the `Traceable` trace method
8
+
5
9
  ### 2.4.0
6
10
 
7
11
  * Add `::Bigcommerce::Lightstep::Traceable` module for tracing individual methods
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('store_id', request.store_id)
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 |args, &block|
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
- super(**args, &block)
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)
@@ -17,6 +17,6 @@
17
17
  #
18
18
  module Bigcommerce
19
19
  module Lightstep
20
- VERSION = '2.4.0'
20
+ VERSION = '2.4.1'
21
21
  end
22
22
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bc-lightstep-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.0
4
+ version: 2.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shaun McCormick