flare 0.5.0 → 0.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +14 -0
- data/lib/flare/cli/ai_clients_setup.rb +249 -0
- data/lib/flare/cli/setup_command.rb +8 -2
- data/lib/flare/cli.rb +4 -0
- data/lib/flare/configuration.rb +8 -0
- data/lib/flare/metric_span_processor.rb +25 -2
- data/lib/flare/storage/sqlite.rb +4 -4
- data/lib/flare/version.rb +1 -1
- data/lib/flare.rb +2 -1
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5fc174023f479f7d8310b929433f258fdf4a5acb2e958d5c5480b8869cc22be5
|
|
4
|
+
data.tar.gz: 945dae2872f5d693da04fd7481fd6b74f7cae5987f1cde40ae42e439ea3fb77f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a40e785ca8110a4c4efd9fd0b4443c421758811b8dd4f8939a6410fb01d5a9e4cc0a6c3d41226241ea31bd872d7a14c579cfeba07a8b85543871df0ab8f66515
|
|
7
|
+
data.tar.gz: 21df6659516866de21ac319e555407da98a760668336c2d771426cc4cdd57b914b46c85c2fc274b66a308ca5b448ed5012dbea0a75598e5657185b334667e931
|
data/README.md
CHANGED
|
@@ -45,6 +45,7 @@ The setup command will:
|
|
|
45
45
|
1. Authenticate with flare.am to configure metrics
|
|
46
46
|
2. Create a config initializer with sensible defaults
|
|
47
47
|
3. Update .gitignore
|
|
48
|
+
4. Offer to connect Claude Code, Codex and Cursor to Flare's MCP server, so you can ask your AI assistant about your app's performance. Each one signs in to Flare the first time it connects.
|
|
48
49
|
|
|
49
50
|
Start your Rails server and visit `/flare` to see the dashboard.
|
|
50
51
|
|
|
@@ -58,6 +59,7 @@ To enable metrics, set `FLARE_KEY` in your environment (get one at [flare.am](ht
|
|
|
58
59
|
|
|
59
60
|
```bash
|
|
60
61
|
flare setup # Authenticate and configure Flare
|
|
62
|
+
flare connect # Connect your AI assistants to Flare
|
|
61
63
|
flare doctor # Check your setup for issues
|
|
62
64
|
flare status # Show current configuration
|
|
63
65
|
flare requests # List recent requests from local development spans
|
|
@@ -135,6 +137,9 @@ Flare.configure do |config|
|
|
|
135
137
|
request.path.start_with?("/health")
|
|
136
138
|
}
|
|
137
139
|
|
|
140
|
+
# Exceptions that don't count as errors in metrics (see below)
|
|
141
|
+
config.ignore_errors << "MyApp::RetryLaterError"
|
|
142
|
+
|
|
138
143
|
# Subscribe to custom notification prefixes (default: ["app."])
|
|
139
144
|
config.subscribe_patterns << "mycompany."
|
|
140
145
|
|
|
@@ -145,6 +150,15 @@ Flare.configure do |config|
|
|
|
145
150
|
end
|
|
146
151
|
```
|
|
147
152
|
|
|
153
|
+
### Errors that aren't failures
|
|
154
|
+
|
|
155
|
+
Some exceptions are control flow. A GoodJob job with `perform_limit` or `perform_throttle` raises `GoodJob::ActiveJobExtensions::Concurrency::ConcurrencyExceededError` (or its subclass `ThrottleExceededError`) to wait its turn, then retries. Flare counts a span that ends with an exception in `config.ignore_errors`, or a subclass of one, as a success: it still counts toward throughput and duration, just not the error rate. Traces still record the exception. Append your own class names, or assign a new list to replace the default:
|
|
156
|
+
|
|
157
|
+
```ruby
|
|
158
|
+
config.ignore_errors << "MyApp::RetryLaterError"
|
|
159
|
+
config.ignore_errors = [] # count every exception as an error
|
|
160
|
+
```
|
|
161
|
+
|
|
148
162
|
## Custom Instrumentation
|
|
149
163
|
|
|
150
164
|
Flare automatically captures Rails internals, but you can also instrument your own code. Use `ActiveSupport::Notifications.instrument` with an `app.` prefix:
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "json"
|
|
4
|
+
require "open3"
|
|
5
|
+
require "fileutils"
|
|
6
|
+
require "securerandom"
|
|
7
|
+
require_relative "output"
|
|
8
|
+
|
|
9
|
+
module Flare
|
|
10
|
+
# Points the AI clients on this machine at Flare's hosted MCP server, as
|
|
11
|
+
# `flare-cli setup` does. Each client signs in to Flare itself the first
|
|
12
|
+
# time it connects, so no token is written anywhere. A client that already
|
|
13
|
+
# has a different `flare` server is left alone.
|
|
14
|
+
class AIClientsSetup
|
|
15
|
+
include CLI::Output
|
|
16
|
+
|
|
17
|
+
DEFAULT_HOST = "https://flare.am"
|
|
18
|
+
SERVER_NAME = "flare"
|
|
19
|
+
FIRST_PROMPT = "Using Flare, what's slowest in production over the last 24 hours?"
|
|
20
|
+
CLIENTS = {
|
|
21
|
+
claude: "Claude Code",
|
|
22
|
+
codex: "Codex",
|
|
23
|
+
cursor: "Cursor",
|
|
24
|
+
claude_desktop: "Claude Desktop",
|
|
25
|
+
}.freeze
|
|
26
|
+
|
|
27
|
+
# Runs the clients' own CLIs. `capture` returns [output, success];
|
|
28
|
+
# `attached` shares the terminal, because Codex may start its sign-in
|
|
29
|
+
# right away and print a URL to open.
|
|
30
|
+
class Runner
|
|
31
|
+
def capture(*command)
|
|
32
|
+
output, status = Open3.capture2e(*command)
|
|
33
|
+
[output, status.success?]
|
|
34
|
+
rescue SystemCallError => e
|
|
35
|
+
[e.message, false]
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def attached(*command)
|
|
39
|
+
system(*command) == true
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def initialize(host: ENV.fetch("FLARE_HOST", DEFAULT_HOST), input: $stdin, env: ENV, home: Dir.home, platform: RUBY_PLATFORM, runner: Runner.new)
|
|
44
|
+
@host = host.chomp("/")
|
|
45
|
+
@url = "#{@host}/mcp"
|
|
46
|
+
@input = input
|
|
47
|
+
@env = env
|
|
48
|
+
@home = home
|
|
49
|
+
@platform = platform
|
|
50
|
+
@runner = runner
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# `flare setup` asks first, since this changes other apps' settings.
|
|
54
|
+
# `flare connect` is the asking. Returns false if any client failed to
|
|
55
|
+
# connect, so `flare connect` can exit non-zero.
|
|
56
|
+
def run(ask: true)
|
|
57
|
+
@failed = false
|
|
58
|
+
puts
|
|
59
|
+
puts bold("Connect your AI assistant")
|
|
60
|
+
|
|
61
|
+
clients = CLIENTS.keys.select { |client| installed?(client) }
|
|
62
|
+
if clients.empty?
|
|
63
|
+
puts " No AI clients found. To connect one later, add #{url} to it as a remote MCP server."
|
|
64
|
+
puts " See #{@host}/docs/mcp"
|
|
65
|
+
elsif !ask || confirmed?(clients)
|
|
66
|
+
connect(clients)
|
|
67
|
+
end
|
|
68
|
+
!@failed
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
private
|
|
72
|
+
|
|
73
|
+
attr_reader :url
|
|
74
|
+
|
|
75
|
+
# A closed stdin (a script, an agent) counts as no.
|
|
76
|
+
def confirmed?(clients)
|
|
77
|
+
print " Found #{clients.map { |client| CLIENTS[client] }.join(", ")}. Connect #{clients.one? ? "it" : "them"} to Flare? (Y/n): "
|
|
78
|
+
answer = @input.gets
|
|
79
|
+
reply = answer.to_s.strip.downcase
|
|
80
|
+
return true if answer && (reply.empty? || reply.start_with?("y"))
|
|
81
|
+
|
|
82
|
+
puts if answer.nil?
|
|
83
|
+
puts " Skipped. Run #{bold("flare connect")} #{answer.nil? ? "in a terminal" : "any time"} to connect them."
|
|
84
|
+
false
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
# Suggests a first question only when some client is, or is about to be,
|
|
88
|
+
# pointed at Flare.
|
|
89
|
+
def connect(clients)
|
|
90
|
+
@ready = false
|
|
91
|
+
next_steps = clients.filter_map do |client|
|
|
92
|
+
hint = send("connect_#{client}")
|
|
93
|
+
"#{CLIENTS[client]}: #{hint}" if hint
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
puts
|
|
97
|
+
if next_steps.any?
|
|
98
|
+
puts " Next:"
|
|
99
|
+
next_steps.each { |line| puts " #{line}" }
|
|
100
|
+
puts
|
|
101
|
+
puts " Then ask: #{FIRST_PROMPT.inspect}"
|
|
102
|
+
elsif @ready
|
|
103
|
+
puts " Ask: #{FIRST_PROMPT.inspect}"
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def installed?(client)
|
|
108
|
+
case client
|
|
109
|
+
when :claude then executable?("claude")
|
|
110
|
+
when :codex then executable?("codex")
|
|
111
|
+
when :cursor then executable?("cursor") || File.directory?(File.join(@home, ".cursor"))
|
|
112
|
+
when :claude_desktop then File.directory?(claude_desktop_directory)
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
def connect_claude
|
|
117
|
+
current = claude_config.dig("mcpServers", SERVER_NAME)
|
|
118
|
+
if current
|
|
119
|
+
return already(:claude) if current["type"] == "http" && current["url"] == url
|
|
120
|
+
return different(:claude, "run #{bold("claude mcp remove #{SERVER_NAME} -s user")}")
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
command = ["claude", "mcp", "add", "--transport", "http", "-s", "user", SERVER_NAME, url]
|
|
124
|
+
output, success = @runner.capture(*command)
|
|
125
|
+
return failed(:claude, command: command, output: output) unless success
|
|
126
|
+
|
|
127
|
+
connected(:claude, "run /mcp, choose #{SERVER_NAME}, and sign in")
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
def connect_codex
|
|
131
|
+
output, success = @runner.capture("codex", "mcp", "get", SERVER_NAME, "--json")
|
|
132
|
+
if success
|
|
133
|
+
current = parse_json(output)
|
|
134
|
+
transport = current["transport"] || {}
|
|
135
|
+
matching = transport["type"] == "streamable_http" && transport["url"] == url
|
|
136
|
+
return different(:codex, "run #{bold("codex mcp remove #{SERVER_NAME}")}") unless matching
|
|
137
|
+
return already(:codex) unless current["enabled"] == false
|
|
138
|
+
elsif !output.downcase.match?(/not found|no mcp server/)
|
|
139
|
+
return failed(:codex, command: ["codex", "mcp", "get", SERVER_NAME], output: output)
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
command = ["codex", "mcp", "add", SERVER_NAME, "--url", url]
|
|
143
|
+
return failed(:codex, command: command) unless @runner.attached(*command)
|
|
144
|
+
|
|
145
|
+
connected(:codex, "run `codex mcp login #{SERVER_NAME}` if it hasn't asked you to sign in")
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
# Sets mcpServers.flare in ~/.cursor/mcp.json, keeping everything else in it.
|
|
149
|
+
def connect_cursor
|
|
150
|
+
path = File.join(@home, ".cursor", "mcp.json")
|
|
151
|
+
document = File.exist?(path) ? JSON.parse(File.read(path)) : {}
|
|
152
|
+
servers = document["mcpServers"] ||= {}
|
|
153
|
+
entry = { "url" => url }
|
|
154
|
+
|
|
155
|
+
if servers.key?(SERVER_NAME)
|
|
156
|
+
return already(:cursor) if servers[SERVER_NAME] == entry
|
|
157
|
+
return different(:cursor, "remove #{SERVER_NAME} from ~/.cursor/mcp.json")
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
servers[SERVER_NAME] = entry
|
|
161
|
+
write_atomically(path, JSON.pretty_generate(document) + "\n")
|
|
162
|
+
connected(:cursor, "open Cursor Settings → MCP and sign in to #{SERVER_NAME}", where: "~/.cursor/mcp.json")
|
|
163
|
+
rescue JSON::ParserError, SystemCallError => e
|
|
164
|
+
failed(:cursor, output: e.message)
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
# Claude Desktop keeps remote servers in your account, not a file.
|
|
168
|
+
def connect_claude_desktop
|
|
169
|
+
"in Settings, add a custom connector with the URL #{url}"
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
# Each outcome prints one line and returns what's left to do in the client.
|
|
173
|
+
def connected(client, hint, where: nil)
|
|
174
|
+
@ready = true
|
|
175
|
+
puts " #{checkmark} Connected #{CLIENTS[client]}#{" in #{where}" if where}"
|
|
176
|
+
hint
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
def already(client)
|
|
180
|
+
@ready = true
|
|
181
|
+
puts " #{checkmark} #{CLIENTS[client]} is already connected to Flare"
|
|
182
|
+
nil
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
# Nothing broke, but this client isn't pointed at Flare, so it counts as
|
|
186
|
+
# a failure for `flare connect`'s exit status.
|
|
187
|
+
def different(client, how)
|
|
188
|
+
@failed = true
|
|
189
|
+
puts " #{warn_mark} #{CLIENTS[client]} already has a different #{SERVER_NAME} server, so it was left alone."
|
|
190
|
+
puts " To replace it, #{how}, then run #{bold("flare connect")}."
|
|
191
|
+
nil
|
|
192
|
+
end
|
|
193
|
+
|
|
194
|
+
def failed(client, command: nil, output: nil)
|
|
195
|
+
@failed = true
|
|
196
|
+
reason = output.to_s.lines.map(&:strip).reject(&:empty?).first
|
|
197
|
+
puts " #{xmark} Couldn't connect #{CLIENTS[client]}#{": #{reason}" if reason}"
|
|
198
|
+
puts " Run it yourself: #{command.join(" ")}" if command
|
|
199
|
+
nil
|
|
200
|
+
end
|
|
201
|
+
|
|
202
|
+
def claude_config
|
|
203
|
+
directory = @env.fetch("CLAUDE_CONFIG_DIR", "").empty? ? @home : @env["CLAUDE_CONFIG_DIR"]
|
|
204
|
+
path = File.join(directory, ".claude.json")
|
|
205
|
+
File.exist?(path) ? parse_json(File.read(path)) : {}
|
|
206
|
+
end
|
|
207
|
+
|
|
208
|
+
def parse_json(text)
|
|
209
|
+
value = JSON.parse(text)
|
|
210
|
+
value.is_a?(Hash) ? value : {}
|
|
211
|
+
rescue JSON::ParserError
|
|
212
|
+
{}
|
|
213
|
+
end
|
|
214
|
+
|
|
215
|
+
def claude_desktop_directory
|
|
216
|
+
case @platform
|
|
217
|
+
when /darwin/ then File.join(@home, "Library", "Application Support", "Claude")
|
|
218
|
+
when /mingw|mswin/ then File.join(@env.fetch("APPDATA", File.join(@home, "AppData", "Roaming")), "Claude")
|
|
219
|
+
else File.join(@env.fetch("XDG_CONFIG_HOME", File.join(@home, ".config")), "Claude")
|
|
220
|
+
end
|
|
221
|
+
end
|
|
222
|
+
|
|
223
|
+
def executable?(name)
|
|
224
|
+
@env.fetch("PATH", "").split(File::PATH_SEPARATOR).any? do |directory|
|
|
225
|
+
path = File.join(directory, name)
|
|
226
|
+
File.file?(path) && File.executable?(path)
|
|
227
|
+
end
|
|
228
|
+
end
|
|
229
|
+
|
|
230
|
+
# Writes to a temporary file and renames it, so a crash never leaves the
|
|
231
|
+
# client with half a config. The temporary file is created with the
|
|
232
|
+
# original's permissions, so a private config is never readable by others.
|
|
233
|
+
def write_atomically(path, contents)
|
|
234
|
+
FileUtils.mkdir_p(File.dirname(path))
|
|
235
|
+
mode = File.exist?(path) ? File.stat(path).mode & 0o777 : 0o644
|
|
236
|
+
temporary = "#{path}.flare-#{SecureRandom.hex(8)}"
|
|
237
|
+
created = false
|
|
238
|
+
File.open(temporary, File::WRONLY | File::CREAT | File::EXCL, mode) do |file|
|
|
239
|
+
created = true
|
|
240
|
+
file.write(contents)
|
|
241
|
+
end
|
|
242
|
+
File.chmod(mode, temporary)
|
|
243
|
+
File.rename(temporary, path)
|
|
244
|
+
created = false
|
|
245
|
+
ensure
|
|
246
|
+
File.delete(temporary) if created && File.exist?(temporary)
|
|
247
|
+
end
|
|
248
|
+
end
|
|
249
|
+
end
|
|
@@ -11,13 +11,14 @@ require "fileutils"
|
|
|
11
11
|
require "timeout"
|
|
12
12
|
require_relative "output"
|
|
13
13
|
require_relative "project"
|
|
14
|
+
require_relative "ai_clients_setup"
|
|
14
15
|
|
|
15
16
|
module Flare
|
|
16
17
|
class SetupCommand
|
|
17
18
|
include CLI::Output
|
|
18
19
|
include CLI::Project
|
|
19
20
|
|
|
20
|
-
DEFAULT_HOST =
|
|
21
|
+
DEFAULT_HOST = AIClientsSetup::DEFAULT_HOST
|
|
21
22
|
TIMEOUT_SECONDS = 300 # 5 minutes
|
|
22
23
|
CLIENT_READ_TIMEOUT = 1
|
|
23
24
|
|
|
@@ -49,6 +50,9 @@ module Flare
|
|
|
49
50
|
# request.path.start_with?("/health")
|
|
50
51
|
# }
|
|
51
52
|
|
|
53
|
+
# Exceptions (and subclasses) that don't count as errors in metrics.
|
|
54
|
+
# config.ignore_errors << "MyApp::RetryLaterError"
|
|
55
|
+
|
|
52
56
|
# ── Metrics (remote monitoring) ────────────────────────────────────
|
|
53
57
|
# Metrics aggregate span data into counts, durations, and error rates.
|
|
54
58
|
# Enabled by default in development and production (disabled in test).
|
|
@@ -82,14 +86,16 @@ module Flare
|
|
|
82
86
|
# end
|
|
83
87
|
RUBY
|
|
84
88
|
|
|
85
|
-
def initialize(force: false)
|
|
89
|
+
def initialize(force: false, ai_clients: AIClientsSetup.new)
|
|
86
90
|
@force = force
|
|
91
|
+
@ai_clients = ai_clients
|
|
87
92
|
end
|
|
88
93
|
|
|
89
94
|
def run
|
|
90
95
|
authenticate
|
|
91
96
|
create_initializer
|
|
92
97
|
add_gitignore_entries
|
|
98
|
+
@ai_clients.run
|
|
93
99
|
|
|
94
100
|
puts
|
|
95
101
|
puts "#{green("Setup complete!")}"
|
data/lib/flare/cli.rb
CHANGED
|
@@ -6,6 +6,7 @@ module Flare
|
|
|
6
6
|
module CLI
|
|
7
7
|
COMMANDS = {
|
|
8
8
|
"setup" => "Authenticate and configure Flare for this project",
|
|
9
|
+
"connect" => "Connect your AI assistants to Flare",
|
|
9
10
|
"doctor" => "Check your Flare setup for issues",
|
|
10
11
|
"status" => "Show current Flare configuration",
|
|
11
12
|
"requests" => "List recent requests from local development spans",
|
|
@@ -23,6 +24,9 @@ module Flare
|
|
|
23
24
|
require_relative "cli/setup_command"
|
|
24
25
|
force = argv.include?("--force")
|
|
25
26
|
SetupCommand.new(force: force).run
|
|
27
|
+
when "connect"
|
|
28
|
+
require_relative "cli/ai_clients_setup"
|
|
29
|
+
exit 1 unless AIClientsSetup.new.run(ask: false)
|
|
26
30
|
when "doctor"
|
|
27
31
|
require_relative "cli/doctor_command"
|
|
28
32
|
DoctorCommand.new.run
|
data/lib/flare/configuration.rb
CHANGED
|
@@ -9,6 +9,7 @@ module Flare
|
|
|
9
9
|
attr_accessor :retention_hours
|
|
10
10
|
attr_accessor :max_spans
|
|
11
11
|
attr_accessor :ignore_request
|
|
12
|
+
attr_accessor :ignore_errors
|
|
12
13
|
attr_writer :database_path
|
|
13
14
|
|
|
14
15
|
# Spans: detailed trace data stored in SQLite (default: development only)
|
|
@@ -35,6 +36,12 @@ module Flare
|
|
|
35
36
|
|
|
36
37
|
attr_accessor :subscribe_patterns
|
|
37
38
|
|
|
39
|
+
# Exceptions that jobs raise to wait or retry rather than to fail. A span
|
|
40
|
+
# that ends with one of these (or a subclass) counts as a success.
|
|
41
|
+
DEFAULT_IGNORE_ERRORS = %w[
|
|
42
|
+
GoodJob::ActiveJobExtensions::Concurrency::ConcurrencyExceededError
|
|
43
|
+
].freeze
|
|
44
|
+
|
|
38
45
|
# HTTP metrics path tracking configuration.
|
|
39
46
|
# Controls which outgoing HTTP paths are tracked with detail vs collapsed to "*".
|
|
40
47
|
attr_reader :http_metrics_config
|
|
@@ -49,6 +56,7 @@ module Flare
|
|
|
49
56
|
@max_spans = 10_000
|
|
50
57
|
@database_path = nil
|
|
51
58
|
@ignore_request = ->(request) { false }
|
|
59
|
+
@ignore_errors = DEFAULT_IGNORE_ERRORS.dup
|
|
52
60
|
@subscribe_patterns = DEFAULT_SUBSCRIBE_PATTERNS.dup
|
|
53
61
|
@debug = ENV["FLARE_DEBUG"] == "1"
|
|
54
62
|
@revision = ENV["FLARE_REVISION"]
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require "active_support/inflector/methods"
|
|
3
4
|
require_relative "metric_key"
|
|
4
5
|
require_relative "http_metrics_config"
|
|
5
6
|
require_relative "sql_mask"
|
|
@@ -30,9 +31,12 @@ module Flare
|
|
|
30
31
|
"solid_cache" => "solid_cache"
|
|
31
32
|
}.freeze
|
|
32
33
|
|
|
33
|
-
|
|
34
|
+
ACTIVE_JOB_ERROR_STATUS = /\AUnexpected ActiveJob Error (\S+)\z/
|
|
35
|
+
|
|
36
|
+
def initialize(storage:, http_metrics_config: nil, ignore_errors: nil)
|
|
34
37
|
@storage = storage
|
|
35
38
|
@http_metrics_config = http_metrics_config || HttpMetricsConfig::DEFAULT
|
|
39
|
+
@ignore_errors = ignore_errors || []
|
|
36
40
|
@pid = $$
|
|
37
41
|
end
|
|
38
42
|
|
|
@@ -301,7 +305,26 @@ module Flare
|
|
|
301
305
|
end
|
|
302
306
|
|
|
303
307
|
def span_error?(span)
|
|
304
|
-
span.status&.code
|
|
308
|
+
return false if span.status&.code != OpenTelemetry::Trace::Status::ERROR
|
|
309
|
+
return true if @ignore_errors.empty?
|
|
310
|
+
|
|
311
|
+
type = exception_type(span)
|
|
312
|
+
type.nil? || !ignored_exception_type?(type)
|
|
313
|
+
end
|
|
314
|
+
|
|
315
|
+
# A job's retried exception is recorded on its enqueue_retry child span,
|
|
316
|
+
# so the process span only names it in the status description.
|
|
317
|
+
def exception_type(span)
|
|
318
|
+
event = span.events&.reverse_each&.find { |e| e.name == "exception" }
|
|
319
|
+
event&.attributes&.[]("exception.type") ||
|
|
320
|
+
span.status.description.to_s[ACTIVE_JOB_ERROR_STATUS, 1]
|
|
321
|
+
end
|
|
322
|
+
|
|
323
|
+
# Subclasses of an ignored class match when the class is loaded.
|
|
324
|
+
def ignored_exception_type?(type)
|
|
325
|
+
klass = ActiveSupport::Inflector.safe_constantize(type)
|
|
326
|
+
names = klass.is_a?(Class) ? klass.ancestors.map(&:name) : [type]
|
|
327
|
+
names.any? { |name| @ignore_errors.include?(name) }
|
|
305
328
|
end
|
|
306
329
|
|
|
307
330
|
def extract_job_system(span)
|
data/lib/flare/storage/sqlite.rb
CHANGED
|
@@ -276,8 +276,8 @@ module Flare
|
|
|
276
276
|
|
|
277
277
|
# List spans that have exception events
|
|
278
278
|
def list_exception_spans(name: nil, sort: nil, limit: 50, offset: 0)
|
|
279
|
-
conditions = []
|
|
280
|
-
values = []
|
|
279
|
+
conditions = ["e.name = ?"]
|
|
280
|
+
values = ["exception"]
|
|
281
281
|
|
|
282
282
|
if name
|
|
283
283
|
conditions << "e.name LIKE ?"
|
|
@@ -315,8 +315,8 @@ module Flare
|
|
|
315
315
|
end
|
|
316
316
|
|
|
317
317
|
def count_exception_spans(name: nil)
|
|
318
|
-
conditions = []
|
|
319
|
-
values = []
|
|
318
|
+
conditions = ["e.name = ?"]
|
|
319
|
+
values = ["exception"]
|
|
320
320
|
|
|
321
321
|
if name
|
|
322
322
|
conditions << "e.name LIKE ?"
|
data/lib/flare/version.rb
CHANGED
data/lib/flare.rb
CHANGED
|
@@ -339,7 +339,8 @@ module Flare
|
|
|
339
339
|
@metric_storage ||= MetricStorage.new
|
|
340
340
|
metric_processor = MetricSpanProcessor.new(
|
|
341
341
|
storage: @metric_storage,
|
|
342
|
-
http_metrics_config: configuration.http_metrics_config
|
|
342
|
+
http_metrics_config: configuration.http_metrics_config,
|
|
343
|
+
ignore_errors: configuration.ignore_errors
|
|
343
344
|
)
|
|
344
345
|
OpenTelemetry.tracer_provider.add_span_processor(metric_processor)
|
|
345
346
|
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: flare
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.5.
|
|
4
|
+
version: 0.5.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- John Nunemaker
|
|
@@ -192,6 +192,7 @@ files:
|
|
|
192
192
|
- lib/flare.rb
|
|
193
193
|
- lib/flare/backoff_policy.rb
|
|
194
194
|
- lib/flare/cli.rb
|
|
195
|
+
- lib/flare/cli/ai_clients_setup.rb
|
|
195
196
|
- lib/flare/cli/doctor_command.rb
|
|
196
197
|
- lib/flare/cli/local_spans.rb
|
|
197
198
|
- lib/flare/cli/nplus1_command.rb
|