Module: Errsight
- Defined in:
- lib/errsight.rb,
lib/errsight/hub.rb,
lib/errsight/scope.rb,
lib/errsight/client.rb,
lib/errsight/logger.rb,
lib/errsight/railtie.rb,
lib/errsight/sidekiq.rb,
lib/errsight/version.rb,
lib/errsight/backtrace.rb,
lib/errsight/middleware.rb,
lib/errsight/configuration.rb,
lib/errsight/source_context.rb,
lib/errsight/capture_middleware.rb,
lib/errsight/integrations/active_job.rb,
lib/errsight/integrations/active_record.rb,
lib/errsight/integrations/rails_error_reporter.rb
Defined Under Namespace
Modules: Backtrace, Integrations, Sidekiq, SourceContext Classes: CaptureMiddleware, Client, Configuration, ConfigurationError, Error, Hub, Logger, Middleware, Railtie, Scope
Constant Summary collapse
- VERSION =
"0.2.1"
Class Method Summary collapse
- .add_breadcrumb(**kwargs) ⇒ Object
- .capture_exception(exception, metadata: {}, fingerprint: nil, user: nil, tags: nil) ⇒ Object
- .clear_breadcrumbs ⇒ Object
- .clear_tags ⇒ Object
- .clear_user ⇒ Object
- .client ⇒ Object
- .configuration ⇒ Object
- .configure {|configuration| ... } ⇒ Object
- .current_scope ⇒ Object
- .hub ⇒ Object
- .log(level:, message:, backtrace: nil, environment: nil, metadata: {}, occurred_at: nil, fingerprint: nil, user: nil, tags: nil, release: nil) ⇒ Object
- .set_tag(key, value) ⇒ Object
- .set_tags(tags) ⇒ Object
-
.set_user(user) ⇒ Object
Public scope mutators delegate to the current (top-of-stack) scope.
-
.with_scope(scope = nil, &block) ⇒ Object
Push a fresh scope for the duration of the block, then pop on exit.
Class Method Details
.add_breadcrumb(**kwargs) ⇒ Object
60 |
# File 'lib/errsight.rb', line 60 def (**kwargs); current_scope.(**kwargs); end |
.capture_exception(exception, metadata: {}, fingerprint: nil, user: nil, tags: nil) ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/errsight.rb', line 91 def capture_exception(exception, metadata: {}, fingerprint: nil, user: nil, tags: nil) return unless exception.is_a?(Exception) = .merge(exception_class: exception.class.to_s) causes = walk_exception_causes(exception) [:exception_causes] = causes if causes.any? frames = build_frames(exception) [:exception_frames] = frames if frames.any? log( level: :error, message: "#{exception.class}: #{exception.}", backtrace: exception.backtrace&.join("\n"), metadata: , fingerprint: fingerprint, user: user, tags: ) end |
.clear_breadcrumbs ⇒ Object
61 |
# File 'lib/errsight.rb', line 61 def ; current_scope.; end |
.clear_tags ⇒ Object
59 |
# File 'lib/errsight.rb', line 59 def ; current_scope.; end |
.clear_user ⇒ Object
56 |
# File 'lib/errsight.rb', line 56 def clear_user; current_scope.clear_user; end |
.client ⇒ Object
29 30 31 |
# File 'lib/errsight.rb', line 29 def client @client ||= Client.new(configuration) end |
.configuration ⇒ Object
19 20 21 |
# File 'lib/errsight.rb', line 19 def configuration @configuration ||= Configuration.new end |
.configure {|configuration| ... } ⇒ Object
23 24 25 26 27 |
# File 'lib/errsight.rb', line 23 def configure yield configuration configuration.validate! configuration end |
.current_scope ⇒ Object
37 38 39 |
# File 'lib/errsight.rb', line 37 def current_scope hub.current_scope end |
.log(level:, message:, backtrace: nil, environment: nil, metadata: {}, occurred_at: nil, fingerprint: nil, user: nil, tags: nil, release: nil) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/errsight.rb', line 63 def log(level:, message:, backtrace: nil, environment: nil, metadata: {}, occurred_at: nil, fingerprint: nil, user: nil, tags: nil, release: nil) return unless configuration.enabled? return if level_below_threshold?(level) scope = current_scope event = { ingestion_id: SecureRandom.uuid, level: level.to_s, message: .to_s, backtrace: backtrace, environment: environment || configuration.environment, metadata: , occurred_at: (occurred_at || Time.now).iso8601(3), release: release || configuration.release, user: user || scope.user, tags: (scope., ), breadcrumbs: scope. } event[:fingerprint] = fingerprint if fingerprint event.compact! event = run_before_send(event) return if event.nil? client.enqueue(event) end |
.set_tag(key, value) ⇒ Object
57 |
# File 'lib/errsight.rb', line 57 def set_tag(key, value); current_scope.set_tag(key, value); end |
.set_tags(tags) ⇒ Object
58 |
# File 'lib/errsight.rb', line 58 def (); current_scope.(); end |
.set_user(user) ⇒ Object
Public scope mutators delegate to the current (top-of-stack) scope. Pre-scope-stack callers wrote directly to Thread.current and relied on the request middleware to clear; those reads bled across requests on long-lived Puma/Sidekiq threads. The stack guarantees cleanup at the block boundary regardless of caller hygiene.
55 |
# File 'lib/errsight.rb', line 55 def set_user(user); current_scope.set_user(user); end |
.with_scope(scope = nil, &block) ⇒ Object
Push a fresh scope for the duration of the block, then pop on exit. Used by request and job middleware so user/tags/breadcrumbs set during one unit of work don’t leak to the next one handled by the same thread. Pass an explicit Scope to install a pre-built one (e.g. rehydrated from a Sidekiq job payload).
46 47 48 |
# File 'lib/errsight.rb', line 46 def with_scope(scope = nil, &block) hub.with_scope(scope, &block) end |