Class: Checkend::NoticeBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/checkend/notice_builder.rb

Overview

NoticeBuilder converts Ruby exceptions into Notice objects.

It handles backtrace cleaning, context merging, and user info extraction.

Constant Summary collapse

MAX_BACKTRACE_LINES =
100
MAX_MESSAGE_LENGTH =
10_000

Class Method Summary collapse

Class Method Details

.build(exception:, context: {}, request: nil, user: nil, fingerprint: nil, tags: []) ⇒ Notice

Build a Notice from an exception

Parameters:

  • exception (Exception) —

    the exception to report

  • context (Hash) (defaults to: {}) —

    additional context data

  • request (Hash) (defaults to: nil) —

    request information

  • user (Hash) (defaults to: nil) —

    user information

  • fingerprint (String) (defaults to: nil) —

    custom fingerprint for grouping

  • tags (Array<String>) (defaults to: []) —

    tags for filtering

Returns:

  • (Notice) —

    the constructed notice



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/checkend/notice_builder.rb', line 22

def build(exception:, context: {}, request: nil, user: nil, fingerprint: nil, tags: [])
  notice = Notice.new

  # Error info
  notice.error_class = exception.class.name
  notice.message = truncate_message(exception.message)
  notice.backtrace = clean_backtrace(exception.backtrace || [])
  notice.fingerprint = fingerprint
  notice.tags = Array(tags)

  # Merge thread-local context with provided context
  notice.context = merge_context(context)
  notice.user = user || thread_local_user
  notice.request = request || {}

  # Environment
  notice.environment = Checkend.configuration.environment

  notice
end