Class: Bugstack::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/bugstack/client.rb

Overview

Core client for capturing and reporting errors to BugStack. Thread-safe. Handles deduplication, filtering, and transport.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Client

Returns a new instance of Client.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/bugstack/client.rb', line 9

def initialize(config)
  @config = config
  @deduplicator = Deduplicator.new(window: config.deduplication_window)
  @transport = nil

  if config.enabled && !config.dry_run
    @transport = Transport.new(
      endpoint: config.endpoint,
      api_key: config.api_key,
      timeout: config.timeout,
      max_retries: config.max_retries,
      debug: config.debug
    )
  end

  log_debug("Client initialized (endpoint=#{config.endpoint}, dry_run=#{config.dry_run})")
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



7
8
9
# File 'lib/bugstack/client.rb', line 7

def config
  @config
end

Instance Method Details

#capture_exception(exception, request: nil, metadata: nil) ⇒ Boolean

Capture an exception and send it to BugStack.

Parameters:

  • (defaults to: nil)

    { route:, method: }

  • (defaults to: nil)

Returns:



33
34
35
36
37
38
# File 'lib/bugstack/client.rb', line 33

def capture_exception(exception, request: nil, metadata: nil)
  do_capture(exception, request: request, metadata: )
rescue => e
  log_debug("Error during capture: #{e.message}")
  false
end

#shutdownObject

Shut down the client and flush pending events.



41
42
43
44
# File 'lib/bugstack/client.rb', line 41

def shutdown
  @transport&.shutdown
  @transport = nil
end