Class: Lapsoss::Client

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

Instance Method Summary collapse

Constructor Details

#initialize(configuration) ⇒ Client

Returns a new instance of Client.



7
8
9
10
11
# File 'lib/lapsoss/client.rb', line 7

def initialize(configuration)
  @configuration = configuration
  # Note: We're using Thread.new directly for async mode instead of a thread pool
  # The Concurrent::FixedThreadPool had issues in Rails development mode
end

Instance Method Details

#add_breadcrumb(message, type: :default, **metadata) ⇒ Object



45
46
47
# File 'lib/lapsoss/client.rb', line 45

def add_breadcrumb(message, type: :default, **)
  current_scope.add_breadcrumb(message, type: type, **)
end

#capture_exception(exception, level: :error, **context) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/lapsoss/client.rb', line 13

def capture_exception(exception, level: :error, **context)
  return nil unless @configuration.enabled

  extra_context = context.delete(:context)
  with_scope(context) do |scope|
    event = Event.build(
      type: :exception,
      level: level,
      exception: exception,
      context: merge_context(scope_to_context(scope), extra_context),
      transaction: scope.transaction_name
    )
    capture_event(event)
  end
end

#capture_message(message, level: :info, **context) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/lapsoss/client.rb', line 29

def capture_message(message, level: :info, **context)
  return nil unless @configuration.enabled

  extra_context = context.delete(:context)
  with_scope(context) do |scope|
    event = Event.build(
      type: :message,
      level: level,
      message: message,
      context: merge_context(scope_to_context(scope), extra_context),
      transaction: scope.transaction_name
    )
    capture_event(event)
  end
end

#current_scopeObject



61
62
63
# File 'lib/lapsoss/client.rb', line 61

def current_scope
  Current.scope ||= Scope.new
end

#flush(timeout: 2) ⇒ Object



65
66
67
68
69
70
71
72
73
74
# File 'lib/lapsoss/client.rb', line 65

def flush(timeout: 2)
  @configuration.logger.debug("[LAPSOSS] Flush called with timeout: #{timeout}")
  # Give threads a moment to complete
  sleep(0.5) if @configuration.async

  # Flush individual adapters if they support it
  Registry.instance.active.each do |adapter|
    adapter.flush(timeout: timeout) if adapter.respond_to?(:flush)
  end
end

#shutdownObject



76
77
78
# File 'lib/lapsoss/client.rb', line 76

def shutdown
  Registry.instance.shutdown
end

#with_scope(context = {}) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
# File 'lib/lapsoss/client.rb', line 49

def with_scope(context = {})
  original_scope = current_scope

  # Create a merged scope with the new context
  merged_scope = MergedScope.new([ context ], original_scope)
  Current.scope = merged_scope

  yield(merged_scope)
ensure
  Current.scope = original_scope
end