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.
@@ -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
- # @param payload [Hash]
25
- def enqueue(payload)
26
- return if @shutdown
27
-
28
- @queue << payload
29
- rescue => e
30
- log_debug("Enqueue failed: #{e.message}")
31
- end
32
-
33
- # Stop the worker thread and wait for it to finish.
34
- def shutdown
35
- @shutdown = true
36
- @queue << :stop
37
- @worker&.join(2)
38
- end
39
-
40
- private
41
-
42
- def start_worker
43
- Thread.new do
44
- loop do
45
- payload = @queue.pop
46
- break if payload == :stop
47
-
48
- send_with_retry(payload)
49
- end
50
- end.tap { |t| t.name = "bugstack-transport" if t.respond_to?(:name=) }
51
- end
52
-
53
- def send_with_retry(payload)
54
- body = JSON.generate(payload)
55
-
56
- @max_retries.times do |attempt|
57
- begin
58
- http = Net::HTTP.new(@endpoint.host, @endpoint.port)
59
- http.use_ssl = @endpoint.scheme == "https"
60
- http.open_timeout = @timeout
61
- http.read_timeout = @timeout
62
-
63
- request = Net::HTTP::Post.new(@endpoint.request_uri)
64
- request["Content-Type"] = "application/json"
65
- request["X-BugStack-API-Key"] = @api_key
66
- request["X-BugStack-SDK-Version"] = Bugstack::VERSION
67
- request.body = body
68
-
69
- response = http.request(request)
70
-
71
- if response.code.to_i < 400
72
- log_debug("Event sent successfully")
73
- return true
74
- end
75
-
76
- log_debug("HTTP #{response.code} (attempt #{attempt + 1})")
77
- rescue => e
78
- log_debug("Send failed (attempt #{attempt + 1}): #{e.message}")
79
- end
80
-
81
- # Exponential backoff: 1s, 2s, 4s
82
- sleep(2**attempt) if attempt < @max_retries - 1
83
- end
84
-
85
- log_debug("Max retries exceeded, dropping event")
86
- false
87
- end
88
-
89
- def log_debug(msg)
90
- return unless @debug
91
-
92
- warn "[BugStack] #{msg}"
93
- end
94
- end
95
- end
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
@@ -1,5 +1,5 @@
1
- # frozen_string_literal: true
2
-
3
- module Bugstack
4
- VERSION = "1.0.2"
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
- # BugStack SDK for Ruby — capture, report, and auto-fix production errors.
11
- #
12
- # Usage:
13
- # Bugstack.init(api_key: "bs_live_...")
14
- #
15
- # begin
16
- # risky_operation
17
- # rescue => e
18
- # Bugstack.capture_exception(e)
19
- # end
20
- module Bugstack
21
- class Error < StandardError; end
22
-
23
- class << self
24
- # @return [Bugstack::Client, nil]
25
- attr_reader :client
26
-
27
- # Initialize the BugStack SDK.
28
- #
29
- # @param api_key [String] Your BugStack API key (required)
30
- # @yield [config] Optional block for configuration
31
- # @return [Bugstack::Client]
32
- def init(api_key: nil, **options, &block)
33
- config = Configuration.new
34
- config.api_key = api_key if api_key
35
- options.each { |k, v| config.public_send(:"#{k}=", v) }
36
- yield config if block_given?
37
-
38
- @client&.shutdown
39
- @client = Client.new(config)
40
- end
41
-
42
- # Capture an exception and send it to BugStack.
43
- #
44
- # @param exception [Exception]
45
- # @param request [Hash, nil] Request context
46
- # @param metadata [Hash, nil] Additional metadata
47
- # @return [Boolean]
48
- def capture_exception(exception, request: nil, metadata: nil)
49
- unless @client
50
- warn "[BugStack] Not initialized. Call Bugstack.init first."
51
- return false
52
- end
53
-
54
- @client.capture_exception(exception, request: request, metadata: metadata)
55
- end
56
-
57
- # Flush pending events and shut down.
58
- def shutdown
59
- @client&.shutdown
60
- @client = nil
61
- end
62
- end
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.2
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
- - BugStack
7
+ - Bugstack
8
+ autorequire:
8
9
  bindir: bin
9
10
  cert_chain: []
10
- date: 1980-01-02 00:00:00.000000000 Z
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: Capture, report, and auto-fix production errors with BugStack. Zero runtime
69
- dependencies. Framework integrations for Rails, Sinatra, and more.
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
- - team@bugstack.dev
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.dev
92
+ homepage: https://bugstack.ai
90
93
  licenses:
91
94
  - MIT
92
95
  metadata:
93
- homepage_uri: https://bugstack.dev
94
- source_code_uri: https://github.com/MasonBachmann7/Bugstack-SDK-Ruby
95
- changelog_uri: https://github.com/MasonBachmann7/Bugstack-SDK-Ruby/blob/main/CHANGELOG.md
96
- bug_tracker_uri: https://github.com/MasonBachmann7/Bugstack-SDK-Ruby/issues
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.6.9
116
+ rubygems_version: 3.4.19
117
+ signing_key:
112
118
  specification_version: 4
113
- summary: Official BugStack SDK for Ruby
119
+ summary: The Bugstack SDK for Ruby
114
120
  test_files: []