sciosano 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.
data/lib/sciosano.rb ADDED
@@ -0,0 +1,213 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "faraday"
4
+ require "concurrent"
5
+ require "json"
6
+ require "securerandom"
7
+ require "socket"
8
+
9
+ require_relative "sciosano/version"
10
+ require_relative "sciosano/configuration"
11
+ require_relative "sciosano/client"
12
+ require_relative "sciosano/context"
13
+ require_relative "sciosano/breadcrumb"
14
+ require_relative "sciosano/report"
15
+
16
+ # Integrations - Rack is always loaded
17
+ require_relative "sciosano/integrations/rack"
18
+
19
+ # Rails integration - load at require time so Railtie initializers register
20
+ # BEFORE Rails runs them. This is critical: if we wait until configure(),
21
+ # Rails has already built the middleware stack and our initializer is missed.
22
+ if defined?(Rails::Railtie)
23
+ require_relative "sciosano/integrations/rails"
24
+ end
25
+
26
+ module Sciosano
27
+ class Error < StandardError; end
28
+ class ConfigurationError < Error; end
29
+
30
+ class << self
31
+ attr_accessor :client
32
+
33
+ # Configure sciosano
34
+ #
35
+ # @example
36
+ # Sciosano.configure do |config|
37
+ # config.api_key = "sciosano_prod_abc123"
38
+ # config.environment = Rails.env
39
+ # end
40
+ #
41
+ # @yield [Configuration] Configuration instance
42
+ def configure
43
+ yield configuration
44
+ self.client = Client.new(configuration)
45
+ setup_integrations
46
+ log_initialization
47
+ end
48
+
49
+ # Get the current configuration
50
+ #
51
+ # @return [Configuration]
52
+ def configuration
53
+ @configuration ||= Configuration.new
54
+ end
55
+
56
+ # Capture an exception
57
+ #
58
+ # @param exception [Exception] The exception to capture
59
+ # @param context [Hash] Additional context
60
+ # @return [String, nil] Report ID if successful
61
+ #
62
+ # @example
63
+ # begin
64
+ # dangerous_operation
65
+ # rescue => e
66
+ # Sciosano.capture_exception(e, user_id: current_user.id)
67
+ # end
68
+ def capture_exception(exception, context = {})
69
+ return nil unless client
70
+
71
+ client.capture_exception(exception, context)
72
+ end
73
+
74
+ # Capture a message
75
+ #
76
+ # @param message [String] The message to capture
77
+ # @param level [Symbol] Message level (:info, :warning, :error)
78
+ # @param context [Hash] Additional context
79
+ # @return [String, nil] Report ID if successful
80
+ def capture_message(message, level: :info, context: {})
81
+ return nil unless client
82
+
83
+ client.capture_message(message, level: level, context: context)
84
+ end
85
+
86
+ # Add a breadcrumb
87
+ #
88
+ # @param category [String] Breadcrumb category
89
+ # @param message [String] Breadcrumb message
90
+ # @param data [Hash] Additional data
91
+ # @param type [Symbol] Breadcrumb type
92
+ def add_breadcrumb(category:, message:, data: {}, type: :default)
93
+ return unless client
94
+
95
+ client.add_breadcrumb(
96
+ Breadcrumb.new(
97
+ type: type,
98
+ category: category,
99
+ message: message,
100
+ data: data
101
+ )
102
+ )
103
+ end
104
+
105
+ # Set user context
106
+ #
107
+ # @param id [String, Integer] User ID
108
+ # @param email [String] User email
109
+ # @param name [String] User name
110
+ # @param extra [Hash] Additional user data
111
+ def set_user(id: nil, email: nil, name: nil, **extra)
112
+ return unless client
113
+
114
+ client.set_user(id: id, email: email, name: name, **extra)
115
+ end
116
+
117
+ # Clear user context
118
+ def clear_user
119
+ return unless client
120
+
121
+ client.clear_user
122
+ end
123
+
124
+ # Set extra context
125
+ #
126
+ # @param key [String, Symbol] Context key
127
+ # @param value [Object] Context value
128
+ def set_extra(key, value)
129
+ return unless client
130
+
131
+ client.set_extra(key, value)
132
+ end
133
+
134
+ # Set tags
135
+ #
136
+ # @param tags [Hash] Tags to set
137
+ def set_tags(tags)
138
+ return unless client
139
+
140
+ client.set_tags(tags)
141
+ end
142
+
143
+ # Execute block with additional context
144
+ #
145
+ # @param context [Hash] Context to add
146
+ # @yield Block to execute
147
+ def with_context(context = {})
148
+ return yield unless client
149
+
150
+ client.with_context(context) { yield }
151
+ end
152
+
153
+ # Verify the installation is working correctly
154
+ #
155
+ # @return [Array<String>] List of issues found (empty = all good)
156
+ def verify_installation
157
+ issues = []
158
+
159
+ unless client
160
+ issues << "Client not initialized - call Sciosano.configure first"
161
+ return issues
162
+ end
163
+
164
+ # Check Rails middleware
165
+ if defined?(Rails.application) && Rails.application
166
+ middleware_installed = Rails.application.middleware.any? do |m|
167
+ m.klass == Sciosano::Integrations::RackMiddleware rescue m == Sciosano::Integrations::RackMiddleware
168
+ end
169
+ issues << "Rails middleware not installed" unless middleware_installed
170
+ end
171
+
172
+ # Check API key format
173
+ unless configuration.api_key&.start_with?("sciosano_")
174
+ issues << "API key appears invalid (should start with 'sciosano_')"
175
+ end
176
+
177
+ issues
178
+ end
179
+
180
+ private
181
+
182
+ def setup_integrations
183
+ # Sidekiq integration - load if Sidekiq is defined and enabled
184
+ if defined?(Sidekiq) && configuration.sidekiq_enabled
185
+ require_relative "sciosano/integrations/sidekiq"
186
+ Sciosano::Integrations::Sidekiq.setup
187
+ end
188
+
189
+ # ActiveJob integration (separate from Rails for standalone use)
190
+ if defined?(ActiveJob) && configuration.active_job_enabled
191
+ require_relative "sciosano/integrations/active_job"
192
+ end
193
+ end
194
+
195
+ def log_initialization
196
+ return unless defined?(Rails.logger) && Rails.logger
197
+
198
+ Rails.logger.info "[Sciosano] Initialized (environment: #{configuration.environment})"
199
+
200
+ # Verify middleware in after_initialize if Rails is present
201
+ if defined?(Rails.application) && Rails.application
202
+ Rails.application.config.after_initialize do
203
+ issues = Sciosano.verify_installation
204
+ if issues.any?
205
+ issues.each { |issue| Rails.logger.warn "[Sciosano] #{issue}" }
206
+ else
207
+ Rails.logger.info "[Sciosano] Middleware installed successfully"
208
+ end
209
+ end
210
+ end
211
+ end
212
+ end
213
+ end
data/sciosano.gemspec ADDED
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/sciosano/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "sciosano"
7
+ spec.version = Sciosano::VERSION
8
+ spec.authors = ["Brightech"]
9
+ spec.email = ["support@brightech.com"]
10
+
11
+ spec.summary = "Error tracking SDK for Ruby and Rails applications"
12
+ spec.description = "Capture and report errors from Ruby and Rails applications to sciosano. Includes Rails middleware, Sidekiq integration, and ActiveJob support."
13
+ spec.homepage = "https://github.com/brightech/sciosano"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = ">= 3.0.0"
16
+
17
+ spec.metadata["homepage_uri"] = spec.homepage
18
+ spec.metadata["source_code_uri"] = "https://github.com/brightech/sciosano"
19
+ spec.metadata["changelog_uri"] = "https://github.com/brightech/sciosano/blob/main/CHANGELOG.md"
20
+
21
+ spec.files = Dir.chdir(__dir__) do
22
+ `git ls-files -z`.split("\x0").reject do |f|
23
+ (File.expand_path(f) == __FILE__) ||
24
+ f.start_with?(*%w[bin/ test/ spec/ features/ .git .github appveyor Gemfile])
25
+ end
26
+ end
27
+
28
+ spec.require_paths = ["lib"]
29
+
30
+ # Runtime dependencies
31
+ spec.add_dependency "faraday", ">= 1.0", "< 3.0"
32
+ spec.add_dependency "concurrent-ruby", "~> 1.0"
33
+
34
+ # Development dependencies
35
+ spec.add_development_dependency "bundler", "~> 2.0"
36
+ spec.add_development_dependency "rake", "~> 13.0"
37
+ spec.add_development_dependency "rspec", "~> 3.0"
38
+ spec.add_development_dependency "rubocop", "~> 1.0"
39
+ spec.add_development_dependency "webmock", "~> 3.0"
40
+ end
metadata ADDED
@@ -0,0 +1,163 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sciosano
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Brightech
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2026-02-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '3.0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '1.0'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '3.0'
33
+ - !ruby/object:Gem::Dependency
34
+ name: concurrent-ruby
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '1.0'
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '1.0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: bundler
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '2.0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '2.0'
61
+ - !ruby/object:Gem::Dependency
62
+ name: rake
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '13.0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '13.0'
75
+ - !ruby/object:Gem::Dependency
76
+ name: rspec
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '3.0'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '3.0'
89
+ - !ruby/object:Gem::Dependency
90
+ name: rubocop
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: '1.0'
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - "~>"
101
+ - !ruby/object:Gem::Version
102
+ version: '1.0'
103
+ - !ruby/object:Gem::Dependency
104
+ name: webmock
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: '3.0'
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - "~>"
115
+ - !ruby/object:Gem::Version
116
+ version: '3.0'
117
+ description: Capture and report errors from Ruby and Rails applications to sciosano.
118
+ Includes Rails middleware, Sidekiq integration, and ActiveJob support.
119
+ email:
120
+ - support@brightech.com
121
+ executables: []
122
+ extensions: []
123
+ extra_rdoc_files: []
124
+ files:
125
+ - lib/sciosano.rb
126
+ - lib/sciosano/breadcrumb.rb
127
+ - lib/sciosano/client.rb
128
+ - lib/sciosano/configuration.rb
129
+ - lib/sciosano/context.rb
130
+ - lib/sciosano/integrations/active_job.rb
131
+ - lib/sciosano/integrations/rack.rb
132
+ - lib/sciosano/integrations/rails.rb
133
+ - lib/sciosano/integrations/sidekiq.rb
134
+ - lib/sciosano/report.rb
135
+ - lib/sciosano/version.rb
136
+ - sciosano.gemspec
137
+ homepage: https://github.com/brightech/sciosano
138
+ licenses:
139
+ - MIT
140
+ metadata:
141
+ homepage_uri: https://github.com/brightech/sciosano
142
+ source_code_uri: https://github.com/brightech/sciosano
143
+ changelog_uri: https://github.com/brightech/sciosano/blob/main/CHANGELOG.md
144
+ post_install_message:
145
+ rdoc_options: []
146
+ require_paths:
147
+ - lib
148
+ required_ruby_version: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: 3.0.0
153
+ required_rubygems_version: !ruby/object:Gem::Requirement
154
+ requirements:
155
+ - - ">="
156
+ - !ruby/object:Gem::Version
157
+ version: '0'
158
+ requirements: []
159
+ rubygems_version: 3.4.19
160
+ signing_key:
161
+ specification_version: 4
162
+ summary: Error tracking SDK for Ruby and Rails applications
163
+ test_files: []