skylight 1.7.0 → 1.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 55eaebadf3fb220c9b3dbccdfc9a7a24daff7eda6775b89e58ea5fe0e2a1ba56
4
- data.tar.gz: 894eb4d03f6b66ca6301884c98f754f0d03dbdb416e40a662b34733e2c5c19f5
3
+ metadata.gz: ad288b69779cb31529b64adbc47d976b06f5300cbb7ff0687b94d412880311dc
4
+ data.tar.gz: de757d14b9080b43e2e0d139965fade57bcaabe924e975b4b46ddbe1f7907563
5
5
  SHA512:
6
- metadata.gz: 9e18ee5d48433c0bdb42090e975ccffbd28b34e179a77f252048bccc27669f41b08a6648aabc55b79eac2158ee57ac74b3308f22bc8ff25e2da1d50efe552073
7
- data.tar.gz: d346a3b7a24e4453324273320c8400d998302a4c658957aef9274fd40f8735c2f33f8245e6ef33ed1dbc39ac081b0fb7bee7addce81f02c4c1457257bf3cddb7
6
+ metadata.gz: 023eff94d6cacf557aeac45a4fee501bf90ac4595d58a671789f3bb6b4726230be6fe3b36805af173809226bbc8c1181d0c073f45d935486da818b824ae47f3f
7
+ data.tar.gz: 4e538a415d63cd62208c6b51ed816e0202e20b9ffc926628e631eeedd896d6dc3c95d83bfc24d1894e83664dadee68a0b80d94e49c2207c5c55b286c333b6e61
@@ -1,3 +1,6 @@
1
+ ## 1.7.1 (October 16 2018)
2
+ * [BUGFIX] (Backported from 2.x series) Fix issue wherein certain error-handling patterns could break the middleware probe.
3
+
1
4
  ## 1.7.0 (April 24, 2018)
2
5
 
3
6
  * [FEATURE] New API for loading Probes. Example: `Skylight.probe(:excon')`
@@ -17,11 +17,21 @@ module Skylight
17
17
  span = Skylight.instrument(title: name, category: "#{category}")
18
18
  resp = call_without_sk(*args, &block)
19
19
 
20
- Skylight::Middleware.with_after_close(resp) { trace.done(span) }
21
- rescue Exception
20
+ proxied_response = Skylight::Middleware.with_after_close(resp) do
21
+ trace.done(span)
22
+ end
23
+ rescue Exception => err
22
24
  # FIXME: Log this?
23
- trace.done(span)
25
+ trace.done(span, exception_object: err)
24
26
  raise
27
+ ensure
28
+ unless err || proxied_response
29
+ # If we've gotten to this point, the most likely scenario is that
30
+ # a throw/catch has bypassed a portion of the callstack. Since these spans would not otherwise
31
+ # be closed, mark them deferred to indicate that they should be implicitly closed.
32
+ # See Core::Trace#deferred_spans or Core::Trace#stop for more information.
33
+ trace.done(span, defer: true)
34
+ end
25
35
  end
26
36
  end
27
37
  RUBY
@@ -95,9 +95,15 @@ module Skylight
95
95
  nil
96
96
  end
97
97
 
98
- def done(span)
98
+ def done(span, meta=nil)
99
99
  return unless span
100
100
  return if broken?
101
+
102
+ if meta && meta[:defer]
103
+ deferred_spans[span] ||= (Util::Clock.nanos - gc_time)
104
+ return
105
+ end
106
+
101
107
  stop(span, Util::Clock.nanos - gc_time)
102
108
  rescue => e
103
109
  error "failed to close span; msg=%s; endpoint=%s", e.message, endpoint
@@ -105,6 +111,13 @@ module Skylight
105
111
  nil
106
112
  end
107
113
 
114
+ # Middleware spans that were interrupted by a throw/catch should be cached here.
115
+ # keys: span ids
116
+ # values: nsec timestamp at which the span was cached here.
117
+ def deferred_spans
118
+ @deferred_spans ||= {}
119
+ end
120
+
108
121
  def release
109
122
  return unless @instrumenter.current_trace == self
110
123
  @instrumenter.current_trace = nil
@@ -171,29 +184,43 @@ module Skylight
171
184
  def stop(span, time)
172
185
  t { "stopping span: #{span}" }
173
186
 
174
- expected = @spans.pop
175
- unless span == expected
176
- message = "[E0001] Spans were closed out of order.\n"
187
+ # If `stop` is called for a span that is not the last item in the stack,
188
+ # check to see if the last item has been marked as deferred. If so, close
189
+ # that span first, then try to close the original.
190
+ while deferred_spans[expected = @spans.pop]
191
+ normalized_stop(expected, deferred_spans.delete(expected))
192
+ end
193
+
194
+ handle_unexpected_stop(expected, span) unless span == expected
177
195
 
178
- if Skylight::Util::Logging.trace?
179
- message << "Expected #{expected}, but received #{span}. See prior logs to match id to a name.\n" \
180
- "If the received span was a Middleware it may be one that doesn't fully conform to " \
181
- "the Rack SPEC."
182
- else
183
- message << "To debug this issue set `SKYLIGHT_ENABLE_TRACE_LOGS=true` " \
184
- "in your environment. (Beware, it is quite noisy!)\n"
185
- end
196
+ normalized_stop(span, time)
197
+ nil
198
+ end
186
199
 
187
- message << "This request will not be tracked. Please contact support@skylight.io for more information."
200
+ def normalized_stop(span, time)
201
+ time = self.class.normalize_time(time)
202
+ native_stop_span(span, time)
203
+ end
188
204
 
189
- error message
205
+ def handle_unexpected_stop(expected, span)
206
+ message = "[E0001] Spans were closed out of order.\n"
190
207
 
191
- broken!
208
+ if Skylight::Util::Logging.trace?
209
+ message << "Expected #{expected}, but received #{span}. See prior logs to match id to a name.\n" \
210
+ "If the received span was a Middleware it may be one that doesn't fully conform to " \
211
+ "the Rack SPEC."
212
+ else
213
+ message << "To debug this issue set `SKYLIGHT_ENABLE_TRACE_LOGS=true` " \
214
+ "in your environment. (Beware, it is quite noisy!)\n"
192
215
  end
193
216
 
194
- time = self.class.normalize_time(time)
195
- native_stop_span(span, time)
196
- nil
217
+ message << "\nThis request will not be tracked. Please contact support@skylight.io for more information."
218
+
219
+ error message
220
+
221
+ t { "expected=#{expected}, actual=#{span}" }
222
+
223
+ broken!
197
224
  end
198
225
 
199
226
  def gc_time
@@ -1,4 +1,4 @@
1
1
  module Skylight
2
- VERSION = '1.7.0'
2
+ VERSION = '1.7.1'
3
3
  end
4
4
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: skylight
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.0
4
+ version: 1.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tilde, Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-04-25 00:00:00.000000000 Z
11
+ date: 2018-10-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport