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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
# File 'app/helpers/flare/application_helper.rb', line 27
def span_display_info(span, category)
props = span[:properties] || {}
case category
when "queries"
stmt = props["db.statement"]&.to_s
name = props["name"]&.to_s
db_name = props["db.name"]&.to_s
source_loc = if props["code.filepath"] && props["code.lineno"]
"#{props["code.filepath"]}:#{props["code.lineno"]}"
end
secondary = [name.presence, db_name.presence, source_loc].compact.join(" \u00b7 ").presence
if stmt.present?
{ primary: stmt, secondary: secondary }
elsif name.present?
{ primary: name, secondary: [db_name.presence, source_loc].compact.join(" \u00b7 ").presence }
else
{ primary: span[:name], secondary: [db_name.presence, source_loc].compact.join(" \u00b7 ").presence }
end
when "cache"
key = props["key"]&.to_s
op = span[:name].to_s.sub(".active_support", "").sub("cache_", "")
store = props["store"]&.to_s&.sub(/^ActiveSupport::Cache::/, "")
{ primary: key.presence || span[:name], secondary: store, cache_op: op }
when "views"
identifier = props["identifier"] || props["code.filepath"]
primary = identifier ? identifier.to_s.sub(/^.*\/app\/views\//, "") : span[:name]
{ primary: primary, secondary: nil }
when "http"
full_url = props["http.url"] || ""
target = props["url.path"] || props["http.target"] || ""
host = props["server.address"] || props["http.host"] || props["net.peer.name"] || props["peer.service"]
uri = URI.parse(full_url) rescue nil
if uri && uri.host
domain = uri.host
path = uri.path.presence || "/"
path = "#{path}?#{uri.query}" if uri.query.present?
else
domain = host
path = target.presence || full_url
end
method = props["http.request.method"] || props["http.method"]
status = props["http.response.status_code"] || props["http.status_code"]
{ primary: path.to_s.truncate(100), secondary: domain, http_method: method, http_status: status }
when "mail"
mailer = props["mailer"]
action = props["action"]
subject = props["subject"]
if mailer && action
{ primary: "#{mailer}##{action}", secondary: subject }
else
{ primary: span[:name], secondary: nil }
end
when "redis"
cmd = props["db.statement"]&.to_s
{ primary: cmd.presence || span[:name], secondary: nil }
when "exceptions"
exc_type = span[:exception_type]
exc_message = span[:exception_message]
primary = if exc_type.present? && exc_message.present?
"#{exc_type}: #{exc_message}"
elsif exc_message.present?
exc_message
elsif exc_type.present?
exc_type
else
span[:name]
end
stacktrace = span[:exception_stacktrace].to_s
first_app_line = stacktrace.split("\n").find { |line| line.include?("/app/") } || stacktrace.split("\n").first
secondary = first_app_line&.strip.to_s.truncate(200)
{ primary: primary, secondary: secondary }
else
{ primary: span[:name], secondary: nil }
end
end
|