errorgap 0.2.0 → 0.4.0
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/CHANGELOG.md +44 -0
- data/lib/errorgap/notice.rb +41 -3
- data/lib/errorgap/rails/railtie.rb +5 -1
- data/lib/errorgap/span_collector.rb +54 -4
- data/lib/errorgap/version.rb +1 -1
- metadata +16 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3a6d206f60530a163bfebf7cbc25d4ef0f889a81d1b15c78f440c2141e4efc3a
|
|
4
|
+
data.tar.gz: d9346233cd3aec6e191a13efcec513fdfec9fadececb304549afc1527f4da3a7
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c35e78949f9cbd4e30e24acacfbd5857f3d3003aa763f6d41c26a1713dde9c3e55a62bfe0bc24caa6941029910423ba1c5b0609ee4f48fed890ff1dbc4364e5a
|
|
7
|
+
data.tar.gz: 73a7f26536826709ceb3feb1624f48caa336dc2f6981c558a7d692a2ddbbef93206ff6397f4fa4192cc6f2306a486d8125f80df5750d4ecce168845ed6466e61
|
data/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,49 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [0.4.0] - 2026-07-16
|
|
9
|
+
|
|
10
|
+
### Fixed
|
|
11
|
+
|
|
12
|
+
- Backtrace frames are now parsed on Ruby 3.4+, which formats frames as
|
|
13
|
+
`file.rb:12:in 'Class#method'` (straight quote) instead of the pre-3.4
|
|
14
|
+
`` file.rb:12:in `method' `` (backtick). Unparsed frames carried no line
|
|
15
|
+
number or function, which also prevented source excerpts from being
|
|
16
|
+
attached — the UI showed "Source is not available for this frame yet."
|
|
17
|
+
for every frame.
|
|
18
|
+
|
|
19
|
+
- DB span durations are now computed from the notification event's
|
|
20
|
+
start/finish timestamps. The `sql.active_record` payload carries no
|
|
21
|
+
`:duration` key, so every query previously shipped `0.0` — showing as
|
|
22
|
+
0.0ms 50th/95th percentiles on the Performance > Queries page.
|
|
23
|
+
|
|
24
|
+
### Added
|
|
25
|
+
|
|
26
|
+
- DB spans now carry the application call site (`file`, `line`, `fn_name`),
|
|
27
|
+
captured from the first non-gem backtrace frame, so Performance > Queries
|
|
28
|
+
can attribute each query to app code.
|
|
29
|
+
|
|
30
|
+
## [0.3.0] - 2026-07-16
|
|
31
|
+
|
|
32
|
+
### Fixed
|
|
33
|
+
|
|
34
|
+
- APM span collection now works when `config.apm_enabled` is set in a Rails
|
|
35
|
+
app initializer (the common case). The `sql.active_record` subscriber was
|
|
36
|
+
previously installed only if APM was already enabled during railtie
|
|
37
|
+
initialization, which runs before `config/initializers` — so transactions
|
|
38
|
+
shipped without spans and the time breakdown showed everything as
|
|
39
|
+
"App / other".
|
|
40
|
+
|
|
41
|
+
### Added
|
|
42
|
+
|
|
43
|
+
- In-app backtrace frames now include a source excerpt (`source: {start_line,
|
|
44
|
+
lines}`, ±6 lines around the failing line) so the errorgap UI can render
|
|
45
|
+
backtrace source without a repository integration.
|
|
46
|
+
|
|
47
|
+
- View-rendering time is now recorded as a `view` span (from Rails'
|
|
48
|
+
`process_action.action_controller` `view_runtime`), populating the
|
|
49
|
+
"View rendering" segment of the route time breakdown.
|
|
50
|
+
|
|
8
51
|
## [0.2.0] - 2026-07-10
|
|
9
52
|
|
|
10
53
|
### Added
|
|
@@ -27,5 +70,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
27
70
|
timing and DB query spans, sampled by `config.apm_sample_rate`.
|
|
28
71
|
- Authentication via the `X-Errorgap-Project-Key` header.
|
|
29
72
|
|
|
73
|
+
[0.3.0]: https://github.com/errorgaphq/errorgap-ruby/compare/v0.2.0...v0.3.0
|
|
30
74
|
[0.2.0]: https://github.com/errorgaphq/errorgap-ruby/compare/v0.1.0...v0.2.0
|
|
31
75
|
[0.1.0]: https://github.com/errorgaphq/errorgap-ruby/releases/tag/v0.1.0
|
data/lib/errorgap/notice.rb
CHANGED
|
@@ -4,6 +4,13 @@ require "time"
|
|
|
4
4
|
|
|
5
5
|
module Errorgap
|
|
6
6
|
class Notice
|
|
7
|
+
# Lines of context shipped either side of the failing line for in-app
|
|
8
|
+
# frames, and a cap on how many frames include an excerpt so deep
|
|
9
|
+
# backtraces don't inflate the payload.
|
|
10
|
+
SOURCE_RADIUS = 6
|
|
11
|
+
MAX_SOURCE_FRAMES = 25
|
|
12
|
+
MAX_SOURCE_LINE_LENGTH = 400
|
|
13
|
+
|
|
7
14
|
def self.from_exception(error, configuration:, context: {}, environment: {}, session: {}, params: {})
|
|
8
15
|
new(
|
|
9
16
|
error: error,
|
|
@@ -54,20 +61,51 @@ module Errorgap
|
|
|
54
61
|
end
|
|
55
62
|
|
|
56
63
|
def backtrace_frames
|
|
64
|
+
source_frames = 0
|
|
57
65
|
Array(@error.backtrace).map.with_index do |line, index|
|
|
58
66
|
file, line_number, function = parse_backtrace_line(line)
|
|
59
|
-
{
|
|
67
|
+
frame = {
|
|
60
68
|
file: relative_file(file),
|
|
61
69
|
line: line_number,
|
|
62
70
|
function: function,
|
|
63
71
|
in_app: in_app?(file),
|
|
64
72
|
index: index
|
|
65
|
-
}
|
|
73
|
+
}
|
|
74
|
+
if in_app?(file) && source_frames < MAX_SOURCE_FRAMES &&
|
|
75
|
+
(source = source_excerpt(file, line_number))
|
|
76
|
+
frame[:source] = source
|
|
77
|
+
source_frames += 1
|
|
78
|
+
end
|
|
79
|
+
frame.compact
|
|
66
80
|
end
|
|
67
81
|
end
|
|
68
82
|
|
|
83
|
+
# Reads the lines around the failing line so the server can show source
|
|
84
|
+
# without needing repository access. Returns nil when the file cannot be
|
|
85
|
+
# read (precompiled deploys, eval'd code, template paths).
|
|
86
|
+
def source_excerpt(file, line_number)
|
|
87
|
+
return nil unless line_number && line_number >= 1
|
|
88
|
+
return nil unless file && File.file?(file) && File.readable?(file)
|
|
89
|
+
|
|
90
|
+
lines = File.readlines(file)
|
|
91
|
+
return nil if lines.empty? || line_number > lines.length
|
|
92
|
+
|
|
93
|
+
start_line = [line_number - SOURCE_RADIUS, 1].max
|
|
94
|
+
end_line = [line_number + SOURCE_RADIUS, lines.length].min
|
|
95
|
+
{
|
|
96
|
+
start_line: start_line,
|
|
97
|
+
lines: lines[(start_line - 1)..(end_line - 1)].map do |text|
|
|
98
|
+
text.chomp[0, MAX_SOURCE_LINE_LENGTH]
|
|
99
|
+
end
|
|
100
|
+
}
|
|
101
|
+
rescue StandardError
|
|
102
|
+
nil
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
# Ruby <= 3.3 formats frames as `file.rb:42:in `method'` (backtick),
|
|
106
|
+
# Ruby >= 3.4 as `file.rb:42:in 'Class#method'` (straight quote).
|
|
69
107
|
def parse_backtrace_line(line)
|
|
70
|
-
match = line.match(/\A(.+?):(\d+)(?::in `(.*)')?\z/)
|
|
108
|
+
match = line.match(/\A(.+?):(\d+)(?::in [`'](.*)')?\z/)
|
|
71
109
|
return [line, nil, nil] unless match
|
|
72
110
|
|
|
73
111
|
[match[1], match[2].to_i, match[3]]
|
|
@@ -18,7 +18,11 @@ module Errorgap
|
|
|
18
18
|
end
|
|
19
19
|
|
|
20
20
|
initializer "errorgap.install_span_collector" do
|
|
21
|
-
|
|
21
|
+
# Unconditional: apps enable APM in config/initializers, which runs
|
|
22
|
+
# after railtie initializers, so the flag cannot be checked here. The
|
|
23
|
+
# subscribers no-op unless the middleware starts a per-request
|
|
24
|
+
# collection, which does check the flag.
|
|
25
|
+
SpanCollector.install
|
|
22
26
|
end
|
|
23
27
|
|
|
24
28
|
generators do
|
|
@@ -14,19 +14,44 @@ module Errorgap
|
|
|
14
14
|
SKIP_NAMES = %w[SCHEMA EXPLAIN CACHE].freeze
|
|
15
15
|
|
|
16
16
|
class << self
|
|
17
|
-
# Call once at boot (from Railtie)
|
|
17
|
+
# Call once at boot (from Railtie). Subscribers only record while a
|
|
18
|
+
# transaction is being collected (the middleware starts one per request
|
|
19
|
+
# when APM is enabled), so installing unconditionally is safe — and
|
|
20
|
+
# required, since app initializers that enable APM run after railtie
|
|
21
|
+
# initializers.
|
|
18
22
|
def install
|
|
19
23
|
return unless defined?(ActiveSupport::Notifications)
|
|
24
|
+
return if @installed
|
|
20
25
|
|
|
21
|
-
|
|
26
|
+
@installed = true
|
|
27
|
+
|
|
28
|
+
# The 5-arg block form receives the event's start/finish times; the
|
|
29
|
+
# sql.active_record payload itself carries no duration key.
|
|
30
|
+
ActiveSupport::Notifications.subscribe("sql.active_record") do |_name, started, finished, _id, payload|
|
|
22
31
|
next unless Thread.current[THREAD_KEY]
|
|
23
32
|
next if SKIP_NAMES.any? { |n| payload[:name]&.start_with?(n) }
|
|
24
33
|
next if payload[:cached]
|
|
25
34
|
|
|
26
|
-
duration_ms =
|
|
35
|
+
duration_ms = ((finished - started) * 1000.0).to_f
|
|
27
36
|
sql = normalize_sql(payload[:sql].to_s)
|
|
37
|
+
file, line, fn_name = app_call_site
|
|
38
|
+
|
|
39
|
+
store << Span.new(
|
|
40
|
+
kind: "db", sql: sql,
|
|
41
|
+
file: file, line: line, fn_name: fn_name,
|
|
42
|
+
duration_ms: duration_ms.round(3)
|
|
43
|
+
)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# Rails reports view_runtime with database time already subtracted, so
|
|
47
|
+
# this does not double count the db spans above.
|
|
48
|
+
ActiveSupport::Notifications.subscribe("process_action.action_controller") do |*, payload|
|
|
49
|
+
next unless Thread.current[THREAD_KEY]
|
|
50
|
+
|
|
51
|
+
view_ms = payload[:view_runtime]
|
|
52
|
+
next unless view_ms&.positive?
|
|
28
53
|
|
|
29
|
-
store << Span.new(kind: "
|
|
54
|
+
store << Span.new(kind: "view", duration_ms: view_ms.round(3))
|
|
30
55
|
end
|
|
31
56
|
end
|
|
32
57
|
|
|
@@ -47,6 +72,31 @@ module Errorgap
|
|
|
47
72
|
def normalize_sql(sql)
|
|
48
73
|
sql.gsub(NORMALIZE_PATTERN, "?").gsub(/\s+/, " ").strip
|
|
49
74
|
end
|
|
75
|
+
|
|
76
|
+
# The first backtrace frame belonging to the application — skipping this
|
|
77
|
+
# gem, other gems, and the Ruby standard library — so a query can be
|
|
78
|
+
# attributed to the app code that ran it. Returns [file, line, fn_name]
|
|
79
|
+
# with the file relative to Rails.root when available, or nils when no
|
|
80
|
+
# app frame is present (e.g. queries run from a console or gem).
|
|
81
|
+
def app_call_site
|
|
82
|
+
root = defined?(Rails) && Rails.respond_to?(:root) && Rails.root ? Rails.root.to_s : nil
|
|
83
|
+
location = caller_locations(1, 60)&.find do |loc|
|
|
84
|
+
path = loc.absolute_path || loc.path
|
|
85
|
+
next false unless path
|
|
86
|
+
next false if path.start_with?(LIB_ROOT)
|
|
87
|
+
next false if GEM_PATH_MARKERS.any? { |marker| path.include?(marker) }
|
|
88
|
+
|
|
89
|
+
root ? path.start_with?(root) : true
|
|
90
|
+
end
|
|
91
|
+
return [nil, nil, nil] unless location
|
|
92
|
+
|
|
93
|
+
path = location.absolute_path || location.path
|
|
94
|
+
path = path.delete_prefix("#{root}/") if root
|
|
95
|
+
[path, location.lineno, location.label]
|
|
96
|
+
end
|
|
50
97
|
end
|
|
98
|
+
|
|
99
|
+
LIB_ROOT = File.expand_path("..", __dir__)
|
|
100
|
+
GEM_PATH_MARKERS = ["/gems/", "/rubygems/", "/lib/ruby/", "/bundler/"].freeze
|
|
51
101
|
end
|
|
52
102
|
end
|
data/lib/errorgap/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: errorgap
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.4.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Errorgap
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-07-
|
|
11
|
+
date: 2026-07-17 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rake
|
|
@@ -38,6 +38,20 @@ dependencies:
|
|
|
38
38
|
- - "~>"
|
|
39
39
|
- !ruby/object:Gem::Version
|
|
40
40
|
version: '5.0'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: activesupport
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - ">="
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '6.1'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - ">="
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '6.1'
|
|
41
55
|
description: Captures Ruby exceptions and sends them to a Errorgap server.
|
|
42
56
|
email:
|
|
43
57
|
- support@errorgap.com
|