railwatch 1.5.0 → 1.6.1
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/AGENTS.md +9 -9
- data/CHANGELOG.md +107 -0
- data/README.md +8 -8
- data/app/controllers/railwatch/beacon_controller.rb +58 -7
- data/docs/ai-and-mcp.md +14 -14
- data/docs/configuration.md +79 -15
- data/docs/faq.md +3 -3
- data/docs/getting-started.md +30 -20
- data/docs/records.md +17 -6
- data/docs/replacing-nightwatch.md +1 -1
- data/docs/replacing-sentry.md +6 -5
- data/docs/security.md +6 -6
- data/docs/self-hosting.md +3 -3
- data/docs/testing.md +1 -1
- data/docs/troubleshooting.md +1 -1
- data/lib/generators/railwatch/agents/agents_generator.rb +5 -4
- data/lib/generators/railwatch/agents/templates/agents_block.md.tt +1 -1
- data/lib/generators/railwatch/install/install_generator.rb +5 -5
- data/lib/generators/railwatch/install/templates/initializer.rb.tt +1 -1
- data/lib/generators/railwatch/install/templates/post-deploy +5 -2
- data/lib/generators/railwatch/install/templates/railwatch.ts +55 -10
- data/lib/puma/plugin/railwatch.rb +7 -0
- data/lib/railwatch/authentication.rb +1 -1
- data/lib/railwatch/backtrace.rb +35 -0
- data/lib/railwatch/configuration.rb +69 -7
- data/lib/railwatch/engine.rb +4 -1
- data/lib/railwatch/middleware/request.rb +31 -0
- data/lib/railwatch/redactor.rb +6 -2
- data/lib/railwatch/sql_normalizer.rb +21 -19
- data/lib/railwatch/subscribers/exceptions.rb +19 -1
- data/lib/railwatch/version.rb +1 -1
- data/lib/railwatch.rb +36 -0
- data/lib/tasks/railwatch_tasks.rake +6 -5
- data/llms.txt +4 -4
- metadata +4 -3
data/lib/railwatch/backtrace.rb
CHANGED
|
@@ -110,6 +110,41 @@ module Railwatch
|
|
|
110
110
|
|
|
111
111
|
MAX_JS_FRAMES = 50
|
|
112
112
|
|
|
113
|
+
# A bundler's content hash in a built file's name: Vite and Rollup's
|
|
114
|
+
# "dist-DedfDSJv.js" (base64url, so it can hold a "-" of its own:
|
|
115
|
+
# "dist-CMHaG-3i.js"), esbuild's "app-5XDGVJ2T.js", webpack's
|
|
116
|
+
# "main.3f2a1b9c.js". The name is greedy, so in "yard-canvas-BwMeIV6a.js"
|
|
117
|
+
# only the last segment that can be a hash is one.
|
|
118
|
+
JS_CONTENT_HASH = /\A(?<name>.+)[-.](?<hash>[A-Za-z0-9_-]{8,64})(?<ext>\.[mc]?js)\z/
|
|
119
|
+
|
|
120
|
+
# Where a browser error is filed for grouping. A content hash changes
|
|
121
|
+
# every deploy the bundle changes, so it is taken out of the file name,
|
|
122
|
+
# and so is the line: in a minified bundle the line is wherever the
|
|
123
|
+
# minifier wrapped (Vite writes the whole app on a line or two) and
|
|
124
|
+
# shifts with any change before it, which is why Sentry leaves the line
|
|
125
|
+
# out of a minified frame it has no source map for. The stored frames
|
|
126
|
+
# keep the real file and line; this is for the fingerprint alone.
|
|
127
|
+
def js_fingerprint_location(frame)
|
|
128
|
+
file = frame[:file]
|
|
129
|
+
match = file && JS_CONTENT_HASH.match(file)
|
|
130
|
+
return [ file, frame[:line] ] unless match && content_hash?(match[:hash])
|
|
131
|
+
|
|
132
|
+
[ "#{match[:name]}#{match[:ext]}", nil ]
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
# A word is not a hash: one has a digit, or mixes cases in a way no
|
|
136
|
+
# camelCase or PascalCase name does ("DedfDSJv"). So the "timeline" in
|
|
137
|
+
# "order-timeline.js" and the "PaymentForm" in "checkout-PaymentForm.js"
|
|
138
|
+
# stay part of the name. A hash that happens to read like words (about
|
|
139
|
+
# 1 in 100 of eight letters with no digit) is kept too, which costs that
|
|
140
|
+
# deploy a split issue, never a wrong merge.
|
|
141
|
+
CAMEL_WORDS = /\A[A-Za-z][a-z]+(?:[A-Z][a-z]{2,})+\z/
|
|
142
|
+
|
|
143
|
+
def content_hash?(segment)
|
|
144
|
+
segment.match?(/\d/) ||
|
|
145
|
+
(segment.match?(/[a-z]/) && segment.match?(/[A-Z]/) && !segment.match?(CAMEL_WORDS))
|
|
146
|
+
end
|
|
147
|
+
|
|
113
148
|
# A browser stack, exactly as the engine wrote it, in the same frame
|
|
114
149
|
# shape as a Ruby backtrace. `origin` is the app's own scheme and host: a
|
|
115
150
|
# script served from it is the app's own, so its file is stored relative
|
|
@@ -60,12 +60,16 @@ module Railwatch
|
|
|
60
60
|
Rack::QueryParser::ParameterTypeError
|
|
61
61
|
].freeze
|
|
62
62
|
|
|
63
|
-
# What railwatch-
|
|
63
|
+
# What railwatch-sidecar's dashboard proxy inherits from unless the host
|
|
64
64
|
# names its own.
|
|
65
65
|
DEFAULT_BASE_CONTROLLER = "ActionController::Base"
|
|
66
66
|
|
|
67
|
+
# The roles railwatch-sidecar can hand a dashboard visitor.
|
|
68
|
+
DASHBOARD_ROLES = %w[admin member].freeze
|
|
69
|
+
|
|
67
70
|
attr_accessor :enabled, :token, :ingest_url, :allow_http, :server, :environment,
|
|
68
71
|
:http_basic_auth_enabled, :http_basic_auth_user, :http_basic_auth_password, :base_controller_class,
|
|
72
|
+
:capture_browser_query_strings, :capture_browser_console_arguments,
|
|
69
73
|
:sample, :log_level, :capture_request_payload,
|
|
70
74
|
:capture_exception_source, :capture_exception_locals, :redact_headers, :redact_params,
|
|
71
75
|
:buffer_size, :buffer_bytes, :execution_buffer_bytes, :batch_bytes,
|
|
@@ -88,13 +92,13 @@ module Railwatch
|
|
|
88
92
|
:capture_console, :interactive_runner_paths, :ignored_request_paths,
|
|
89
93
|
:capture_llm_content, :timing_headers, :browser_client
|
|
90
94
|
|
|
91
|
-
attr_reader :deploy, :deploy_source, :detect_deploy, :user_resolver, :beacon_user_resolver,
|
|
95
|
+
attr_reader :dashboard_default_role, :deploy, :deploy_source, :detect_deploy, :user_resolver, :beacon_user_resolver,
|
|
92
96
|
:fingerprint_resolver, :redactors, :rejectors, :before_ingest, :backpressure_high_water
|
|
93
97
|
|
|
94
98
|
def initialize
|
|
95
99
|
@enabled = env_bool("RAILWATCH_ENABLED", true)
|
|
96
100
|
@token = ENV["RAILWATCH_TOKEN"]
|
|
97
|
-
# The gate in front of the dashboard railwatch-
|
|
101
|
+
# The gate in front of the dashboard railwatch-sidecar serves at
|
|
98
102
|
# /railwatch, the way Mission Control Jobs does it: HTTP Basic
|
|
99
103
|
# authentication is on and CLOSED by default. With no user and password
|
|
100
104
|
# configured every dashboard request is 401, so an install that forgot
|
|
@@ -103,16 +107,22 @@ module Railwatch
|
|
|
103
107
|
# by `bin/rails railwatch:authentication:configure`), from these env
|
|
104
108
|
# vars, or by assignment here. A host with its own admin auth turns
|
|
105
109
|
# Basic off and names a base controller. Nothing here reads them unless
|
|
106
|
-
# railwatch-
|
|
110
|
+
# railwatch-sidecar is installed.
|
|
107
111
|
@http_basic_auth_enabled = env_bool("RAILWATCH_HTTP_BASIC_AUTH_ENABLED", true)
|
|
108
112
|
@http_basic_auth_user = ENV["RAILWATCH_HTTP_BASIC_AUTH_USER"]
|
|
109
113
|
@http_basic_auth_password = ENV["RAILWATCH_HTTP_BASIC_AUTH_PASSWORD"]
|
|
110
|
-
# railwatch-
|
|
114
|
+
# railwatch-sidecar's dashboard proxy inherits from this class, so a
|
|
111
115
|
# host's own before_actions (require an admin, redirect to sign-in) run
|
|
112
116
|
# in front of every page. The default authenticates nothing itself
|
|
113
117
|
# beyond HTTP Basic above.
|
|
114
118
|
@base_controller_class = ENV.fetch("RAILWATCH_BASE_CONTROLLER_CLASS", DEFAULT_BASE_CONTROLLER)
|
|
115
|
-
|
|
119
|
+
# The role railwatch-sidecar gives a dashboard visitor the app did not
|
|
120
|
+
# name (no Railwatch::Sidecar.config.user): the HTTP Basic user, or the
|
|
121
|
+
# one operator. A member, so a shared Basic password or a gate that
|
|
122
|
+
# turns out to be open does not hand out token, member and integration
|
|
123
|
+
# management. "admin" restores the old behaviour.
|
|
124
|
+
self.dashboard_default_role = ENV.fetch("RAILWATCH_DASHBOARD_DEFAULT_ROLE", "member")
|
|
125
|
+
@ingest_url = ENV.fetch("RAILWATCH_INGEST_URL", "https://app.railwatch.dev")
|
|
116
126
|
@allow_http = env_bool("RAILWATCH_ALLOW_HTTP", false)
|
|
117
127
|
@project_root = defined?(Rails) ? Rails.root : Dir.pwd
|
|
118
128
|
@detect_deploy = env_bool("RAILWATCH_DETECT_DEPLOY", true)
|
|
@@ -190,6 +200,14 @@ module Railwatch
|
|
|
190
200
|
# as Sentry's allowed domains: "https://app.example.com", or a host on
|
|
191
201
|
# its own. Empty means same-origin only.
|
|
192
202
|
@beacon_allowed_origins = ENV["RAILWATCH_BEACON_ALLOWED_ORIGINS"]&.split(",")&.map(&:strip)&.reject(&:empty?) || []
|
|
203
|
+
# A page's query string is where reset, magic-link and OAuth secrets
|
|
204
|
+
# ride, so the beacon keeps only the path of the page, the visit and
|
|
205
|
+
# each navigation unless an app opts in. The fragment is always dropped.
|
|
206
|
+
@capture_browser_query_strings = env_bool("RAILWATCH_CAPTURE_BROWSER_QUERY_STRINGS", false)
|
|
207
|
+
# What the page passed to console.error/console.warn is whatever it had
|
|
208
|
+
# in hand, user data included, so a console breadcrumb keeps only its
|
|
209
|
+
# level unless an app opts in.
|
|
210
|
+
@capture_browser_console_arguments = env_bool("RAILWATCH_CAPTURE_BROWSER_CONSOLE_ARGUMENTS", false)
|
|
193
211
|
@debug = env_bool("RAILWATCH_DEBUG", false)
|
|
194
212
|
# Tail-based sampling: a head-sampled-out execution is still kept when
|
|
195
213
|
# it ran at least this long, raised, or Railwatch.keep! was called. nil = off.
|
|
@@ -313,7 +331,7 @@ module Railwatch
|
|
|
313
331
|
# Whether the request carries the configured HTTP Basic credentials.
|
|
314
332
|
# False when Basic is on and nothing is configured (closed), true when
|
|
315
333
|
# Basic is off (the host's base controller is the gate then).
|
|
316
|
-
# railwatch-
|
|
334
|
+
# railwatch-sidecar's dashboard proxy calls it.
|
|
317
335
|
def http_basic_auth_ok?(request)
|
|
318
336
|
return true unless http_basic_auth_enabled
|
|
319
337
|
return true if http_basic_auth_waived?
|
|
@@ -325,6 +343,24 @@ module Railwatch
|
|
|
325
343
|
end == true
|
|
326
344
|
end
|
|
327
345
|
|
|
346
|
+
# Whether anything stands in front of railwatch-sidecar's dashboard:
|
|
347
|
+
# HTTP Basic (which refuses everyone until credentials exist), or a base
|
|
348
|
+
# controller of the host's own whose before_actions run first. False is
|
|
349
|
+
# Basic turned off with the base controller left at ActionController::Base,
|
|
350
|
+
# which serves the dashboard to anyone. railwatch-sidecar asks this
|
|
351
|
+
# (when the gem has it) and refuses to serve outside development.
|
|
352
|
+
def dashboard_gate_configured?
|
|
353
|
+
return true if http_basic_auth_enabled
|
|
354
|
+
|
|
355
|
+
base = base_controller_class.to_s.strip.delete_prefix("::")
|
|
356
|
+
base != "" && base != DEFAULT_BASE_CONTROLLER
|
|
357
|
+
end
|
|
358
|
+
|
|
359
|
+
def dashboard_default_role=(value)
|
|
360
|
+
role = value.to_s.strip.downcase
|
|
361
|
+
@dashboard_default_role = DASHBOARD_ROLES.include?(role) ? role : "member"
|
|
362
|
+
end
|
|
363
|
+
|
|
328
364
|
def ingest_url_allowed?
|
|
329
365
|
url_allowed?(ingest_url)
|
|
330
366
|
end
|
|
@@ -420,6 +456,32 @@ module Railwatch
|
|
|
420
456
|
end
|
|
421
457
|
end
|
|
422
458
|
|
|
459
|
+
# Settings of 0.x embedded mode, which 1.0 removed: the dashboard and its
|
|
460
|
+
# storage are railwatch-sidecar (or a railwatch-rs server) now. Assigning
|
|
461
|
+
# one raises with the migration instead of a bare NoMethodError.
|
|
462
|
+
EMBEDDED_MODE_SETTINGS = %i[
|
|
463
|
+
transport issue_prefix repository_url retention_days dashboard_user dashboard_open
|
|
464
|
+
writer_socket migration_busy_timeout
|
|
465
|
+
].freeze
|
|
466
|
+
|
|
467
|
+
EMBEDDED_MODE_MIGRATION = "Railwatch 1.0 removed embedded mode: this gem is the agent only, and the " \
|
|
468
|
+
"dashboard runs in railwatch-sidecar (gem \"railwatch-sidecar\" plus `plugin :railwatch_sidecar` in " \
|
|
469
|
+
"config/puma.rb) or a railwatch-rs server. See " \
|
|
470
|
+
"https://github.com/Rebulk/railwatch/blob/main/docs/getting-started.md#coming-from-0x-embedded-mode"
|
|
471
|
+
|
|
472
|
+
class RemovedSetting < NoMethodError; end
|
|
473
|
+
|
|
474
|
+
EMBEDDED_MODE_SETTINGS.each do |name|
|
|
475
|
+
define_method(:"#{name}=") do |_value|
|
|
476
|
+
raise RemovedSetting.new("[railwatch] `#{name}` was removed. #{EMBEDDED_MODE_MIGRATION}", :"#{name}=")
|
|
477
|
+
end
|
|
478
|
+
end
|
|
479
|
+
|
|
480
|
+
# The environment variable that turned embedded mode on, if it is still set.
|
|
481
|
+
def embedded_mode_env
|
|
482
|
+
"RAILWATCH_TRANSPORT" if ENV["RAILWATCH_TRANSPORT"].to_s.strip != ""
|
|
483
|
+
end
|
|
484
|
+
|
|
423
485
|
private
|
|
424
486
|
|
|
425
487
|
def detect_release
|
data/lib/railwatch/engine.rb
CHANGED
|
@@ -21,7 +21,7 @@ module Railwatch
|
|
|
21
21
|
Railwatch::Console.silence!
|
|
22
22
|
end
|
|
23
23
|
|
|
24
|
-
# The dashboard gate railwatch-
|
|
24
|
+
# The dashboard gate railwatch-sidecar's proxy applies. Same source
|
|
25
25
|
# Mission Control Jobs reads: railwatch.http_basic_auth_user and
|
|
26
26
|
# _password in Rails credentials, which `bin/rails
|
|
27
27
|
# railwatch:authentication:configure` writes. An initializer or env var
|
|
@@ -39,6 +39,9 @@ module Railwatch
|
|
|
39
39
|
next unless Railwatch.enabled?
|
|
40
40
|
|
|
41
41
|
Rails.logger.warn("[railwatch] #{Railwatch::JsonCompat.advice}") if Railwatch::JsonCompat.broken?
|
|
42
|
+
if (name = Railwatch.config.embedded_mode_env)
|
|
43
|
+
Rails.logger.warn("[railwatch] #{name} is ignored. #{Railwatch::Configuration::EMBEDDED_MODE_MIGRATION}")
|
|
44
|
+
end
|
|
42
45
|
end
|
|
43
46
|
end
|
|
44
47
|
|
|
@@ -145,6 +145,8 @@ module Railwatch
|
|
|
145
145
|
end
|
|
146
146
|
|
|
147
147
|
def finish(env, exe, status, headers)
|
|
148
|
+
return Railwatch.discard_execution if static_file?(env, status)
|
|
149
|
+
|
|
148
150
|
exe.finish_stages
|
|
149
151
|
# Resolved here, once, for both the request record and the session
|
|
150
152
|
# key below (the start_processing subscriber ran before the app's
|
|
@@ -165,6 +167,35 @@ module Railwatch
|
|
|
165
167
|
nil
|
|
166
168
|
end
|
|
167
169
|
|
|
170
|
+
# A file ActionDispatch::Static served from public/: a bundle, a
|
|
171
|
+
# stylesheet, a favicon. This middleware sits in front of Static, so
|
|
172
|
+
# without this every one of them is a "GET unmatched" request record
|
|
173
|
+
# -- about 23 per page load, a tenth of rebulk-system's requests --
|
|
174
|
+
# and a row in the session's journey. Only a success or a 304 is
|
|
175
|
+
# skipped: an unmatched 404 is a probe the security tools read.
|
|
176
|
+
#
|
|
177
|
+
# Static's 304 is a bare [304, {}, []], so the response cannot say a
|
|
178
|
+
# file answered it. The path can: it names a file under public/,
|
|
179
|
+
# looked up the way Static looks (unescaped, cleaned, then with
|
|
180
|
+
# ".html" or "/index.html", or only its precompressed ".br" or ".gz",
|
|
181
|
+
# which Static serves in its place). Every check before that one is an
|
|
182
|
+
# env or integer read, so a routed request never touches the
|
|
183
|
+
# filesystem.
|
|
184
|
+
def static_file?(env, status)
|
|
185
|
+
return false if env["railwatch.route"] || env["action_dispatch.route"]
|
|
186
|
+
return false unless status && (status.to_i.between?(200, 299) || status.to_i == 304)
|
|
187
|
+
return false unless env["REQUEST_METHOD"] == "GET" || env["REQUEST_METHOD"] == "HEAD"
|
|
188
|
+
|
|
189
|
+
path = Rack::Utils.unescape_path(env["PATH_INFO"].to_s.chomp("/"))
|
|
190
|
+
return false unless Rack::Utils.valid_path?(path)
|
|
191
|
+
|
|
192
|
+
file = File.join(Rails.public_path.to_s, Rack::Utils.clean_path_info(path))
|
|
193
|
+
[ file, "#{file}.html", File.join(file, "index.html"), "#{file}.br", "#{file}.gz" ]
|
|
194
|
+
.any? { |candidate| File.file?(candidate) }
|
|
195
|
+
rescue StandardError
|
|
196
|
+
false
|
|
197
|
+
end
|
|
198
|
+
|
|
168
199
|
def parent_fields(env, exe, status, headers)
|
|
169
200
|
req = ActionDispatch::Request.new(env)
|
|
170
201
|
route = env["railwatch.route"] || {}
|
data/lib/railwatch/redactor.rb
CHANGED
|
@@ -9,7 +9,9 @@ module Railwatch
|
|
|
9
9
|
# Credentials are often carried in vendor-specific headers that an app
|
|
10
10
|
# cannot enumerate ahead of time (X-Api-Key, Stripe-Signature,
|
|
11
11
|
# X-Auth-Token, and similar). Match credential-shaped name segments in
|
|
12
|
-
# addition to the exact configurable denylist.
|
|
12
|
+
# addition to the exact configurable denylist. Identity headers an
|
|
13
|
+
# authenticating proxy adds (X-Forwarded-Email, X-Remote-User, a client
|
|
14
|
+
# certificate) name a person, so they count too.
|
|
13
15
|
SENSITIVE_HEADER_NAME = %r{
|
|
14
16
|
(?:\A|-)
|
|
15
17
|
(?:
|
|
@@ -20,7 +22,9 @@ module Railwatch
|
|
|
20
22
|
security-?token|service-?token|identity-?token|id-?token|
|
|
21
23
|
csrf-?token|xsrf-?token|credential|
|
|
22
24
|
hmac(?:-?signature)?|jwt(?:-?(?:assertion|token))?|
|
|
23
|
-
webhook-?(?:hmac|secret|signature)|token|secret|signature
|
|
25
|
+
webhook-?(?:hmac|secret|signature)|token|secret|signature|
|
|
26
|
+
password|passwd|session-?id|subscription-?key|client-?cert|
|
|
27
|
+
(?:forwarded|remote)-?(?:user|email)
|
|
24
28
|
)
|
|
25
29
|
(?:-|\z)
|
|
26
30
|
}ix
|
|
@@ -141,10 +141,11 @@ module Railwatch
|
|
|
141
141
|
# default the notification does not carry: MySQL escapes (unless the
|
|
142
142
|
# session sets NO_BACKSLASH_ESCAPES), PostgreSQL does not (unless it
|
|
143
143
|
# sets standard_conforming_strings off, deprecated since 9.1), E''
|
|
144
|
-
# always does, SQLite never does. Scan with each dialect's default
|
|
145
|
-
#
|
|
146
|
-
#
|
|
147
|
-
# the
|
|
144
|
+
# always does, SQLite never does. Scan with each dialect's default.
|
|
145
|
+
# An unknown adapter is scanned both ways: where the readings agree
|
|
146
|
+
# nothing is lost, and where they disagree no single reading is
|
|
147
|
+
# safe (each exposes a value the other hides), so the rest of the
|
|
148
|
+
# statement is masked (#ambiguous_quoted_value_end).
|
|
148
149
|
#
|
|
149
150
|
# This deliberately no longer abandons the rest of the statement on
|
|
150
151
|
# seeing \'. That was safe but destroyed the shape, and on MySQL --
|
|
@@ -154,26 +155,16 @@ module Railwatch
|
|
|
154
155
|
# hashed into one query group. Values are masked either way; only
|
|
155
156
|
# the tail's shape was being thrown away.
|
|
156
157
|
backslash_escapes = mysql || unknown_adapter || explicit_escape_string
|
|
157
|
-
i
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
elsif bytes.getbyte(i) == 39
|
|
162
|
-
if bytes.getbyte(i + 1) == 39
|
|
163
|
-
i += 2
|
|
164
|
-
else
|
|
165
|
-
i += 1
|
|
166
|
-
break
|
|
167
|
-
end
|
|
168
|
-
else
|
|
169
|
-
i += 1
|
|
170
|
-
end
|
|
158
|
+
i = if unknown_adapter && !explicit_escape_string
|
|
159
|
+
ambiguous_quoted_value_end(bytes, i, 39)
|
|
160
|
+
else
|
|
161
|
+
skip_quoted_value(bytes, i, 39, backslash_escapes: backslash_escapes)
|
|
171
162
|
end
|
|
172
163
|
out << "?"
|
|
173
164
|
# When adapter metadata is unavailable, privacy wins over preserving
|
|
174
165
|
# ANSI quoted-identifier shape: this may be a MySQL-compatible string.
|
|
175
166
|
elsif mysql_ambiguous && byte == 34 # MySQL/Trilogy default: "..." is a string.
|
|
176
|
-
i = skip_quoted_value(bytes, i, 34, backslash_escapes: true)
|
|
167
|
+
i = mysql ? skip_quoted_value(bytes, i, 34, backslash_escapes: true) : ambiguous_quoted_value_end(bytes, i, 34)
|
|
177
168
|
out << "?"
|
|
178
169
|
elsif sqlite && byte == 34 # SQLite DQS is ambiguous; mask unless syntax proves identifier use.
|
|
179
170
|
close_at = quoted_identifier_end(bytes, i, 34)
|
|
@@ -218,6 +209,17 @@ module Railwatch
|
|
|
218
209
|
out.force_encoding(Encoding::UTF_8)
|
|
219
210
|
end
|
|
220
211
|
|
|
212
|
+
# Where a quoted value ends when the adapter is unknown, so whether a
|
|
213
|
+
# backslash escapes the quote after it is too. Where the two readings
|
|
214
|
+
# agree, that is the end. Where they disagree ('C:\' AND ssn = '1' ...)
|
|
215
|
+
# they pair every later quote differently, and whichever is wrong puts
|
|
216
|
+
# the next value outside quotes -- so the rest of the statement is masked.
|
|
217
|
+
def ambiguous_quoted_value_end(bytes, index, quote)
|
|
218
|
+
escaped = skip_quoted_value(bytes, index, quote, backslash_escapes: true)
|
|
219
|
+
standard = skip_quoted_value(bytes, index, quote, backslash_escapes: false)
|
|
220
|
+
escaped == standard ? escaped : bytes.bytesize
|
|
221
|
+
end
|
|
222
|
+
|
|
221
223
|
def skip_quoted_value(bytes, index, quote, backslash_escapes:)
|
|
222
224
|
length = bytes.bytesize
|
|
223
225
|
i = index + 1
|
|
@@ -248,15 +248,33 @@ module Railwatch
|
|
|
248
248
|
error.class.ancestors.any? { |ancestor| (name = ancestor.name) && ignored.include?(name) }
|
|
249
249
|
end
|
|
250
250
|
|
|
251
|
+
# An IPv6 address, full ("2607:fb90:...:74c7") or compressed around
|
|
252
|
+
# "::" ("2600:3c15::2000:22ff:febb:8bb9", "2a03:2880:f802:c::"). It
|
|
253
|
+
# has to carry a digit and stand alone, and it is lower case, as
|
|
254
|
+
# RFC 5952 and IPAddr write it: so a constant path like Foo::Bar or
|
|
255
|
+
# Abc1::Def stays, and a clock time like 12:30:45 has neither eight
|
|
256
|
+
# groups nor a "::".
|
|
257
|
+
IPV6 = /
|
|
258
|
+
(?<![\w:])
|
|
259
|
+
(?=[0-9a-f:]*\d)
|
|
260
|
+
(?:
|
|
261
|
+
[0-9a-f]{1,4}(?::[0-9a-f]{1,4}){7}
|
|
262
|
+
| (?:[0-9a-f]{1,4}(?::[0-9a-f]{1,4}){0,6})?::(?:[0-9a-f]{1,4}(?::[0-9a-f]{1,4}){0,6})?
|
|
263
|
+
)
|
|
264
|
+
(?![\w:])
|
|
265
|
+
/x
|
|
266
|
+
|
|
251
267
|
# Variable data that would otherwise split one issue into thousands of
|
|
252
268
|
# them. Applied in this order: a URL before the numbers inside it, a
|
|
253
|
-
# quoted string before the id it quotes, hex before
|
|
269
|
+
# quoted string before the id it quotes, an IPv6 address and hex before
|
|
270
|
+
# plain digits.
|
|
254
271
|
MESSAGE_NOISE = [
|
|
255
272
|
%r{\bhttps?://\S+}, # URLs
|
|
256
273
|
/\b[^\s@]+@[^\s@]+\.[^\s@]+\b/, # email addresses
|
|
257
274
|
/\h{8}-\h{4}-\h{4}-\h{4}-\h{12}/, # UUIDs
|
|
258
275
|
/\d{4}-\d{2}-\d{2}[T ]\d{2}:\d{2}:\d{2}\S*/, # ISO timestamps
|
|
259
276
|
/\b\d{1,3}(?:\.\d{1,3}){3}\b/, # IPv4 addresses
|
|
277
|
+
IPV6, # IPv6, before hex and digits
|
|
260
278
|
/(?<!\w)'[^']*'|"[^"]*"/, # quoted strings ("won't" is not one)
|
|
261
279
|
/\b(?:0x)?\h{6,}\b/, # hex: digests, object addresses
|
|
262
280
|
/\b\d+\b/ # plain integers
|
data/lib/railwatch/version.rb
CHANGED
data/lib/railwatch.rb
CHANGED
|
@@ -199,6 +199,18 @@ module Railwatch
|
|
|
199
199
|
Current.execution = exe&.parent_execution
|
|
200
200
|
end
|
|
201
201
|
|
|
202
|
+
# Ends the execution and ships nothing of it, for one that turned out
|
|
203
|
+
# not to be worth a record at all (the request middleware's static
|
|
204
|
+
# files). A profile it started is stopped and thrown away.
|
|
205
|
+
def discard_execution
|
|
206
|
+
exe = Current.execution
|
|
207
|
+
return unless exe
|
|
208
|
+
|
|
209
|
+
Profiler.stop if exe.profiler_handle
|
|
210
|
+
Current.execution = exe.parent_execution
|
|
211
|
+
nil
|
|
212
|
+
end
|
|
213
|
+
|
|
202
214
|
# --- record writing --------------------------------------------------------
|
|
203
215
|
|
|
204
216
|
# Records that make sense without a parent execution (console, boot).
|
|
@@ -309,6 +321,30 @@ module Railwatch
|
|
|
309
321
|
config.user(&block)
|
|
310
322
|
end
|
|
311
323
|
|
|
324
|
+
# The tenant hint for the browser client (startRailwatch({ tenant })),
|
|
325
|
+
# signed with the app's secret_key_base. The beacon takes no credential,
|
|
326
|
+
# so it believes only a tenant this app put in the page itself; a bare
|
|
327
|
+
# name a client sends is ignored. nil in, nil out.
|
|
328
|
+
def beacon_tenant_hint(tenant)
|
|
329
|
+
return nil if tenant.nil? || tenant.to_s.empty?
|
|
330
|
+
|
|
331
|
+
beacon_tenant_verifier.generate(tenant.to_s[0, 255], purpose: :railwatch_beacon_tenant)
|
|
332
|
+
end
|
|
333
|
+
|
|
334
|
+
# The tenant a signed hint names, or nil for anything this app did not sign.
|
|
335
|
+
def verified_beacon_tenant(hint)
|
|
336
|
+
return nil unless hint.is_a?(String) && !hint.empty?
|
|
337
|
+
|
|
338
|
+
tenant = beacon_tenant_verifier.verified(hint, purpose: :railwatch_beacon_tenant)
|
|
339
|
+
tenant.is_a?(String) ? tenant : nil
|
|
340
|
+
rescue StandardError
|
|
341
|
+
nil
|
|
342
|
+
end
|
|
343
|
+
|
|
344
|
+
def beacon_tenant_verifier
|
|
345
|
+
Rails.application.message_verifier("railwatch.beacon_tenant")
|
|
346
|
+
end
|
|
347
|
+
|
|
312
348
|
def fingerprint(&block)
|
|
313
349
|
config.fingerprint(&block)
|
|
314
350
|
end
|
|
@@ -30,9 +30,10 @@ module Railwatch
|
|
|
30
30
|
|
|
31
31
|
# Where this install's platform lives, derived from config.ingest_url:
|
|
32
32
|
# railwatch:token and railwatch:mcp point at the same host the gem already
|
|
33
|
-
# ships to, so a self-hosted app never gets told to visit railwatch.
|
|
33
|
+
# ships to, so a self-hosted app never gets told to visit app.railwatch.dev.
|
|
34
34
|
class Endpoints
|
|
35
|
-
|
|
35
|
+
# Railwatch Cloud; railwatch.rebulk.com is its old name and redirects.
|
|
36
|
+
HOSTED_HOSTS = %w[app.railwatch.dev railwatch.rebulk.com].freeze
|
|
36
37
|
|
|
37
38
|
def initialize(config)
|
|
38
39
|
@uri = URI.parse(config.ingest_url)
|
|
@@ -48,7 +49,7 @@ module Railwatch
|
|
|
48
49
|
end
|
|
49
50
|
|
|
50
51
|
def self_hosted?
|
|
51
|
-
@uri.host
|
|
52
|
+
!HOSTED_HOSTS.include?(@uri.host)
|
|
52
53
|
end
|
|
53
54
|
end
|
|
54
55
|
end
|
|
@@ -275,9 +276,9 @@ namespace :railwatch do
|
|
|
275
276
|
# The same shape as `mission_control:jobs:authentication:configure`: asks
|
|
276
277
|
# for a user and password and writes them to the current environment's
|
|
277
278
|
# credentials under `railwatch:`, which the engine reads at boot and
|
|
278
|
-
# railwatch-
|
|
279
|
+
# railwatch-sidecar's dashboard proxy checks.
|
|
279
280
|
# RAILS_ENV=production bin/rails railwatch:authentication:configure
|
|
280
|
-
desc "Configure HTTP Basic authentication for railwatch-
|
|
281
|
+
desc "Configure HTTP Basic authentication for railwatch-sidecar's dashboard (writes Rails credentials)"
|
|
281
282
|
task "authentication:configure" => :environment do
|
|
282
283
|
Railwatch::Authentication.configure
|
|
283
284
|
end
|
data/llms.txt
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
> every one of them into a single execution tree by `execution_id`/`trace_id`,
|
|
8
8
|
> and sends them from a background thread over HTTPS to a Railwatch server:
|
|
9
9
|
> Railwatch Cloud (the default), a self-hosted railwatch-rs, or the one the
|
|
10
|
-
> separate `railwatch-
|
|
10
|
+
> separate `railwatch-sidecar` gem runs next to Puma for an embedded dashboard
|
|
11
11
|
> at `/railwatch`. It replaces a separate APM and a separate error tracker
|
|
12
12
|
> with one gem and one configuration block, costs under a millisecond of CPU
|
|
13
13
|
> per request, and never writes to the application's primary database.
|
|
@@ -20,9 +20,9 @@
|
|
|
20
20
|
|
|
21
21
|
## Docs
|
|
22
22
|
|
|
23
|
-
- [README](README.md): what Railwatch is, where telemetry goes (Cloud, self-hosted, railwatch-
|
|
24
|
-
- [Getting started](docs/getting-started.md): the install and where its token comes from, embedded with the `railwatch-
|
|
25
|
-
- [Configuration](docs/configuration.md): every configuration option and its `RAILWATCH_*` environment variable, plus the full public facade, redaction, rejection, transport and buffering behaviour, the dashboard gate railwatch-
|
|
23
|
+
- [README](README.md): what Railwatch is, where telemetry goes (Cloud, self-hosted, railwatch-sidecar), the install, and where each document fits.
|
|
24
|
+
- [Getting started](docs/getting-started.md): the install and where its token comes from, embedded with the `railwatch-sidecar` gem, moving from 0.x embedded mode, the three optional lines, and deploying under Kamal, Docker/Heroku/Render, or no deploy tool at all.
|
|
25
|
+
- [Configuration](docs/configuration.md): every configuration option and its `RAILWATCH_*` environment variable, plus the full public facade, redaction, rejection, transport and buffering behaviour, the dashboard gate railwatch-sidecar uses, and the rake tasks.
|
|
26
26
|
- [Record types](docs/records.md): every record type the gem ships and every attribute on it, including RubyLLM calls (tokens, cost, finish reason, tool calls, workflows), sourced from the code that builds it.
|
|
27
27
|
- [Testing](docs/testing.md): the RSpec and Minitest matchers (`have_railwatch_queries`, `have_railwatch_n_plus_one`, `record_railwatch_span`, `record_railwatch_exception`, `have_railwatch_outgoing_requests`, `have_railwatch_http_in_transaction`) and a CI performance-gate recipe.
|
|
28
28
|
- [Production source maps](docs/source-maps.md): hidden Vite maps, private upload before publishing assets, safe opt-in deletion, resolved browser stacks and default issue grouping.
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: railwatch
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.6.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Cole Robertson
|
|
@@ -77,6 +77,7 @@ files:
|
|
|
77
77
|
- lib/generators/railwatch/install/templates/initializer.rb.tt
|
|
78
78
|
- lib/generators/railwatch/install/templates/post-deploy
|
|
79
79
|
- lib/generators/railwatch/install/templates/railwatch.ts
|
|
80
|
+
- lib/puma/plugin/railwatch.rb
|
|
80
81
|
- lib/railwatch.rb
|
|
81
82
|
- lib/railwatch/attachments.rb
|
|
82
83
|
- lib/railwatch/authentication.rb
|
|
@@ -137,11 +138,11 @@ files:
|
|
|
137
138
|
- lib/railwatch/wire_fixtures.json
|
|
138
139
|
- lib/tasks/railwatch_tasks.rake
|
|
139
140
|
- llms.txt
|
|
140
|
-
homepage: https://railwatch.
|
|
141
|
+
homepage: https://railwatch.dev
|
|
141
142
|
licenses:
|
|
142
143
|
- MIT
|
|
143
144
|
metadata:
|
|
144
|
-
homepage_uri: https://railwatch.
|
|
145
|
+
homepage_uri: https://railwatch.dev
|
|
145
146
|
source_code_uri: https://github.com/Rebulk/railwatch
|
|
146
147
|
changelog_uri: https://github.com/Rebulk/railwatch/blob/main/CHANGELOG.md
|
|
147
148
|
documentation_uri: https://github.com/Rebulk/railwatch/blob/main/README.md
|