raises 0.1.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 +7 -0
- data/CHANGELOG.md +7 -0
- data/LICENSE.txt +9 -0
- data/README.md +13 -0
- data/lib/raises/railtie.rb +9 -0
- data/lib/raises/subscriber.rb +139 -0
- data/lib/raises/version.rb +5 -0
- data/lib/raises.rb +8 -0
- metadata +64 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: bf7a8c31ce5ed40e110b57671dee77d76cc712059ba386c64fed29f3e9da31ad
|
|
4
|
+
data.tar.gz: 12e7e56ce32e4c3cbeea11912f7de8e765ee0cf44636a99bd963e8b2796c510f
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 3ca5937ee49e66bafd8c7dc6d25ca55999d35ebc2f336f75d9206f3a1dccc4570b70c62f4d3169021b305d790941586df216ade5d4257c090b8c9223b09a7f1f
|
|
7
|
+
data.tar.gz: 95e0bac19718d9f1f0ab67856425c31180f7207c72e0e2fc1cb64d0727c3c446a1cf7dcbaf9adfa33c7c00f8c446b64f7563d58a1cb70af899008b1d90cb256f
|
data/CHANGELOG.md
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Clayton Lengel-Zigich
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# raises
|
|
2
|
+
|
|
3
|
+
The Rails client for [Raises](https://raises.dev), error reporting operated by coding agents.
|
|
4
|
+
|
|
5
|
+
```ruby
|
|
6
|
+
gem "raises"
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
Set `RAISES_TOKEN` to the ingestion credential created for the project. Production errors are reported to `https://raises.dev` automatically through `Rails.error`. Set `RAISES_REPORT=1` to exercise the integration outside production.
|
|
10
|
+
|
|
11
|
+
Optional settings are `RAISES_URL`, `RAISES_ENV`, `RAISES_REVISION`, `RAISES_OPEN_TIMEOUT`, and `RAISES_READ_TIMEOUT`.
|
|
12
|
+
|
|
13
|
+
The reporter fails open: network or serialization failures never replace the application exception. Rails filtered parameters are included; headers, raw bodies, query strings, and the request object are not.
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "json"
|
|
4
|
+
require "net/http"
|
|
5
|
+
require "uri"
|
|
6
|
+
|
|
7
|
+
module Raises
|
|
8
|
+
class Subscriber
|
|
9
|
+
def report(error, handled:, severity:, context:, source: nil)
|
|
10
|
+
return unless report?
|
|
11
|
+
|
|
12
|
+
notice = {
|
|
13
|
+
env: env_name,
|
|
14
|
+
revision: revision,
|
|
15
|
+
handled: handled,
|
|
16
|
+
error: {
|
|
17
|
+
class: error.class.name,
|
|
18
|
+
message: error.message.to_s,
|
|
19
|
+
backtrace: Array(error.backtrace)
|
|
20
|
+
},
|
|
21
|
+
context: json_safe(context_without_request(context).merge(severity: severity.to_s, source: source)),
|
|
22
|
+
request: request_from(context)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
post(notice)
|
|
26
|
+
rescue StandardError => e
|
|
27
|
+
warn("raises subscriber failed: #{e.class}: #{e.message}")
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
private
|
|
31
|
+
|
|
32
|
+
def report?
|
|
33
|
+
return false if url.to_s.empty? || token.to_s.empty?
|
|
34
|
+
return true if ENV["RAISES_REPORT"] == "1"
|
|
35
|
+
|
|
36
|
+
env_name == "production"
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def url
|
|
40
|
+
ENV.fetch("RAISES_URL", "https://raises.dev")
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def token
|
|
44
|
+
ENV["RAISES_TOKEN"].to_s
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def env_name
|
|
48
|
+
ENV["RAISES_ENV"].to_s.then { |value| value.empty? ? nil : value } ||
|
|
49
|
+
(defined?(Rails) ? Rails.env.to_s : "production")
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def revision
|
|
53
|
+
first_present(ENV.fetch("RAISES_REVISION", nil), ENV.fetch("KAMAL_VERSION", nil), git_revision)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def first_present(*values)
|
|
57
|
+
values.find { |value| !value.to_s.empty? }
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def git_revision
|
|
61
|
+
return unless defined?(Rails)
|
|
62
|
+
|
|
63
|
+
path = Rails.root.join("REVISION")
|
|
64
|
+
path.read.strip if path.exist?
|
|
65
|
+
rescue StandardError
|
|
66
|
+
nil
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def request_from(context)
|
|
70
|
+
req = context[:request] || context["request"]
|
|
71
|
+
return unless req.respond_to?(:method) && req.respond_to?(:original_url)
|
|
72
|
+
|
|
73
|
+
json_safe(
|
|
74
|
+
method: req.method,
|
|
75
|
+
path: filtered_path(req),
|
|
76
|
+
params: req.respond_to?(:filtered_parameters) ? req.filtered_parameters : nil
|
|
77
|
+
)
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def context_without_request(context)
|
|
81
|
+
return {} unless context.respond_to?(:each)
|
|
82
|
+
|
|
83
|
+
context.each_with_object({}) do |(key, value), clean|
|
|
84
|
+
clean[key] = value unless key.to_s == "request"
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def filtered_path(request)
|
|
89
|
+
return request.filtered_path if request.respond_to?(:filtered_path)
|
|
90
|
+
|
|
91
|
+
uri = URI(request.original_url)
|
|
92
|
+
uri.path.to_s.empty? ? "/" : uri.path
|
|
93
|
+
rescue URI::InvalidURIError
|
|
94
|
+
"/"
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
def json_safe(value)
|
|
98
|
+
JSON.parse(JSON.generate(as_jsonable(value)))
|
|
99
|
+
rescue StandardError
|
|
100
|
+
{ "unserializable" => value.class.name }
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
def as_jsonable(value)
|
|
104
|
+
case value
|
|
105
|
+
when Hash
|
|
106
|
+
value.each_with_object({}) { |(k, v), acc| acc[k.to_s] = as_jsonable(v) }
|
|
107
|
+
when Array
|
|
108
|
+
value.map { |item| as_jsonable(item) }
|
|
109
|
+
when Numeric, TrueClass, FalseClass, NilClass
|
|
110
|
+
value
|
|
111
|
+
else
|
|
112
|
+
value.to_s
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
def post(notice)
|
|
117
|
+
uri = URI.join(url.end_with?("/") ? url : "#{url}/", "v1/notices")
|
|
118
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
|
119
|
+
http.use_ssl = uri.scheme == "https"
|
|
120
|
+
http.open_timeout = timeout("RAISES_OPEN_TIMEOUT", 1)
|
|
121
|
+
http.read_timeout = timeout("RAISES_READ_TIMEOUT", 2)
|
|
122
|
+
request = Net::HTTP::Post.new(uri.request_uri)
|
|
123
|
+
request["Authorization"] = "Bearer #{token}"
|
|
124
|
+
request["Content-Type"] = "application/json"
|
|
125
|
+
request["User-Agent"] = "raises-ruby/#{Raises::VERSION}"
|
|
126
|
+
request.body = JSON.generate(notice)
|
|
127
|
+
response = http.request(request)
|
|
128
|
+
warn("raises rejected notice: HTTP #{response.code}") unless response.is_a?(Net::HTTPSuccess)
|
|
129
|
+
response
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
def timeout(name, fallback)
|
|
133
|
+
value = Float(ENV.fetch(name, fallback.to_s))
|
|
134
|
+
value.positive? && value <= 30 ? value : fallback
|
|
135
|
+
rescue ArgumentError
|
|
136
|
+
fallback
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
end
|
data/lib/raises.rb
ADDED
metadata
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: raises
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Clayton Lengel-Zigich
|
|
8
|
+
bindir: bin
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: railties
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - ">="
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: '7.1'
|
|
19
|
+
type: :runtime
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - ">="
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: '7.1'
|
|
26
|
+
description: A Rails.error subscriber for the agent-operated Raises exception inbox.
|
|
27
|
+
executables: []
|
|
28
|
+
extensions: []
|
|
29
|
+
extra_rdoc_files: []
|
|
30
|
+
files:
|
|
31
|
+
- CHANGELOG.md
|
|
32
|
+
- LICENSE.txt
|
|
33
|
+
- README.md
|
|
34
|
+
- lib/raises.rb
|
|
35
|
+
- lib/raises/railtie.rb
|
|
36
|
+
- lib/raises/subscriber.rb
|
|
37
|
+
- lib/raises/version.rb
|
|
38
|
+
homepage: https://raises.dev
|
|
39
|
+
licenses:
|
|
40
|
+
- MIT
|
|
41
|
+
metadata:
|
|
42
|
+
homepage_uri: https://raises.dev
|
|
43
|
+
source_code_uri: https://github.com/clayton/raises
|
|
44
|
+
changelog_uri: https://github.com/clayton/raises/blob/master/gem/CHANGELOG.md
|
|
45
|
+
bug_tracker_uri: https://github.com/clayton/raises/issues
|
|
46
|
+
rubygems_mfa_required: 'true'
|
|
47
|
+
rdoc_options: []
|
|
48
|
+
require_paths:
|
|
49
|
+
- lib
|
|
50
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - ">="
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '3.2'
|
|
55
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
56
|
+
requirements:
|
|
57
|
+
- - ">="
|
|
58
|
+
- !ruby/object:Gem::Version
|
|
59
|
+
version: '0'
|
|
60
|
+
requirements: []
|
|
61
|
+
rubygems_version: 4.0.10
|
|
62
|
+
specification_version: 4
|
|
63
|
+
summary: Rails.error subscriber that reports exceptions to a raises inbox
|
|
64
|
+
test_files: []
|