Module: Sentry
- Extended by:
- Forwardable
- Defined in:
- lib/sentry/backtrace.rb,
lib/sentry/dsn.rb,
lib/sentry/hub.rb,
lib/sentry-ruby.rb,
lib/sentry/span.rb,
lib/sentry/event.rb,
lib/sentry/scope.rb,
lib/sentry/client.rb,
lib/sentry/logger.rb,
lib/sentry/version.rb,
lib/sentry/interface.rb,
lib/sentry/linecache.rb,
lib/sentry/transport.rb,
lib/sentry/breadcrumb.rb,
lib/sentry/integrable.rb,
lib/sentry/transaction.rb,
lib/sentry/configuration.rb,
lib/sentry/utils/real_ip.rb,
lib/sentry/utils/request_id.rb,
lib/sentry/background_worker.rb,
lib/sentry/breadcrumb_buffer.rb,
lib/sentry/rack/deprecations.rb,
lib/sentry/transaction_event.rb,
lib/sentry/interfaces/request.rb,
lib/sentry/interfaces/threads.rb,
lib/sentry/interfaces/exception.rb,
lib/sentry/interfaces/stacktrace.rb,
lib/sentry/rack/capture_exceptions.rb,
lib/sentry/transport/configuration.rb,
lib/sentry/breadcrumb/sentry_logger.rb,
lib/sentry/transport/http_transport.rb,
lib/sentry/transport/dummy_transport.rb,
lib/sentry/interfaces/single_exception.rb,
lib/sentry/utils/exception_cause_chain.rb,
lib/sentry/benchmarks/benchmark_transport.rb,
lib/sentry/utils/argument_checking_helper.rb
Overview
Based on ActionDispatch::RemoteIp. All security-related precautions from that middleware have been removed, because the Event IP just needs to be accurate, and spoofing an IP here only makes data inaccurate, not insecure. Don’t re-use this module if you have to trust the IP address.
Defined Under Namespace
Modules: ArgumentCheckingHelper, Integrable, Rack, Utils Classes: BackgroundWorker, Backtrace, BenchmarkTransport, Breadcrumb, BreadcrumbBuffer, Client, Configuration, DSN, DummyTransport, Error, Event, ExceptionInterface, HTTPTransport, Hub, Interface, LineCache, Logger, RequestInterface, Scope, SingleExceptionInterface, Span, StacktraceInterface, ThreadsInterface, Transaction, TransactionEvent, Transport
Constant Summary collapse
- META =
{ "name" => "sentry.ruby", "version" => Sentry::VERSION }.freeze
- LOGGER_PROGNAME =
"sentry".freeze
- THREAD_LOCAL =
:sentry_hub- VERSION =
"4.2.2"
Class Attribute Summary collapse
-
.background_worker ⇒ Object
Returns the value of attribute background_worker.
Class Method Summary collapse
-
.add_breadcrumb(breadcrumb) ⇒ Object
Takes an instance of Sentry::Breadcrumb and stores it to the current active scope.
-
.capture_event(event) ⇒ Object
Takes an instance of Sentry::Event and dispatches it to the currently active hub.
-
.capture_exception(exception, **options, &block) ⇒ Object
Takes an exception and reports it to Sentry via the currently active hub.
-
.capture_message(message, **options, &block) ⇒ Object
Takes a message string and reports it to Sentry via the currently active hub.
-
.clone_hub_to_current_thread ⇒ Object
Clones the main thread’s active hub and stores it to the current thread.
-
.configure_scope(&block) ⇒ Object
Takes a block and yields the current active scope.
-
.get_current_client ⇒ Object
Returns the current active client.
-
.get_current_hub ⇒ Object
Returns the current active hub.
-
.get_current_scope ⇒ Object
Returns the current active scope.
-
.get_main_hub ⇒ Object
Returns the main thread’s active hub.
- .init {|config| ... } ⇒ Object
- .initialized? ⇒ Boolean
-
.integrations ⇒ Object
Returns a hash that contains all the integrations that have been registered to the main SDK.
-
.last_event_id ⇒ Object
Returns the id of the lastly reported Sentry::Event.
- .logger ⇒ Object
-
.register_integration(name, version) ⇒ Object
Registers the SDK integration with its name and version.
- .sdk_meta ⇒ Object
-
.start_transaction(**options) ⇒ Object
Takes or initializes a new Sentry::Transaction and makes a sampling decision for it.
- .sys_command(command) ⇒ Object
- .utc_now ⇒ Object
-
.with_scope(&block) ⇒ Object
Takes a block and yields a temporary scope.
Class Attribute Details
.background_worker ⇒ Object
Returns the value of attribute background_worker.
65 66 67 |
# File 'lib/sentry-ruby.rb', line 65 def background_worker @background_worker end |
Class Method Details
.add_breadcrumb(breadcrumb) ⇒ Object
Takes an instance of Sentry::Breadcrumb and stores it to the current active scope.
84 85 86 |
# File 'lib/sentry-ruby.rb', line 84 def () get_current_scope..record() end |
.capture_event(event) ⇒ Object
Takes an instance of Sentry::Event and dispatches it to the currently active hub.
163 164 165 |
# File 'lib/sentry-ruby.rb', line 163 def capture_event(event) get_current_hub&.capture_event(event) end |
.capture_exception(exception, **options, &block) ⇒ Object
Takes an exception and reports it to Sentry via the currently active hub.
153 154 155 |
# File 'lib/sentry-ruby.rb', line 153 def capture_exception(exception, **, &block) get_current_hub&.capture_exception(exception, **, &block) end |
.capture_message(message, **options, &block) ⇒ Object
Takes a message string and reports it to Sentry via the currently active hub.
158 159 160 |
# File 'lib/sentry-ruby.rb', line 158 def (, **, &block) get_current_hub&.(, **, &block) end |
.clone_hub_to_current_thread ⇒ Object
Clones the main thread’s active hub and stores it to the current thread.
111 112 113 |
# File 'lib/sentry-ruby.rb', line 111 def clone_hub_to_current_thread Thread.current[THREAD_LOCAL] = get_main_hub.clone end |
.configure_scope(&block) ⇒ Object
Takes a block and yields the current active scope.
“‘ruby Sentry.configure_scope do |scope|
scope.(foo: "bar")
end
Sentry.capture_message(“test message”) # this event will have tags { foo: “bar” } “‘
125 126 127 |
# File 'lib/sentry-ruby.rb', line 125 def configure_scope(&block) get_current_hub&.configure_scope(&block) end |
.get_current_client ⇒ Object
Returns the current active client.
101 102 103 |
# File 'lib/sentry-ruby.rb', line 101 def get_current_client get_current_hub&.current_client end |
.get_current_hub ⇒ Object
Returns the current active hub. If the current thread doesn’t have an active hub, it will clone the main thread’s active hub, stores it in the current thread, and then returns it.
91 92 93 94 95 96 97 98 |
# File 'lib/sentry-ruby.rb', line 91 def get_current_hub # we need to assign a hub to the current thread if it doesn't have one yet # # ideally, we should do this proactively whenever a new thread is created # but it's impossible for the SDK to keep track every new thread # so we need to use this rather passive way to make sure the app doesn't crash Thread.current[THREAD_LOCAL] || clone_hub_to_current_thread end |
.get_current_scope ⇒ Object
Returns the current active scope.
106 107 108 |
# File 'lib/sentry-ruby.rb', line 106 def get_current_scope get_current_hub&.current_scope end |
.get_main_hub ⇒ Object
Returns the main thread’s active hub.
79 80 81 |
# File 'lib/sentry-ruby.rb', line 79 def get_main_hub @main_hub end |
.init {|config| ... } ⇒ Object
67 68 69 70 71 72 73 74 75 76 |
# File 'lib/sentry-ruby.rb', line 67 def init(&block) config = Configuration.new yield(config) if block_given? client = Client.new(config) scope = Scope.new hub = Hub.new(client, scope) Thread.current[THREAD_LOCAL] = hub @main_hub = hub @background_worker = Sentry::BackgroundWorker.new(config) end |
.initialized? ⇒ Boolean
184 185 186 |
# File 'lib/sentry-ruby.rb', line 184 def initialized? !!@main_hub end |
.integrations ⇒ Object
Returns a hash that contains all the integrations that have been registered to the main SDK.
48 49 50 |
# File 'lib/sentry-ruby.rb', line 48 def integrations @integrations ||= {} end |
.last_event_id ⇒ Object
Returns the id of the lastly reported Sentry::Event.
173 174 175 |
# File 'lib/sentry-ruby.rb', line 173 def last_event_id get_current_hub&.last_event_id end |
.logger ⇒ Object
188 189 190 |
# File 'lib/sentry-ruby.rb', line 188 def logger configuration.logger end |
.register_integration(name, version) ⇒ Object
Registers the SDK integration with its name and version.
53 54 55 56 |
# File 'lib/sentry-ruby.rb', line 53 def register_integration(name, version) = { name: "sentry.ruby.#{name}", version: version }.freeze integrations[name.to_s] = end |
.start_transaction(**options) ⇒ Object
Takes or initializes a new Sentry::Transaction and makes a sampling decision for it.
168 169 170 |
# File 'lib/sentry-ruby.rb', line 168 def start_transaction(**) get_current_hub&.start_transaction(**) end |
.sys_command(command) ⇒ Object
177 178 179 180 181 182 |
# File 'lib/sentry-ruby.rb', line 177 def sys_command(command) result = `#{command} 2>&1` rescue nil return if result.nil? || result.empty? || ($CHILD_STATUS && $CHILD_STATUS.exitstatus != 0) result.strip end |
.utc_now ⇒ Object
42 43 44 |
# File 'lib/sentry-ruby.rb', line 42 def self.utc_now Time.now.utc end |
.with_scope(&block) ⇒ Object
Takes a block and yields a temporary scope. The temporary scope will inherit all the attributes from the current active scope and replace it to be the active scope inside the block. For example:
“‘ruby Sentry.configure_scope do |scope|
scope.(foo: "bar")
end
Sentry.capture_message(“test message”) # this event will have tags { foo: “bar” }
Sentry.with_scope do |temp_scope|
temp_scope.(foo: "baz")
Sentry.("test message 2") # this event will have tags { foo: "baz" }
end
Sentry.capture_message(“test message 3”) # this event will have tags { foo: “bar” } “‘
148 149 150 |
# File 'lib/sentry-ruby.rb', line 148 def with_scope(&block) get_current_hub&.with_scope(&block) end |