rack-honeycomb 0.3.0 → 0.4.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: d71737f6f10436e9df8ccf2589fa626b720baf0eca15dd764496daa6028d3be1
4
- data.tar.gz: 132781010ca1cf718553c968961bf10f3ec683b891b53fb800c5539148d357c7
3
+ metadata.gz: 2df72a49bca0dd5e2665baf5761f34a21f1140e718f26c1df5f72994e332b77b
4
+ data.tar.gz: 6a3743e0c01dc73c1b503a6e0103c77fb0c7aacaef83c1a9c1b01449aec393c1
5
5
  SHA512:
6
- metadata.gz: e698f60be56541bd891ad9b2e00c897553fd2851127524e9726394ca28d1af80c6929cb01a6ba40286e8fc326d5df21009ace359f7ee718139e42368630738db
7
- data.tar.gz: 7aa9fd274977bd1dc31985eb66f37f28ac433aa6d3632f192b8640f897203c3ea80b260a217f6bd562b85cb80eaa830fc54450cdfb36a895fae8b4debca147b9
6
+ metadata.gz: f81063f7b9acc8e374408a8ef8c18c8b6b20ddf78ba7ab0faf2e2c0abd5716b8931968aac459abd77e4dfc92330d596e18759045808a1f96fd7174a025fee277
7
+ data.tar.gz: f7579b4e2074b46164345c437814889a2cb7b30cffceb9a43a36cc22e4c8eb5795741e034f72a1e3d7a32420f6ac905eb73597a2b584c81b77b7f9329d80cb6c
@@ -77,7 +77,7 @@ module Rack
77
77
  add_request_fields(ev, env)
78
78
 
79
79
  start = Time.now
80
- status, headers, body = adding_span_metadata_if_available(ev, env) do
80
+ status, headers, body = with_tracing_if_available(ev, env) do
81
81
  @app.call(env)
82
82
  end
83
83
 
@@ -186,8 +186,8 @@ module Rack
186
186
  # anything inside the Rack handler.
187
187
  env.each_pair do |k, v|
188
188
  if k.is_a?(String) && k.match(ENV_REGEX)
189
- namespaced_k = "#{APP_FIELD_NAMESPACE}.#{k.sub(ENV_REGEX, '')}"
190
- event.add_field(namespaced_k, v)
189
+ field_name = k.sub(ENV_REGEX, '')
190
+ add_app_field(event, field_name, v)
191
191
  env.delete(k)
192
192
  end
193
193
  end
@@ -197,18 +197,45 @@ module Rack
197
197
  event.add_field('response.status_code', status)
198
198
  end
199
199
 
200
- def adding_span_metadata_if_available(event, env)
201
- return yield unless defined?(::Honeycomb.with_trace_id)
202
-
203
- ::Honeycomb.with_trace_id do |trace_id|
204
- event.add_field 'trace.trace_id', trace_id
205
- span_id = trace_id # so this shows up as a root span
206
- event.add_field 'trace.span_id', span_id
207
- ::Honeycomb.with_span_id(span_id) do
208
- yield
200
+ def with_tracing_if_available(event, env)
201
+ # return if we are not using the ruby beeline
202
+ return yield unless defined?(::Honeycomb)
203
+
204
+ # beeline version <= 0.5.0
205
+ if ::Honeycomb.respond_to? :with_trace_id
206
+ ::Honeycomb.with_trace_id do |trace_id|
207
+ event.add_field "trace.trace_id", trace_id
208
+ # so this shows up as a root span
209
+ event.add_field "trace.span_id", trace_id
210
+ ::Honeycomb.with_span_id(trace_id) do
211
+ yield
212
+ end
213
+ end
214
+ # beeline version > 0.5.0
215
+ elsif ::Honeycomb.respond_to? :trace_from_encoded_context
216
+ encoded_context = trace_context_from_header(env)
217
+ ::Honeycomb.trace_from_encoded_context(encoded_context) do
218
+ ::Honeycomb.span_for_existing_event(
219
+ event,
220
+ name: nil, # this is only added if it is present, we set the name in #add_request_fields
221
+ type: EVENT_TYPE,
222
+ ) do
223
+ yield
224
+ end
209
225
  end
226
+ # fallback if we don't detect any known beeline tracing methods
227
+ else
228
+ yield
210
229
  end
211
230
  end
231
+
232
+ def trace_context_from_header(env)
233
+ env['HTTP_X_HONEYCOMB_TRACE']
234
+ end
235
+
236
+ def add_app_field(event, k, v)
237
+ event.add_field "#{APP_FIELD_NAMESPACE}.#{k}", v
238
+ end
212
239
  end
213
240
 
214
241
  class << self
@@ -1,5 +1,5 @@
1
1
  module Rack
2
2
  module Honeycomb
3
- VERSION="0.3.0"
3
+ VERSION="0.4.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-honeycomb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - The Honeycomb.io Team
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-11-16 00:00:00.000000000 Z
11
+ date: 2018-11-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bump