bugstack 1.0.1 → 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,123 +1,123 @@
1
- # frozen_string_literal: true
2
-
3
- module Bugstack
4
- # Core client for capturing and reporting errors to BugStack.
5
- # Thread-safe. Handles deduplication, filtering, and transport.
6
- class Client
7
- attr_reader :config
8
-
9
- def initialize(config)
10
- @config = config
11
- @deduplicator = Deduplicator.new(window: config.deduplication_window)
12
- @transport = nil
13
-
14
- if config.enabled && !config.dry_run
15
- @transport = Transport.new(
16
- endpoint: config.endpoint,
17
- api_key: config.api_key,
18
- timeout: config.timeout,
19
- max_retries: config.max_retries,
20
- debug: config.debug
21
- )
22
- end
23
-
24
- log_debug("Client initialized (endpoint=#{config.endpoint}, dry_run=#{config.dry_run})")
25
- end
26
-
27
- # Capture an exception and send it to BugStack.
28
- #
29
- # @param exception [Exception]
30
- # @param request [Hash, nil] { route:, method: }
31
- # @param metadata [Hash, nil]
32
- # @return [Boolean]
33
- def capture_exception(exception, request: nil, metadata: nil)
34
- do_capture(exception, request: request, metadata: metadata)
35
- rescue => e
36
- log_debug("Error during capture: #{e.message}")
37
- false
38
- end
39
-
40
- # Shut down the client and flush pending events.
41
- def shutdown
42
- @transport&.shutdown
43
- @transport = nil
44
- end
45
-
46
- private
47
-
48
- def do_capture(exception, request: nil, metadata: nil)
49
- return false unless @config.enabled
50
-
51
- # Check ignored errors
52
- if ignored?(exception)
53
- log_debug("Error ignored: #{exception.class.name}")
54
- return false
55
- end
56
-
57
- # Extract location info
58
- exc_type, file, function, line = Fingerprint.extract_location(exception)
59
- stack_trace = Fingerprint.format_backtrace(exception)
60
-
61
- # Build event
62
- event = Event.new(
63
- message: exception.message,
64
- stack_trace: stack_trace,
65
- file: file,
66
- function: function,
67
- exception_type: exc_type,
68
- fingerprint: Fingerprint.generate(exc_type, file, function, line),
69
- request: request,
70
- timestamp: Time.now.utc.iso8601,
71
- metadata: metadata || {}
72
- )
73
-
74
- # before_send hook
75
- if @config.before_send
76
- event = @config.before_send.call(event)
77
- if event.nil?
78
- log_debug("Event dropped by before_send")
79
- return false
80
- end
81
- end
82
-
83
- # Deduplication
84
- unless @deduplicator.should_send?(event.fingerprint)
85
- log_debug("Event deduplicated: #{event.fingerprint}")
86
- return false
87
- end
88
-
89
- # Build payload
90
- payload = event.to_payload(@config)
91
-
92
- # Dry run
93
- if @config.dry_run
94
- $stdout.puts "[BugStack DryRun] Would send: #{JSON.pretty_generate(payload)}"
95
- return true
96
- end
97
-
98
- # Enqueue for sending
99
- @transport&.enqueue(payload)
100
- log_debug("Event queued: #{event.fingerprint}")
101
- true
102
- end
103
-
104
- def ignored?(exception)
105
- @config.ignored_errors.any? do |pattern|
106
- case pattern
107
- when Class
108
- exception.is_a?(pattern)
109
- when String
110
- exception.message == pattern
111
- else
112
- false
113
- end
114
- end
115
- end
116
-
117
- def log_debug(msg)
118
- return unless @config.debug
119
-
120
- warn "[BugStack] #{msg}"
121
- end
122
- end
123
- end
1
+ # frozen_string_literal: true
2
+
3
+ module Bugstack
4
+ # Core client for capturing and reporting errors to BugStack.
5
+ # Thread-safe. Handles deduplication, filtering, and transport.
6
+ class Client
7
+ attr_reader :config
8
+
9
+ def initialize(config)
10
+ @config = config
11
+ @deduplicator = Deduplicator.new(window: config.deduplication_window)
12
+ @transport = nil
13
+
14
+ if config.enabled && !config.dry_run
15
+ @transport = Transport.new(
16
+ endpoint: config.endpoint,
17
+ api_key: config.api_key,
18
+ timeout: config.timeout,
19
+ max_retries: config.max_retries,
20
+ debug: config.debug
21
+ )
22
+ end
23
+
24
+ log_debug("Client initialized (endpoint=#{config.endpoint}, dry_run=#{config.dry_run})")
25
+ end
26
+
27
+ # Capture an exception and send it to BugStack.
28
+ #
29
+ # @param exception [Exception]
30
+ # @param request [Hash, nil] { route:, method: }
31
+ # @param metadata [Hash, nil]
32
+ # @return [Boolean]
33
+ def capture_exception(exception, request: nil, metadata: nil)
34
+ do_capture(exception, request: request, metadata: metadata)
35
+ rescue => e
36
+ log_debug("Error during capture: #{e.message}")
37
+ false
38
+ end
39
+
40
+ # Shut down the client and flush pending events.
41
+ def shutdown
42
+ @transport&.shutdown
43
+ @transport = nil
44
+ end
45
+
46
+ private
47
+
48
+ def do_capture(exception, request: nil, metadata: nil)
49
+ return false unless @config.enabled
50
+
51
+ # Check ignored errors
52
+ if ignored?(exception)
53
+ log_debug("Error ignored: #{exception.class.name}")
54
+ return false
55
+ end
56
+
57
+ # Extract location info
58
+ exc_type, file, function, line = Fingerprint.extract_location(exception)
59
+ stack_trace = Fingerprint.format_backtrace(exception)
60
+
61
+ # Build event
62
+ event = Event.new(
63
+ message: exception.message,
64
+ stack_trace: stack_trace,
65
+ file: file,
66
+ function: function,
67
+ exception_type: exc_type,
68
+ fingerprint: Fingerprint.generate(exc_type, file, function, line),
69
+ request: request,
70
+ timestamp: Time.now.utc.iso8601,
71
+ metadata: metadata || {}
72
+ )
73
+
74
+ # before_send hook
75
+ if @config.before_send
76
+ event = @config.before_send.call(event)
77
+ if event.nil?
78
+ log_debug("Event dropped by before_send")
79
+ return false
80
+ end
81
+ end
82
+
83
+ # Deduplication
84
+ unless @deduplicator.should_send?(event.fingerprint)
85
+ log_debug("Event deduplicated: #{event.fingerprint}")
86
+ return false
87
+ end
88
+
89
+ # Build payload
90
+ payload = event.to_payload(@config)
91
+
92
+ # Dry run
93
+ if @config.dry_run
94
+ $stdout.puts "[BugStack DryRun] Would send: #{JSON.pretty_generate(payload)}"
95
+ return true
96
+ end
97
+
98
+ # Enqueue for sending
99
+ @transport&.enqueue(payload)
100
+ log_debug("Event queued: #{event.fingerprint}")
101
+ true
102
+ end
103
+
104
+ def ignored?(exception)
105
+ @config.ignored_errors.any? do |pattern|
106
+ case pattern
107
+ when Class
108
+ exception.is_a?(pattern)
109
+ when String
110
+ exception.message == pattern
111
+ else
112
+ false
113
+ end
114
+ end
115
+ end
116
+
117
+ def log_debug(msg)
118
+ return unless @config.debug
119
+
120
+ warn "[BugStack] #{msg}"
121
+ end
122
+ end
123
+ end
@@ -1,68 +1,68 @@
1
- # frozen_string_literal: true
2
-
3
- module Bugstack
4
- # Configuration for the BugStack SDK.
5
- #
6
- # @example
7
- # Bugstack.init do |config|
8
- # config.api_key = "bs_live_..."
9
- # config.environment = "production"
10
- # config.auto_fix = true
11
- # end
12
- class Configuration
13
- # @return [String] BugStack API key (required)
14
- attr_accessor :api_key
15
-
16
- # @return [String] BugStack API endpoint
17
- attr_accessor :endpoint
18
-
19
- # @return [String] Project identifier
20
- attr_accessor :project_id
21
-
22
- # @return [String] Environment name
23
- attr_accessor :environment
24
-
25
- # @return [Boolean] Enable autonomous error fixing
26
- attr_accessor :auto_fix
27
-
28
- # @return [Boolean] Kill switch — set to false to disable everything
29
- attr_accessor :enabled
30
-
31
- # @return [Boolean] Log SDK activity to console
32
- attr_accessor :debug
33
-
34
- # @return [Boolean] Log errors but don't send them
35
- attr_accessor :dry_run
36
-
37
- # @return [Float] Deduplication window in seconds
38
- attr_accessor :deduplication_window
39
-
40
- # @return [Float] HTTP timeout in seconds
41
- attr_accessor :timeout
42
-
43
- # @return [Integer] Max retry attempts
44
- attr_accessor :max_retries
45
-
46
- # @return [Array<Class, String>] Error types or messages to ignore
47
- attr_accessor :ignored_errors
48
-
49
- # @return [Proc, nil] Hook to inspect/modify/drop events before sending
50
- attr_accessor :before_send
51
-
52
- def initialize
53
- @api_key = ""
54
- @endpoint = "https://api.bugstack.dev/api/capture"
55
- @project_id = ""
56
- @environment = "production"
57
- @auto_fix = false
58
- @enabled = true
59
- @debug = false
60
- @dry_run = false
61
- @deduplication_window = 300.0
62
- @timeout = 5.0
63
- @max_retries = 3
64
- @ignored_errors = []
65
- @before_send = nil
66
- end
67
- end
68
- end
1
+ # frozen_string_literal: true
2
+
3
+ module Bugstack
4
+ # Configuration for the BugStack SDK.
5
+ #
6
+ # @example
7
+ # Bugstack.init do |config|
8
+ # config.api_key = "bs_live_..."
9
+ # config.environment = "production"
10
+ # config.auto_fix = true
11
+ # end
12
+ class Configuration
13
+ # @return [String] BugStack API key (required)
14
+ attr_accessor :api_key
15
+
16
+ # @return [String] BugStack API endpoint
17
+ attr_accessor :endpoint
18
+
19
+ # @return [String] Project identifier
20
+ attr_accessor :project_id
21
+
22
+ # @return [String] Environment name
23
+ attr_accessor :environment
24
+
25
+ # @return [Boolean] Enable autonomous error fixing
26
+ attr_accessor :auto_fix
27
+
28
+ # @return [Boolean] Kill switch — set to false to disable everything
29
+ attr_accessor :enabled
30
+
31
+ # @return [Boolean] Log SDK activity to console
32
+ attr_accessor :debug
33
+
34
+ # @return [Boolean] Log errors but don't send them
35
+ attr_accessor :dry_run
36
+
37
+ # @return [Float] Deduplication window in seconds
38
+ attr_accessor :deduplication_window
39
+
40
+ # @return [Float] HTTP timeout in seconds
41
+ attr_accessor :timeout
42
+
43
+ # @return [Integer] Max retry attempts
44
+ attr_accessor :max_retries
45
+
46
+ # @return [Array<Class, String>] Error types or messages to ignore
47
+ attr_accessor :ignored_errors
48
+
49
+ # @return [Proc, nil] Hook to inspect/modify/drop events before sending
50
+ attr_accessor :before_send
51
+
52
+ def initialize
53
+ @api_key = ""
54
+ @endpoint = "https://dashboard.bugstack.ai/api/ingest/sdk"
55
+ @project_id = ""
56
+ @environment = "production"
57
+ @auto_fix = false
58
+ @enabled = true
59
+ @debug = false
60
+ @dry_run = false
61
+ @deduplication_window = 300.0
62
+ @timeout = 5.0
63
+ @max_retries = 3
64
+ @ignored_errors = []
65
+ @before_send = nil
66
+ end
67
+ end
68
+ end
@@ -1,90 +1,90 @@
1
- # frozen_string_literal: true
2
-
3
- require "json"
4
- require "time"
5
-
6
- module Bugstack
7
- # Represents an error event to be sent to BugStack.
8
- class Event
9
- attr_accessor :message, :stack_trace, :file, :function, :fingerprint,
10
- :exception_type, :request, :environment, :timestamp, :metadata
11
-
12
- def initialize(
13
- message:,
14
- stack_trace: "",
15
- file: "",
16
- function: "",
17
- fingerprint: "",
18
- exception_type: "",
19
- request: nil,
20
- environment: nil,
21
- timestamp: nil,
22
- metadata: {}
23
- )
24
- @message = message
25
- @stack_trace = stack_trace
26
- @file = file
27
- @function = function
28
- @fingerprint = fingerprint
29
- @exception_type = exception_type
30
- @request = request
31
- @environment = environment || default_environment
32
- @timestamp = timestamp || Time.now.utc.iso8601
33
- @metadata = metadata || {}
34
- end
35
-
36
- # Serialize to the standard BugStack API payload.
37
- #
38
- # @param config [Bugstack::Configuration]
39
- # @return [Hash]
40
- def to_payload(config)
41
- payload = {
42
- "apiKey" => config.api_key,
43
- "error" => {
44
- "message" => @message,
45
- "stackTrace" => @stack_trace,
46
- "file" => @file,
47
- "function" => @function,
48
- "fingerprint" => @fingerprint
49
- },
50
- "environment" => {
51
- "language" => @environment[:language],
52
- "languageVersion" => @environment[:language_version],
53
- "framework" => @environment[:framework].to_s,
54
- "frameworkVersion" => @environment[:framework_version].to_s,
55
- "os" => @environment[:os],
56
- "sdkVersion" => @environment[:sdk_version]
57
- },
58
- "timestamp" => @timestamp
59
- }
60
-
61
- if @request
62
- payload["request"] = {
63
- "route" => @request[:route].to_s,
64
- "method" => @request[:method].to_s
65
- }
66
- end
67
-
68
- payload["projectId"] = config.project_id unless config.project_id.empty?
69
-
70
- meta = @metadata.dup
71
- meta["autoFix"] = true if config.auto_fix
72
- payload["metadata"] = meta unless meta.empty?
73
-
74
- payload
75
- end
76
-
77
- private
78
-
79
- def default_environment
80
- {
81
- language: "ruby",
82
- language_version: RUBY_VERSION,
83
- framework: "",
84
- framework_version: "",
85
- os: RUBY_PLATFORM,
86
- sdk_version: Bugstack::VERSION
87
- }
88
- end
89
- end
90
- end
1
+ # frozen_string_literal: true
2
+
3
+ require "json"
4
+ require "time"
5
+
6
+ module Bugstack
7
+ # Represents an error event to be sent to BugStack.
8
+ class Event
9
+ attr_accessor :message, :stack_trace, :file, :function, :fingerprint,
10
+ :exception_type, :request, :environment, :timestamp, :metadata
11
+
12
+ def initialize(
13
+ message:,
14
+ stack_trace: "",
15
+ file: "",
16
+ function: "",
17
+ fingerprint: "",
18
+ exception_type: "",
19
+ request: nil,
20
+ environment: nil,
21
+ timestamp: nil,
22
+ metadata: {}
23
+ )
24
+ @message = message
25
+ @stack_trace = stack_trace
26
+ @file = file
27
+ @function = function
28
+ @fingerprint = fingerprint
29
+ @exception_type = exception_type
30
+ @request = request
31
+ @environment = environment || default_environment
32
+ @timestamp = timestamp || Time.now.utc.iso8601
33
+ @metadata = metadata || {}
34
+ end
35
+
36
+ # Serialize to the standard BugStack API payload.
37
+ #
38
+ # @param config [Bugstack::Configuration]
39
+ # @return [Hash]
40
+ def to_payload(config)
41
+ payload = {
42
+ "apiKey" => config.api_key,
43
+ "error" => {
44
+ "message" => @message,
45
+ "stackTrace" => @stack_trace,
46
+ "file" => @file,
47
+ "function" => @function,
48
+ "fingerprint" => @fingerprint
49
+ },
50
+ "environment" => {
51
+ "language" => @environment[:language],
52
+ "languageVersion" => @environment[:language_version],
53
+ "framework" => @environment[:framework].to_s,
54
+ "frameworkVersion" => @environment[:framework_version].to_s,
55
+ "os" => @environment[:os],
56
+ "sdkVersion" => @environment[:sdk_version]
57
+ },
58
+ "timestamp" => @timestamp
59
+ }
60
+
61
+ if @request
62
+ payload["request"] = {
63
+ "route" => @request[:route].to_s,
64
+ "method" => @request[:method].to_s
65
+ }
66
+ end
67
+
68
+ payload["projectId"] = config.project_id unless config.project_id.empty?
69
+
70
+ meta = @metadata.dup
71
+ meta["autoFix"] = true if config.auto_fix
72
+ payload["metadata"] = meta unless meta.empty?
73
+
74
+ payload
75
+ end
76
+
77
+ private
78
+
79
+ def default_environment
80
+ {
81
+ language: "ruby",
82
+ language_version: RUBY_VERSION,
83
+ framework: "",
84
+ framework_version: "",
85
+ os: RUBY_PLATFORM,
86
+ sdk_version: Bugstack::VERSION
87
+ }
88
+ end
89
+ end
90
+ end