Module: Sciosano

Defined in:
lib/sciosano.rb,
lib/sciosano/client.rb,
lib/sciosano/report.rb,
lib/sciosano/context.rb,
lib/sciosano/version.rb,
lib/sciosano/breadcrumb.rb,
lib/sciosano/configuration.rb,
lib/sciosano/integrations/rack.rb,
lib/sciosano/integrations/rails.rb,
lib/sciosano/integrations/sidekiq.rb,
lib/sciosano/integrations/active_job.rb

Defined Under Namespace

Modules: Integrations Classes: Breadcrumb, Client, Configuration, ConfigurationError, Context, Error, Report

Constant Summary collapse

VERSION =
"0.1.0"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.clientObject

Returns the value of attribute client.



31
32
33
# File 'lib/sciosano.rb', line 31

def client
  @client
end

Class Method Details

.add_breadcrumb(category:, message:, data: {}, type: :default) ⇒ Object

Add a breadcrumb

Parameters:

  • category (String)

    Breadcrumb category

  • message (String)

    Breadcrumb message

  • data (Hash) (defaults to: {})

    Additional data

  • type (Symbol) (defaults to: :default)

    Breadcrumb type



92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/sciosano.rb', line 92

def add_breadcrumb(category:, message:, data: {}, type: :default)
  return unless client

  client.add_breadcrumb(
    Breadcrumb.new(
      type: type,
      category: category,
      message: message,
      data: data
    )
  )
end

.capture_exception(exception, context = {}) ⇒ String?

Capture an exception

Examples:

begin
  dangerous_operation
rescue => e
  Sciosano.capture_exception(e, user_id: current_user.id)
end

Parameters:

  • exception (Exception)

    The exception to capture

  • context (Hash) (defaults to: {})

    Additional context

Returns:

  • (String, nil)

    Report ID if successful



68
69
70
71
72
# File 'lib/sciosano.rb', line 68

def capture_exception(exception, context = {})
  return nil unless client

  client.capture_exception(exception, context)
end

.capture_message(message, level: :info, context: {}) ⇒ String?

Capture a message

Parameters:

  • message (String)

    The message to capture

  • level (Symbol) (defaults to: :info)

    Message level (:info, :warning, :error)

  • context (Hash) (defaults to: {})

    Additional context

Returns:

  • (String, nil)

    Report ID if successful



80
81
82
83
84
# File 'lib/sciosano.rb', line 80

def capture_message(message, level: :info, context: {})
  return nil unless client

  client.capture_message(message, level: level, context: context)
end

.clear_userObject

Clear user context



118
119
120
121
122
# File 'lib/sciosano.rb', line 118

def clear_user
  return unless client

  client.clear_user
end

.configurationConfiguration

Get the current configuration

Returns:



52
53
54
# File 'lib/sciosano.rb', line 52

def configuration
  @configuration ||= Configuration.new
end

.configure {|Configuration| ... } ⇒ Object

Configure sciosano

Examples:

Sciosano.configure do |config|
  config.api_key = "sciosano_prod_abc123"
  config.environment = Rails.env
end

Yields:



42
43
44
45
46
47
# File 'lib/sciosano.rb', line 42

def configure
  yield configuration
  self.client = Client.new(configuration)
  setup_integrations
  log_initialization
end

.set_extra(key, value) ⇒ Object

Set extra context

Parameters:

  • key (String, Symbol)

    Context key

  • value (Object)

    Context value



128
129
130
131
132
# File 'lib/sciosano.rb', line 128

def set_extra(key, value)
  return unless client

  client.set_extra(key, value)
end

.set_tags(tags) ⇒ Object

Set tags

Parameters:

  • tags (Hash)

    Tags to set



137
138
139
140
141
# File 'lib/sciosano.rb', line 137

def set_tags(tags)
  return unless client

  client.set_tags(tags)
end

.set_user(id: nil, email: nil, name: nil, **extra) ⇒ Object

Set user context

Parameters:

  • id (String, Integer) (defaults to: nil)

    User ID

  • email (String) (defaults to: nil)

    User email

  • name (String) (defaults to: nil)

    User name

  • extra (Hash)

    Additional user data



111
112
113
114
115
# File 'lib/sciosano.rb', line 111

def set_user(id: nil, email: nil, name: nil, **extra)
  return unless client

  client.set_user(id: id, email: email, name: name, **extra)
end

.verify_installationArray<String>

Verify the installation is working correctly

Returns:

  • (Array<String>)

    List of issues found (empty = all good)



156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# File 'lib/sciosano.rb', line 156

def verify_installation
  issues = []

  unless client
    issues << "Client not initialized - call Sciosano.configure first"
    return issues
  end

  # Check Rails middleware
  if defined?(Rails.application) && Rails.application
    middleware_installed = Rails.application.middleware.any? do |m|
      m.klass == Sciosano::Integrations::RackMiddleware rescue m == Sciosano::Integrations::RackMiddleware
    end
    issues << "Rails middleware not installed" unless middleware_installed
  end

  # Check API key format
  unless configuration.api_key&.start_with?("sciosano_")
    issues << "API key appears invalid (should start with 'sciosano_')"
  end

  issues
end

.with_context(context = {}) { ... } ⇒ Object

Execute block with additional context

Parameters:

  • context (Hash) (defaults to: {})

    Context to add

Yields:

  • Block to execute



147
148
149
150
151
# File 'lib/sciosano.rb', line 147

def with_context(context = {})
  return yield unless client

  client.with_context(context) { yield }
end