bugstack 1.0.2 → 1.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 +4 -4
- data/CHANGELOG.md +31 -20
- data/LICENSE +21 -21
- data/README.md +176 -174
- data/lib/bugstack/client.rb +123 -123
- data/lib/bugstack/configuration.rb +68 -68
- data/lib/bugstack/event.rb +90 -90
- data/lib/bugstack/fingerprint.rb +97 -97
- data/lib/bugstack/integrations/generic.rb +41 -41
- data/lib/bugstack/integrations/rails.rb +61 -61
- data/lib/bugstack/integrations/sinatra.rb +41 -41
- data/lib/bugstack/transport.rb +111 -95
- data/lib/bugstack/version.rb +5 -5
- data/lib/bugstack.rb +64 -63
- metadata +19 -13
data/lib/bugstack/transport.rb
CHANGED
|
@@ -1,95 +1,111 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "net/http"
|
|
4
|
-
require "json"
|
|
5
|
-
require "uri"
|
|
6
|
-
|
|
7
|
-
module Bugstack
|
|
8
|
-
# HTTP transport with background thread and retry logic.
|
|
9
|
-
# Uses stdlib net/http — zero gem dependencies.
|
|
10
|
-
class Transport
|
|
11
|
-
def initialize(endpoint:, api_key:, timeout: 5.0, max_retries: 3, debug: false)
|
|
12
|
-
@endpoint = URI.parse(endpoint)
|
|
13
|
-
@api_key = api_key
|
|
14
|
-
@timeout = timeout
|
|
15
|
-
@max_retries = max_retries
|
|
16
|
-
@debug = debug
|
|
17
|
-
@queue = Queue.new
|
|
18
|
-
@shutdown = false
|
|
19
|
-
@worker = start_worker
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
# Add a payload to the send queue (non-blocking).
|
|
23
|
-
#
|
|
24
|
-
#
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
def
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "net/http"
|
|
4
|
+
require "json"
|
|
5
|
+
require "uri"
|
|
6
|
+
|
|
7
|
+
module Bugstack
|
|
8
|
+
# HTTP transport with background thread and retry logic.
|
|
9
|
+
# Uses stdlib net/http — zero gem dependencies.
|
|
10
|
+
class Transport
|
|
11
|
+
def initialize(endpoint:, api_key:, timeout: 5.0, max_retries: 3, debug: false)
|
|
12
|
+
@endpoint = URI.parse(endpoint)
|
|
13
|
+
@api_key = api_key
|
|
14
|
+
@timeout = timeout
|
|
15
|
+
@max_retries = max_retries
|
|
16
|
+
@debug = debug
|
|
17
|
+
@queue = Queue.new
|
|
18
|
+
@shutdown = false
|
|
19
|
+
@worker = start_worker
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# Add a payload to the send queue (non-blocking).
|
|
23
|
+
# Falls back to synchronous send if worker thread is dead.
|
|
24
|
+
#
|
|
25
|
+
# @param payload [Hash]
|
|
26
|
+
def enqueue(payload)
|
|
27
|
+
return if @shutdown
|
|
28
|
+
|
|
29
|
+
# Check if worker thread is alive; if not (e.g. after fork), send synchronously
|
|
30
|
+
if @worker&.alive?
|
|
31
|
+
log_debug("Enqueuing to background thread")
|
|
32
|
+
@queue << payload
|
|
33
|
+
else
|
|
34
|
+
log_debug("Worker thread dead (pid=#{Process.pid}), sending synchronously")
|
|
35
|
+
send_with_retry(payload)
|
|
36
|
+
end
|
|
37
|
+
rescue => e
|
|
38
|
+
log_debug("Enqueue failed: #{e.message}")
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# Stop the worker thread and wait for it to finish.
|
|
42
|
+
def shutdown
|
|
43
|
+
@shutdown = true
|
|
44
|
+
@queue << :stop
|
|
45
|
+
@worker&.join(2)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
private
|
|
49
|
+
|
|
50
|
+
def start_worker
|
|
51
|
+
debug = @debug
|
|
52
|
+
Thread.new do
|
|
53
|
+
warn "[BugStack] Transport worker started (pid=#{Process.pid})" if debug
|
|
54
|
+
loop do
|
|
55
|
+
payload = @queue.pop
|
|
56
|
+
break if payload == :stop
|
|
57
|
+
|
|
58
|
+
warn "[BugStack] Worker dequeued event, sending..." if debug
|
|
59
|
+
send_with_retry(payload)
|
|
60
|
+
end
|
|
61
|
+
rescue Exception => e
|
|
62
|
+
warn "[BugStack] Worker thread crashed: #{e.class}: #{e.message}"
|
|
63
|
+
end.tap { |t| t.name = "bugstack-transport" if t.respond_to?(:name=) }
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def send_with_retry(payload)
|
|
67
|
+
body = JSON.generate(payload)
|
|
68
|
+
|
|
69
|
+
@max_retries.times do |attempt|
|
|
70
|
+
begin
|
|
71
|
+
http = Net::HTTP.new(@endpoint.host, @endpoint.port)
|
|
72
|
+
http.use_ssl = @endpoint.scheme == "https"
|
|
73
|
+
http.open_timeout = @timeout
|
|
74
|
+
http.read_timeout = @timeout
|
|
75
|
+
|
|
76
|
+
request = Net::HTTP::Post.new(@endpoint.request_uri)
|
|
77
|
+
request["Content-Type"] = "application/json"
|
|
78
|
+
request["X-BugStack-API-Key"] = @api_key
|
|
79
|
+
request["X-BugStack-SDK-Version"] = Bugstack::VERSION
|
|
80
|
+
request.body = body
|
|
81
|
+
|
|
82
|
+
response = http.request(request)
|
|
83
|
+
|
|
84
|
+
if response.code.to_i < 400
|
|
85
|
+
log_debug("Event sent successfully (HTTP #{response.code})")
|
|
86
|
+
return true
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
log_debug("HTTP #{response.code} (attempt #{attempt + 1})")
|
|
90
|
+
rescue => e
|
|
91
|
+
log_debug("Send failed (attempt #{attempt + 1}): #{e.class}: #{e.message}")
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
# Exponential backoff: 1s, 2s, 4s
|
|
95
|
+
sleep(2**attempt) if attempt < @max_retries - 1
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
log_debug("Max retries exceeded, dropping event")
|
|
99
|
+
false
|
|
100
|
+
rescue => e
|
|
101
|
+
log_debug("send_with_retry crashed: #{e.class}: #{e.message}")
|
|
102
|
+
false
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
def log_debug(msg)
|
|
106
|
+
return unless @debug
|
|
107
|
+
|
|
108
|
+
warn "[BugStack] #{msg}"
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
end
|
data/lib/bugstack/version.rb
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Bugstack
|
|
4
|
-
VERSION = "1.0
|
|
5
|
-
end
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Bugstack
|
|
4
|
+
VERSION = "1.1.0"
|
|
5
|
+
end
|
data/lib/bugstack.rb
CHANGED
|
@@ -1,63 +1,64 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require_relative "bugstack/version"
|
|
4
|
-
require_relative "bugstack/configuration"
|
|
5
|
-
require_relative "bugstack/event"
|
|
6
|
-
require_relative "bugstack/fingerprint"
|
|
7
|
-
require_relative "bugstack/transport"
|
|
8
|
-
require_relative "bugstack/client"
|
|
9
|
-
|
|
10
|
-
#
|
|
11
|
-
#
|
|
12
|
-
#
|
|
13
|
-
#
|
|
14
|
-
#
|
|
15
|
-
#
|
|
16
|
-
#
|
|
17
|
-
#
|
|
18
|
-
#
|
|
19
|
-
#
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
#
|
|
29
|
-
#
|
|
30
|
-
# @
|
|
31
|
-
# @
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
config
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
@client
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
#
|
|
44
|
-
#
|
|
45
|
-
# @param
|
|
46
|
-
# @param
|
|
47
|
-
# @
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
@client
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
end
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "bugstack/version"
|
|
4
|
+
require_relative "bugstack/configuration"
|
|
5
|
+
require_relative "bugstack/event"
|
|
6
|
+
require_relative "bugstack/fingerprint"
|
|
7
|
+
require_relative "bugstack/transport"
|
|
8
|
+
require_relative "bugstack/client"
|
|
9
|
+
|
|
10
|
+
# The Bugstack SDK for Ruby. Reports uncaught server errors to Bugstack,
|
|
11
|
+
# autonomous software maintenance.
|
|
12
|
+
#
|
|
13
|
+
# Usage:
|
|
14
|
+
# Bugstack.init(api_key: "bs_live_...")
|
|
15
|
+
#
|
|
16
|
+
# begin
|
|
17
|
+
# risky_operation
|
|
18
|
+
# rescue => e
|
|
19
|
+
# Bugstack.capture_exception(e)
|
|
20
|
+
# end
|
|
21
|
+
module Bugstack
|
|
22
|
+
class Error < StandardError; end
|
|
23
|
+
|
|
24
|
+
class << self
|
|
25
|
+
# @return [Bugstack::Client, nil]
|
|
26
|
+
attr_reader :client
|
|
27
|
+
|
|
28
|
+
# Initialize the BugStack SDK.
|
|
29
|
+
#
|
|
30
|
+
# @param api_key [String] Your BugStack API key (required)
|
|
31
|
+
# @yield [config] Optional block for configuration
|
|
32
|
+
# @return [Bugstack::Client]
|
|
33
|
+
def init(api_key: nil, **options, &block)
|
|
34
|
+
config = Configuration.new
|
|
35
|
+
config.api_key = api_key if api_key
|
|
36
|
+
options.each { |k, v| config.public_send(:"#{k}=", v) }
|
|
37
|
+
yield config if block_given?
|
|
38
|
+
|
|
39
|
+
@client&.shutdown
|
|
40
|
+
@client = Client.new(config)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# Capture an exception and send it to BugStack.
|
|
44
|
+
#
|
|
45
|
+
# @param exception [Exception]
|
|
46
|
+
# @param request [Hash, nil] Request context
|
|
47
|
+
# @param metadata [Hash, nil] Additional metadata
|
|
48
|
+
# @return [Boolean]
|
|
49
|
+
def capture_exception(exception, request: nil, metadata: nil)
|
|
50
|
+
unless @client
|
|
51
|
+
warn "[BugStack] Not initialized. Call Bugstack.init first."
|
|
52
|
+
return false
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
@client.capture_exception(exception, request: request, metadata: metadata)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
# Flush pending events and shut down.
|
|
59
|
+
def shutdown
|
|
60
|
+
@client&.shutdown
|
|
61
|
+
@client = nil
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|
metadata
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: bugstack
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.0
|
|
4
|
+
version: 1.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
|
-
-
|
|
7
|
+
- Bugstack
|
|
8
|
+
autorequire:
|
|
8
9
|
bindir: bin
|
|
9
10
|
cert_chain: []
|
|
10
|
-
date:
|
|
11
|
+
date: 2026-11-17 00:00:00.000000000 Z
|
|
11
12
|
dependencies:
|
|
12
13
|
- !ruby/object:Gem::Dependency
|
|
13
14
|
name: rspec
|
|
@@ -65,10 +66,12 @@ dependencies:
|
|
|
65
66
|
- - "~>"
|
|
66
67
|
- !ruby/object:Gem::Version
|
|
67
68
|
version: '1.50'
|
|
68
|
-
description:
|
|
69
|
-
|
|
69
|
+
description: Reports uncaught server errors from Rails, Sinatra and Rack apps to Bugstack,
|
|
70
|
+
autonomous software maintenance. Bugstack watches your app and your repository,
|
|
71
|
+
fixes what breaks, and sends every change as a pull request you control. No runtime
|
|
72
|
+
dependencies.
|
|
70
73
|
email:
|
|
71
|
-
-
|
|
74
|
+
- support@bugstack.ai
|
|
72
75
|
executables: []
|
|
73
76
|
extensions: []
|
|
74
77
|
extra_rdoc_files: []
|
|
@@ -86,14 +89,16 @@ files:
|
|
|
86
89
|
- lib/bugstack/integrations/sinatra.rb
|
|
87
90
|
- lib/bugstack/transport.rb
|
|
88
91
|
- lib/bugstack/version.rb
|
|
89
|
-
homepage: https://bugstack.
|
|
92
|
+
homepage: https://bugstack.ai
|
|
90
93
|
licenses:
|
|
91
94
|
- MIT
|
|
92
95
|
metadata:
|
|
93
|
-
homepage_uri: https://bugstack.
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
96
|
+
homepage_uri: https://bugstack.ai
|
|
97
|
+
documentation_uri: https://bugstack.ai/docs/sdk/ruby
|
|
98
|
+
source_code_uri: https://github.com/Bugstackai/Bugstack-SDK-Ruby
|
|
99
|
+
changelog_uri: https://github.com/Bugstackai/Bugstack-SDK-Ruby/blob/main/CHANGELOG.md
|
|
100
|
+
bug_tracker_uri: https://github.com/Bugstackai/Bugstack-SDK-Ruby/issues
|
|
101
|
+
post_install_message:
|
|
97
102
|
rdoc_options: []
|
|
98
103
|
require_paths:
|
|
99
104
|
- lib
|
|
@@ -108,7 +113,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
108
113
|
- !ruby/object:Gem::Version
|
|
109
114
|
version: '0'
|
|
110
115
|
requirements: []
|
|
111
|
-
rubygems_version: 3.
|
|
116
|
+
rubygems_version: 3.4.19
|
|
117
|
+
signing_key:
|
|
112
118
|
specification_version: 4
|
|
113
|
-
summary:
|
|
119
|
+
summary: The Bugstack SDK for Ruby
|
|
114
120
|
test_files: []
|