errorgap 0.1.0 → 0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9fc092f673d279e6295144e0bcd302fabf729ff193b00b14ed651706f9cbb388
4
- data.tar.gz: e89ffdc6f5eaab044376725d9baa3b8584a428d7f4799a89f5c22c13b9a96b30
3
+ metadata.gz: cabe7a082d767651c4e56f067d77fa21486056cde995842eb4ef7f8531adbf00
4
+ data.tar.gz: 10cc33121d252ce987eb92ccd2e57301ea4399bafa42c2b8cada4ab0dd4d1f63
5
5
  SHA512:
6
- metadata.gz: b93c2e7bbd4c4b29364a98db702c7463ac21906d73a5ace7fd779fecc209187284bc666badd6a5fe70854ae4a8f3367bbf73b8b49d0ac9e9673248e5c86ec83a
7
- data.tar.gz: c5563c43afef3637222dc69b82388bd5cb42fb44daa5494c83a79d5c053da778c1fa15dc85915a6eea0ef6e7b079a002c8b1e3a6b7a5be447c2e37be5f2e7f58
6
+ metadata.gz: 283fcdf5b95bcbf34a175b2e9249c5e2a5b4c16f46bedfe9852f088214ada0e6aa022d84f816a4c692b36291c9a3d8a0f099ee0f18beb15cf5c856d014ecdb14
7
+ data.tar.gz: a66f945ca3d16ee996aeec660dc24351baa3799e7b7404ce209202e98a3c10e6df7eac940c4bdea82e4b7ca86391c98ed3b718c174c0cfe5499485cfb14bd1b2
data/CHANGELOG.md ADDED
@@ -0,0 +1,53 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [0.3.0] - 2026-07-16
9
+
10
+ ### Fixed
11
+
12
+ - APM span collection now works when `config.apm_enabled` is set in a Rails
13
+ app initializer (the common case). The `sql.active_record` subscriber was
14
+ previously installed only if APM was already enabled during railtie
15
+ initialization, which runs before `config/initializers` — so transactions
16
+ shipped without spans and the time breakdown showed everything as
17
+ "App / other".
18
+
19
+ ### Added
20
+
21
+ - In-app backtrace frames now include a source excerpt (`source: {start_line,
22
+ lines}`, ±6 lines around the failing line) so the errorgap UI can render
23
+ backtrace source without a repository integration.
24
+
25
+ - View-rendering time is now recorded as a `view` span (from Rails'
26
+ `process_action.action_controller` `view_runtime`), populating the
27
+ "View rendering" segment of the route time breakdown.
28
+
29
+ ## [0.2.0] - 2026-07-10
30
+
31
+ ### Added
32
+
33
+ - `config.ignore_environments` configuration option to skip all reporting
34
+ (error notices and APM transactions) in the listed environments, e.g.
35
+ `config.ignore_environments = %w[test development]`. Also configurable via
36
+ the `ERRORGAP_IGNORE_ENVIRONMENTS` environment variable (comma-separated).
37
+ - `Errorgap::Configuration#ignored_environment?` helper.
38
+ - The Rails install generator initializer now includes `ignore_environments`
39
+ with `test` and `development` ignored by default.
40
+
41
+ ## [0.1.0] - 2026-07-09
42
+
43
+ ### Added
44
+
45
+ - Initial release: exception capture with normalized backtraces, manual
46
+ `Errorgap.notify`, Rack middleware, Rails Railtie and install generator.
47
+ - APM performance monitoring (opt-in via `config.apm_enabled`) with request
48
+ timing and DB query spans, sampled by `config.apm_sample_rate`.
49
+ - Authentication via the `X-Errorgap-Project-Key` header.
50
+
51
+ [0.3.0]: https://github.com/errorgaphq/errorgap-ruby/compare/v0.2.0...v0.3.0
52
+ [0.2.0]: https://github.com/errorgaphq/errorgap-ruby/compare/v0.1.0...v0.2.0
53
+ [0.1.0]: https://github.com/errorgaphq/errorgap-ruby/releases/tag/v0.1.0
data/README.md CHANGED
@@ -27,6 +27,10 @@ Errorgap.configure do |config|
27
27
  config.project_id = ENV["ERRORGAP_PROJECT_ID"]
28
28
  config.api_key = ENV["ERRORGAP_API_KEY"]
29
29
  config.environment = ENV.fetch("RAILS_ENV", ENV.fetch("RACK_ENV", "development"))
30
+
31
+ # Skip reporting entirely (errors and APM) in these environments.
32
+ # Also configurable via ERRORGAP_IGNORE_ENVIRONMENTS="test,development".
33
+ config.ignore_environments = %w[test development]
30
34
  end
31
35
  ```
32
36
 
@@ -11,6 +11,7 @@ module Errorgap
11
11
  :async,
12
12
  :logger,
13
13
  :filter_keys,
14
+ :ignore_environments,
14
15
  :apm_enabled,
15
16
  :apm_sample_rate
16
17
 
@@ -23,6 +24,7 @@ module Errorgap
23
24
  @root_directory = Dir.pwd
24
25
  @async = true
25
26
  @filter_keys = %w[password password_confirmation token secret api_key authorization cookie]
27
+ @ignore_environments = ENV.fetch("ERRORGAP_IGNORE_ENVIRONMENTS", "").split(",").map(&:strip).reject(&:empty?)
26
28
  @apm_enabled = false
27
29
  @apm_sample_rate = 1.0
28
30
  end
@@ -33,6 +35,10 @@ module Errorgap
33
35
  true
34
36
  end
35
37
 
38
+ def ignored_environment?
39
+ Array(ignore_environments).map(&:to_s).include?(environment.to_s)
40
+ end
41
+
36
42
  private
37
43
 
38
44
  def blank?(value)
@@ -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,18 +61,47 @@ 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
- }.compact
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
+
69
105
  def parse_backtrace_line(line)
70
106
  match = line.match(/\A(.+?):(\d+)(?::in `(.*)')?\z/)
71
107
  return [line, nil, nil] unless match
@@ -22,6 +22,8 @@ module Errorgap
22
22
 
23
23
  def notify(error, context: {}, environment: {}, session: {}, params: {}, sync: false)
24
24
  @configuration.validate!
25
+ return Response.new(status: 202, body: "ignored environment") if @configuration.ignored_environment?
26
+
25
27
  notice = Notice.from_exception(
26
28
  error,
27
29
  configuration: @configuration,
@@ -18,7 +18,11 @@ module Errorgap
18
18
  end
19
19
 
20
20
  initializer "errorgap.install_span_collector" do
21
- SpanCollector.install if Errorgap.configuration.apm_enabled
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,9 +14,16 @@ module Errorgap
14
14
  SKIP_NAMES = %w[SCHEMA EXPLAIN CACHE].freeze
15
15
 
16
16
  class << self
17
- # Call once at boot (from Railtie) when APM is enabled.
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
25
+
26
+ @installed = true
20
27
 
21
28
  ActiveSupport::Notifications.subscribe("sql.active_record") do |*, payload|
22
29
  next unless Thread.current[THREAD_KEY]
@@ -28,6 +35,17 @@ module Errorgap
28
35
 
29
36
  store << Span.new(kind: "db", sql: sql, duration_ms: duration_ms.round(3))
30
37
  end
38
+
39
+ # Rails reports view_runtime with database time already subtracted, so
40
+ # this does not double count the db spans above.
41
+ ActiveSupport::Notifications.subscribe("process_action.action_controller") do |*, payload|
42
+ next unless Thread.current[THREAD_KEY]
43
+
44
+ view_ms = payload[:view_runtime]
45
+ next unless view_ms&.positive?
46
+
47
+ store << Span.new(kind: "view", duration_ms: view_ms.round(3))
48
+ end
31
49
  end
32
50
 
33
51
  def start
@@ -15,6 +15,7 @@ module Errorgap
15
15
  end
16
16
 
17
17
  def deliver_async(transaction)
18
+ return if @configuration.ignored_environment?
18
19
  return unless should_sample?
19
20
 
20
21
  Thread.new { deliver(transaction) }
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Errorgap
4
- VERSION = "0.1.0"
4
+ VERSION = "0.3.0"
5
5
  end
@@ -17,6 +17,9 @@ module Errorgap
17
17
  config.root_directory = Rails.root.to_s
18
18
  config.logger = Rails.logger
19
19
 
20
+ # Environments in which nothing is reported (errors or APM).
21
+ config.ignore_environments = %w[test development]
22
+
20
23
  # Enable APM performance monitoring (opt-in).
21
24
  # Records HTTP request timing and DB query spans via ActiveSupport::Notifications.
22
25
  # config.apm_enabled = true
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.1.0
4
+ version: 0.3.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-07 00:00:00.000000000 Z
11
+ date: 2026-07-16 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
@@ -46,6 +60,7 @@ executables:
46
60
  extensions: []
47
61
  extra_rdoc_files: []
48
62
  files:
63
+ - CHANGELOG.md
49
64
  - LICENSE.txt
50
65
  - README.md
51
66
  - exe/errorgap
@@ -66,6 +81,7 @@ licenses:
66
81
  metadata:
67
82
  homepage_uri: https://github.com/errorgaphq/errorgap-ruby
68
83
  source_code_uri: https://github.com/errorgaphq/errorgap-ruby
84
+ changelog_uri: https://github.com/errorgaphq/errorgap-ruby/blob/main/CHANGELOG.md
69
85
  post_install_message:
70
86
  rdoc_options: []
71
87
  require_paths: