Class: DebuggerServiceUtil

Inherits:
Object
  • Object
show all
Defined in:
lib/wingify/utils/debugger_service_util.rb

Class Method Summary collapse

Class Method Details

.send_debugger_event(event_props) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/wingify/utils/debugger_service_util.rb', line 25

def send_debugger_event(event_props)
  # Sampled keys: apply sampling only when alwaysApplySampling.server is true; others always send
  msg_t = event_props[:msg_t] || event_props['msg_t']
  is_sampled_debug_event = msg_t.is_a?(String) && InternalEventsSamplingUtil.is_sampled_debug_error_template_key(msg_t)

  # Resolve settings from the live SDK instance without a hard require (avoids circular load)
  settings = nil
  if defined?(Wingify) && Wingify.respond_to?(:instance)
    instance = Wingify.instance
    settings = instance.respond_to?(:settings) ? instance.settings : nil
  end

  # If msg_t is in the sampled set, drop the event when the sampling check fails
  if is_sampled_debug_event
    sampling_service = InternalEventsSamplingService.new
    return unless sampling_service.should_send_sampled_debug_event(settings)
  end

  # get base properties for the event
  properties = NetworkUtil.get_events_base_properties(EventEnum::DEBUGGER_EVENT)

  # get debugger event payload
  payload = NetworkUtil.get_debugger_event_payload(event_props)

  # send event
  if BatchEventsQueue.instance
    # add the payload to the batch events queue
    BatchEventsQueue.instance.enqueue(payload)
  else
    # Send the prepared payload via POST API request
    NetworkUtil.send_event(properties, payload)
  end
end