Module: SolidEvents::TracesHelper

Includes:
ActionView::Helpers::DateHelper, ActionView::Helpers::NumberHelper
Defined in:
app/helpers/solid_events/traces_helper.rb

Instance Method Summary collapse

Instance Method Details

#absolute_time(time) ⇒ Object



28
29
30
31
32
# File 'app/helpers/solid_events/traces_helper.rb', line 28

def absolute_time(time)
  return "n/a" unless time

  time.strftime("%Y-%m-%d %H:%M:%S %Z")
end

#duration_delta_label(recent_ms, baseline_ms) ⇒ Object



71
72
73
74
75
76
77
# File 'app/helpers/solid_events/traces_helper.rb', line 71

def duration_delta_label(recent_ms, baseline_ms)
  return "n/a" unless recent_ms && baseline_ms

  delta = (recent_ms - baseline_ms).round(2)
  sign = delta.positive? ? "+" : ""
  "#{sign}#{delta} ms"
end

#event_payload_summary(event) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/helpers/solid_events/traces_helper.rb', line 34

def event_payload_summary(event)
  payload = event.payload.to_h
  return "{}" if payload.empty?

  if event.event_type == "sql"
    sql = payload["sql"] || payload[:sql]
    return truncate(sql.to_s.squish, length: 160) if sql.present?
  end

  truncate(payload.to_json, length: 160)
rescue StandardError
  "{}"
end

#formatted_trace_duration(trace) ⇒ Object



16
17
18
19
20
# File 'app/helpers/solid_events/traces_helper.rb', line 16

def formatted_trace_duration(trace)
  return "n/a" unless trace.finished_at && trace.started_at

  "#{((trace.finished_at - trace.started_at) * 1000.0).round(2)} ms"
end

#relative_time(time) ⇒ Object



22
23
24
25
26
# File 'app/helpers/solid_events/traces_helper.rb', line 22

def relative_time(time)
  return "n/a" unless time

  "#{time_ago_in_words(time)} ago"
end


56
57
58
# File 'app/helpers/solid_events/traces_helper.rb', line 56

def trace_error_link_count(trace)
  trace.summary&.error_count || trace.error_links.size
end

#trace_event_count(trace) ⇒ Object



48
49
50
# File 'app/helpers/solid_events/traces_helper.rb', line 48

def trace_event_count(trace)
  trace.summary&.event_count || trace.events.size
end


52
53
54
# File 'app/helpers/solid_events/traces_helper.rb', line 52

def trace_record_link_count(trace)
  trace.summary&.record_link_count || trace.record_links.size
end

#trace_sql_count(trace) ⇒ Object



60
61
62
# File 'app/helpers/solid_events/traces_helper.rb', line 60

def trace_sql_count(trace)
  trace.summary&.sql_count || trace.events.count { |event| event.event_type == "sql" }
end

#trace_sql_duration_ms(trace) ⇒ Object



64
65
66
67
68
69
# File 'app/helpers/solid_events/traces_helper.rb', line 64

def trace_sql_duration_ms(trace)
  value = trace.summary&.sql_duration_ms
  return value if value

  trace.events.select { |event| event.event_type == "sql" }.sum { |event| event.duration_ms.to_f }.round(2)
end

#trace_status_badge(status) ⇒ Object



8
9
10
11
12
13
14
# File 'app/helpers/solid_events/traces_helper.rb', line 8

def trace_status_badge(status)
  case status.to_s
  when "ok" then "ok"
  when "error" then "error"
  else "muted"
  end
end