Module: Sentiero::Reporter
- Defined in:
- lib/sentiero/reporter.rb,
lib/sentiero/reporter/context.rb,
lib/sentiero/reporter/scrubber.rb,
lib/sentiero/reporter/dispatcher.rb,
lib/sentiero/reporter/middleware.rb,
lib/sentiero/reporter/normalizer.rb,
lib/sentiero/reporter/test_helper.rb,
lib/sentiero/reporter/configuration.rb,
lib/sentiero/reporter/log_transport.rb,
lib/sentiero/reporter/http_transport.rb,
lib/sentiero/reporter/null_transport.rb,
lib/sentiero/reporter/report_context.rb,
lib/sentiero/reporter/test_transport.rb
Overview
Client SDK for reporting exceptions and custom events to a (remote) Sentiero
ingest. Every public method is fail-safe: it never raises into the host app.
Defined Under Namespace
Modules: Normalizer, TestHelper
Classes: Configuration, Context, Dispatcher, HttpTransport, LogTransport, Middleware, NullTransport, ReportContext, Scrubber, TestTransport
Constant Summary
collapse
- RUNTIME_LOCK =
Guards lazy creation/teardown of the shared dispatcher (which spawns a
background thread + queue) so a concurrent cold start can't build two.
Mutex.new
Class Method Summary
collapse
Class Method Details
.add_context(hash) ⇒ Object
74
75
76
|
# File 'lib/sentiero/reporter.rb', line 74
def add_context(hash)
self.fiber_local_context = context_store.merge(hash)
end
|
.clear_context ⇒ Object
86
87
88
|
# File 'lib/sentiero/reporter.rb', line 86
def clear_context
self.fiber_local_context = Context.new
end
|
.configuration ⇒ Object
25
26
27
|
# File 'lib/sentiero/reporter.rb', line 25
def configuration
@configuration ||= Configuration.new
end
|
29
30
31
32
33
|
# File 'lib/sentiero/reporter.rb', line 29
def configure
yield(configuration)
reset_runtime!
configuration
end
|
.context ⇒ Object
Per-thread context. Stored as a Context (string-keyed by construction)
so readback is consistently string-keyed.
70
71
72
|
# File 'lib/sentiero/reporter.rb', line 70
def context
context_store.to_h
end
|
.flush ⇒ Object
90
91
92
|
# File 'lib/sentiero/reporter.rb', line 90
def flush
@dispatcher&.flush
end
|
.notify(exception, context: {}) ⇒ Object
44
45
46
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/sentiero/reporter.rb', line 44
def notify(exception, context: {})
return unless configuration.active?
return if ignored?(exception)
payload = run_before_notify(build_error_payload(exception, build_report_context(context)))
return if payload.nil?
dispatcher.enqueue("errors", payload)
nil
rescue => e
warn "[Sentiero::Reporter] notify failed: #{e.class}: #{e.message}"
nil
end
|
.reset! ⇒ Object
35
36
37
38
39
40
41
42
|
# File 'lib/sentiero/reporter.rb', line 35
def reset!
RUNTIME_LOCK.synchronize do
shutdown
@configuration = Configuration.new
@dispatcher = nil
@scrubber = nil
end
end
|
.shutdown ⇒ Object
94
95
96
|
# File 'lib/sentiero/reporter.rb', line 94
def shutdown
@dispatcher&.shutdown
end
|
.track(name, level: "info", session_id: nil, **payload) ⇒ Object
58
59
60
61
62
63
64
65
66
|
# File 'lib/sentiero/reporter.rb', line 58
def track(name, level: "info", session_id: nil, **payload)
return unless configuration.active?
dispatcher.enqueue("track", build_track_event(name, level, session_id, payload))
nil
rescue => e
warn "[Sentiero::Reporter] track failed: #{e.class}: #{e.message}"
nil
end
|
.with_context(hash) ⇒ Object
78
79
80
81
82
83
84
|
# File 'lib/sentiero/reporter.rb', line 78
def with_context(hash)
previous = context_store
self.fiber_local_context = context_store.merge(hash)
yield
ensure
self.fiber_local_context = previous
end
|