logbrew-sdk 0.1.7 → 0.1.8
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 +4 -4
- data/README.md +1 -1
- data/lib/logbrew/trace.rb +4 -14
- data/lib/logbrew/version.rb +1 -1
- data/lib/logbrew.rb +24 -18
- 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: 23bb3971a708e01fb3baa93461beb30dda7ff5a6d1b807a6f21a2c4365b718ee
|
|
4
|
+
data.tar.gz: 2254bb2a7317aa32053e43ae2463ba527c8ec4bd9d7147d31a1c085df690857d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b516708afcb021d131aac74c02b0dae2b97d04875f45ec408ff431a5046d2c12af0e824ddddbd5e9280c934ed2a016615cabb4e9d035174c2da99e4806afbc14
|
|
7
|
+
data.tar.gz: '09b94b37beba32a8956b06295ca7ad0b4f16b0de21e1148a127797f1fd61f0c7763dc85b336ee7a8e249dbd38f02e2e878aadb855dc6beb4404584a5ae6b89d4'
|
data/README.md
CHANGED
data/lib/logbrew/trace.rb
CHANGED
|
@@ -240,7 +240,7 @@ module LogBrew
|
|
|
240
240
|
|
|
241
241
|
private
|
|
242
242
|
|
|
243
|
-
def capture_request_span(env, status_code, elapsed_ms, status)
|
|
243
|
+
def capture_request_span(env, status_code, elapsed_ms, status, timestamp)
|
|
244
244
|
context = rack_trace_context(env)
|
|
245
245
|
attributes = {
|
|
246
246
|
name: request_name(env),
|
|
@@ -252,31 +252,21 @@ module LogBrew
|
|
|
252
252
|
}
|
|
253
253
|
attributes[:parentSpanId] = context.parent_span_id if context && context.parent_span_id
|
|
254
254
|
|
|
255
|
-
@client.span(next_event_id("span"),
|
|
255
|
+
@client.span(next_event_id("span"), timestamp, attributes)
|
|
256
256
|
end
|
|
257
257
|
|
|
258
258
|
def trace_id(env)
|
|
259
|
-
|
|
260
|
-
return context.trace_id if context
|
|
261
|
-
|
|
262
|
-
super
|
|
259
|
+
rack_trace_context(env)&.trace_id || super
|
|
263
260
|
end
|
|
264
261
|
|
|
265
262
|
def span_id(env)
|
|
266
|
-
|
|
267
|
-
return context.span_id if context
|
|
268
|
-
|
|
269
|
-
super
|
|
263
|
+
rack_trace_context(env)&.span_id || super
|
|
270
264
|
end
|
|
271
265
|
|
|
272
266
|
def request_metadata(env, status_code)
|
|
273
267
|
Trace.add_metadata(super, rack_trace_context(env))
|
|
274
268
|
end
|
|
275
269
|
|
|
276
|
-
def exception_metadata(env, error)
|
|
277
|
-
Trace.add_metadata(super, rack_trace_context(env))
|
|
278
|
-
end
|
|
279
|
-
|
|
280
270
|
def rack_trace_context(env)
|
|
281
271
|
trace = env["logbrew.trace"] if env.respond_to?(:[])
|
|
282
272
|
trace.is_a?(TraceContext) ? trace : Trace.current
|
data/lib/logbrew/version.rb
CHANGED
data/lib/logbrew.rb
CHANGED
|
@@ -45,9 +45,9 @@ module LogBrew
|
|
|
45
45
|
metadata.each_with_object({}) { |(key, value), copied| copied[key.to_s] = value if primitive_metadata_value?(value) }
|
|
46
46
|
end
|
|
47
47
|
|
|
48
|
-
def logbrew_timestamp
|
|
48
|
+
def logbrew_timestamp(precision = nil)
|
|
49
49
|
timestamp = @timestamp_provider.respond_to?(:call) ? @timestamp_provider.call : Time.now
|
|
50
|
-
timestamp.respond_to?(:iso8601) ? timestamp.iso8601 : timestamp.to_s
|
|
50
|
+
timestamp.respond_to?(:iso8601) ? timestamp.iso8601(*[precision].compact) : timestamp.to_s
|
|
51
51
|
end
|
|
52
52
|
|
|
53
53
|
def capture_safely
|
|
@@ -412,36 +412,42 @@ module LogBrew
|
|
|
412
412
|
|
|
413
413
|
def call(env)
|
|
414
414
|
started_at = monotonic_time
|
|
415
|
-
|
|
416
|
-
|
|
415
|
+
started_timestamp, timestamp_error = request_timestamp
|
|
416
|
+
response = begin
|
|
417
|
+
@app.call(env)
|
|
417
418
|
rescue StandardError => error
|
|
418
|
-
|
|
419
|
-
capture_safely do
|
|
420
|
-
capture_exception_issue(env, error) if status_code >= 500
|
|
421
|
-
capture_request_span(env, status_code, duration_ms(started_at), status_code >= 500 ? "error" : "ok")
|
|
422
|
-
flush_if_configured
|
|
423
|
-
end
|
|
419
|
+
capture_request(env, exception_status_code(error), started_at, started_timestamp, timestamp_error, error)
|
|
424
420
|
raise
|
|
425
421
|
end
|
|
422
|
+
capture_request(env, rack_status(response), started_at, started_timestamp, timestamp_error)
|
|
423
|
+
response
|
|
424
|
+
end
|
|
425
|
+
|
|
426
|
+
private
|
|
426
427
|
|
|
427
|
-
|
|
428
|
+
def capture_request(env, status_code, started_at, timestamp, timestamp_error, error = nil)
|
|
428
429
|
capture_safely do
|
|
429
|
-
|
|
430
|
+
raise timestamp_error unless timestamp_error.nil?
|
|
431
|
+
capture_exception_issue(env, error, logbrew_timestamp(6)) if error && status_code >= 500
|
|
432
|
+
capture_request_span(env, status_code, duration_ms(started_at), status_code >= 500 ? "error" : "ok", timestamp)
|
|
430
433
|
flush_if_configured
|
|
431
434
|
end
|
|
432
|
-
response
|
|
433
435
|
end
|
|
434
436
|
|
|
435
|
-
|
|
437
|
+
def request_timestamp
|
|
438
|
+
[logbrew_timestamp(6), nil]
|
|
439
|
+
rescue StandardError => error
|
|
440
|
+
[nil, error]
|
|
441
|
+
end
|
|
436
442
|
|
|
437
443
|
def exception_status_code(_error)
|
|
438
444
|
500
|
|
439
445
|
end
|
|
440
446
|
|
|
441
|
-
def capture_request_span(env, status_code, elapsed_ms, status)
|
|
447
|
+
def capture_request_span(env, status_code, elapsed_ms, status, timestamp)
|
|
442
448
|
@client.span(
|
|
443
449
|
next_event_id("span"),
|
|
444
|
-
|
|
450
|
+
timestamp,
|
|
445
451
|
name: request_name(env),
|
|
446
452
|
traceId: trace_id(env),
|
|
447
453
|
spanId: span_id(env),
|
|
@@ -451,7 +457,7 @@ module LogBrew
|
|
|
451
457
|
)
|
|
452
458
|
end
|
|
453
459
|
|
|
454
|
-
def capture_exception_issue(env, error)
|
|
460
|
+
def capture_exception_issue(env, error, timestamp)
|
|
455
461
|
attributes = IssueDiagnostics.from_exception(
|
|
456
462
|
error,
|
|
457
463
|
message: @include_exception_message ? error.message : nil,
|
|
@@ -459,7 +465,7 @@ module LogBrew
|
|
|
459
465
|
handled: false,
|
|
460
466
|
metadata: exception_metadata(env, error)
|
|
461
467
|
)
|
|
462
|
-
@client.issue(next_event_id("issue"),
|
|
468
|
+
@client.issue(next_event_id("issue"), timestamp, attributes)
|
|
463
469
|
end
|
|
464
470
|
|
|
465
471
|
def next_event_id(kind)
|