Module: Sentry
- Extended by:
- Forwardable
- Defined in:
- lib/sentry/dsn.rb,
lib/sentry/hub.rb,
lib/sentry-ruby.rb,
lib/sentry/puma.rb,
lib/sentry/rake.rb,
lib/sentry/span.rb,
lib/sentry/event.rb,
lib/sentry/redis.rb,
lib/sentry/scope.rb,
lib/sentry/client.rb,
lib/sentry/logger.rb,
lib/sentry/baggage.rb,
lib/sentry/faraday.rb,
lib/sentry/metrics.rb,
lib/sentry/session.rb,
lib/sentry/version.rb,
lib/sentry/envelope.rb,
lib/sentry/net/http.rb,
lib/sentry/profiler.rb,
lib/sentry/backtrace.rb,
lib/sentry/interface.rb,
lib/sentry/linecache.rb,
lib/sentry/transport.rb,
lib/sentry/attachment.rb,
lib/sentry/breadcrumb.rb,
lib/sentry/exceptions.rb,
lib/sentry/integrable.rb,
lib/sentry/error_event.rb,
lib/sentry/test_helper.rb,
lib/sentry/transaction.rb,
lib/sentry/configuration.rb,
lib/sentry/envelope/item.rb,
lib/sentry/check_in_event.rb,
lib/sentry/metrics/metric.rb,
lib/sentry/metrics/timing.rb,
lib/sentry/vernier/output.rb,
lib/sentry/session_flusher.rb,
lib/sentry/excon/middleware.rb,
lib/sentry/profiler/helpers.rb,
lib/sentry/release_detector.rb,
lib/sentry/vernier/profiler.rb,
lib/sentry/background_worker.rb,
lib/sentry/breadcrumb_buffer.rb,
lib/sentry/transaction_event.rb,
lib/sentry/cron/configuration.rb,
lib/sentry/interfaces/request.rb,
lib/sentry/interfaces/threads.rb,
lib/sentry/metrics/aggregator.rb,
lib/sentry/metrics/set_metric.rb,
lib/sentry/cron/monitor_config.rb,
lib/sentry/propagation_context.rb,
lib/sentry/backpressure_monitor.rb,
lib/sentry/interfaces/exception.rb,
lib/sentry/interfaces/mechanism.rb,
lib/sentry/metrics/gauge_metric.rb,
lib/sentry/cron/monitor_schedule.rb,
lib/sentry/interfaces/stacktrace.rb,
lib/sentry/metrics/configuration.rb,
lib/sentry/cron/monitor_check_ins.rb,
lib/sentry/metrics/counter_metric.rb,
lib/sentry/rack/capture_exceptions.rb,
lib/sentry/transport/configuration.rb,
lib/sentry/breadcrumb/sentry_logger.rb,
lib/sentry/metrics/local_aggregator.rb,
lib/sentry/threaded_periodic_worker.rb,
lib/sentry/transport/http_transport.rb,
lib/sentry/transport/dummy_transport.rb,
lib/sentry/interfaces/single_exception.rb,
lib/sentry/metrics/distribution_metric.rb,
lib/sentry/interfaces/stacktrace_builder.rb,
lib/sentry/transport/spotlight_transport.rb more...
Defined Under Namespace
Modules: Cron, Excon, Faraday, Integrable, Metrics, Net, Puma, Rack, Rake, TestHelper, Vernier Classes: Attachment, BackgroundWorker, BackpressureMonitor, Backtrace, Baggage, Breadcrumb, BreadcrumbBuffer, CheckInEvent, Client, Configuration, DSN, DummyTransport, Envelope, Error, ErrorEvent, Event, ExceptionInterface, ExternalError, HTTPTransport, Hub, Interface, LineCache, Logger, Mechanism, Profiler, PropagationContext, Redis, ReleaseDetector, RequestInterface, Scope, Session, SessionFlusher, SingleExceptionInterface, Span, SpotlightTransport, StacktraceBuilder, StacktraceInterface, ThreadedPeriodicWorker, ThreadsInterface, Transaction, TransactionEvent, Transport
Constant Summary collapse
- META =
{ "name" => "sentry.ruby", "version" => Sentry::VERSION }.freeze
- CAPTURED_SIGNATURE =
:@__sentry_captured
- LOGGER_PROGNAME =
"sentry"
- SENTRY_TRACE_HEADER_NAME =
"sentry-trace"
- BAGGAGE_HEADER_NAME =
"baggage"
- THREAD_LOCAL =
:sentry_hub
- MUTEX =
Mutex.new
- GLOBALS =
%i[ main_hub session_flusher backpressure_monitor metrics_aggregator exception_locals_tp ].freeze
- VERSION =
"5.23.0"
Class Attribute Summary collapse
- .background_worker ⇒ BackgroundWorker
-
.backpressure_monitor ⇒ Object
readonly
Returns the value of attribute backpressure_monitor.
-
.metrics_aggregator ⇒ Object
readonly
Returns the value of attribute metrics_aggregator.
-
.session_flusher ⇒ Object
readonly
Returns the value of attribute session_flusher.
Class Method Summary collapse
- .add_attachment ⇒ Object
-
.add_breadcrumb(breadcrumb, **options) ⇒ Breadcrumb?
Takes an instance of Sentry::Breadcrumb and stores it to the current active scope.
-
.add_global_event_processor {|event, hint| ... } ⇒ void
Add a global event processor [Proc].
-
.capture_check_in(slug, status, **options) ⇒ String?
Captures a check-in and sends it to Sentry via the currently active hub.
-
.capture_event(event) ⇒ Event?
Takes an instance of Sentry::Event and dispatches it to the currently active hub.
-
.capture_exception(exception, **options) {|scope| ... } ⇒ Event?
Takes an exception and reports it to Sentry via the currently active hub.
-
.capture_message(message, **options) {|scope| ... } ⇒ Event?
Takes a message string and reports it to Sentry via the currently active hub.
-
.clone_hub_to_current_thread ⇒ void
Clones the main thread’s active hub and stores it to the current thread.
-
.close ⇒ void
Flushes pending events and cleans up SDK state.
- .configuration ⇒ Object
-
.configure_scope {|scope| ... } ⇒ void
Takes a block and yields the current active scope.
-
.continue_trace(env, **options) ⇒ Transaction?
Continue an incoming trace from a rack env like hash.
-
.csp_report_uri ⇒ String?
Returns an uri for security policy reporting that’s generated from the given DSN (To learn more about security policy reporting: docs.sentry.io/product/security-policy-reporting/).
-
.exception_captured?(exc) ⇒ Boolean
Checks if the exception object has been captured by the SDK.
-
.get_baggage ⇒ String?
Returns the baggage header for distributed tracing.
-
.get_current_client ⇒ Client?
Returns the current active client.
-
.get_current_hub ⇒ Hub
Returns the current active hub.
-
.get_current_scope ⇒ Scope?
Returns the current active scope.
-
.get_main_hub ⇒ Hub
Returns the main thread’s active hub.
-
.get_trace_propagation_headers ⇒ Hash?
Returns the a Hash containing sentry-trace and baggage.
-
.get_trace_propagation_meta ⇒ String
Returns the a Hash containing sentry-trace and baggage.
-
.get_traceparent ⇒ String?
Returns the traceparent (sentry-trace) header for distributed tracing.
-
.init {|config| ... } ⇒ void
Initializes the SDK with given configuration.
-
.initialized? ⇒ Boolean
Returns true if the SDK is initialized.
-
.integrations ⇒ Hash{String=>Hash}
Returns a hash that contains all the integrations that have been registered to the main SDK.
-
.last_event_id ⇒ String?
Returns the id of the lastly reported Sentry::Event.
-
.register_integration(name, version) ⇒ Object
Registers the SDK integration with its name and version.
- .send_event ⇒ Object
- .set_context ⇒ Object
- .set_extras ⇒ Object
- .set_tags ⇒ Object
- .set_user ⇒ Object
-
.start_transaction(**options) ⇒ Transaction?
Takes or initializes a new Sentry::Transaction and makes a sampling decision for it.
-
.with_child_span(**attributes) {|child_span| ... } ⇒ Object
Records the block’s execution as a child of the current span.
-
.with_exception_captured(**options, &block) ⇒ Object
Takes a block and evaluates it.
-
.with_scope {|scope| ... } ⇒ void
Takes a block and yields a temporary scope.
-
.with_session_tracking(&block) ⇒ void
Wrap a given block with session tracking.
Class Attribute Details
permalink .background_worker ⇒ BackgroundWorker
83 84 85 |
# File 'lib/sentry-ruby.rb', line 83 def background_worker @background_worker end |
permalink .backpressure_monitor ⇒ Object (readonly)
Returns the value of attribute backpressure_monitor.
91 92 93 |
# File 'lib/sentry-ruby.rb', line 91 def backpressure_monitor @backpressure_monitor end |
permalink .metrics_aggregator ⇒ Object (readonly)
Returns the value of attribute metrics_aggregator.
95 96 97 |
# File 'lib/sentry-ruby.rb', line 95 def metrics_aggregator @metrics_aggregator end |
permalink .session_flusher ⇒ Object (readonly)
Returns the value of attribute session_flusher.
87 88 89 |
# File 'lib/sentry-ruby.rb', line 87 def session_flusher @session_flusher end |
Class Method Details
permalink .add_attachment ⇒ Object
[View source]
227 228 229 230 |
# File 'lib/sentry-ruby.rb', line 227 def (**opts) return unless initialized? get_current_scope.(**opts) end |
permalink .add_breadcrumb(breadcrumb, **options) ⇒ Breadcrumb?
Takes an instance of Sentry::Breadcrumb and stores it to the current active scope.
328 329 330 331 |
# File 'lib/sentry-ruby.rb', line 328 def (, **) return unless initialized? get_current_hub.(, **) end |
permalink .add_global_event_processor {|event, hint| ... } ⇒ void
This method returns an undefined value.
Add a global event processor [Proc]. These run before scope event processors.
547 548 549 |
# File 'lib/sentry-ruby.rb', line 547 def add_global_event_processor(&block) Scope.add_global_event_processor(&block) end |
permalink .capture_check_in(slug, status, **options) ⇒ String?
Captures a check-in and sends it to Sentry via the currently active hub.
487 488 489 490 |
# File 'lib/sentry-ruby.rb', line 487 def capture_check_in(slug, status, **) return unless initialized? get_current_hub.capture_check_in(slug, status, **) end |
permalink .capture_event(event) ⇒ Event?
Takes an instance of Sentry::Event and dispatches it to the currently active hub.
471 472 473 474 |
# File 'lib/sentry-ruby.rb', line 471 def capture_event(event) return unless initialized? get_current_hub.capture_event(event) end |
permalink .capture_exception(exception, **options) {|scope| ... } ⇒ Event?
Takes an exception and reports it to Sentry via the currently active hub.
435 436 437 438 |
# File 'lib/sentry-ruby.rb', line 435 def capture_exception(exception, **, &block) return unless initialized? get_current_hub.capture_exception(exception, **, &block) end |
permalink .capture_message(message, **options) {|scope| ... } ⇒ Event?
Takes a message string and reports it to Sentry via the currently active hub.
463 464 465 466 |
# File 'lib/sentry-ruby.rb', line 463 def (, **, &block) return unless initialized? get_current_hub.(, **, &block) end |
permalink .clone_hub_to_current_thread ⇒ void
This method returns an undefined value.
Clones the main thread’s active hub and stores it to the current thread.
365 366 367 368 |
# File 'lib/sentry-ruby.rb', line 365 def clone_hub_to_current_thread return unless initialized? Thread.current.thread_variable_set(THREAD_LOCAL, get_main_hub.clone) end |
permalink .close ⇒ void
This method returns an undefined value.
Flushes pending events and cleans up SDK state. SDK will stop sending events and all top-level APIs will be no-ops after this.
261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 |
# File 'lib/sentry-ruby.rb', line 261 def close if @session_flusher @session_flusher.flush @session_flusher.kill @session_flusher = nil end if @backpressure_monitor @backpressure_monitor.kill @backpressure_monitor = nil end if @metrics_aggregator @metrics_aggregator.flush(force: true) @metrics_aggregator.kill @metrics_aggregator = nil end if client = get_current_client client.flush if client.configuration.include_local_variables exception_locals_tp.disable end end @background_worker.shutdown MUTEX.synchronize do @main_hub = nil Thread.current.thread_variable_set(THREAD_LOCAL, nil) end end |
permalink .configuration ⇒ Object
[View source]
167 168 169 170 |
# File 'lib/sentry-ruby.rb', line 167 def configuration return unless initialized? get_current_client.configuration end |
permalink .configure_scope {|scope| ... } ⇒ void
This method returns an undefined value.
Takes a block and yields the current active scope.
381 382 383 384 |
# File 'lib/sentry-ruby.rb', line 381 def configure_scope(&block) return unless initialized? get_current_hub.configure_scope(&block) end |
permalink .continue_trace(env, **options) ⇒ Transaction?
Continue an incoming trace from a rack env like hash.
591 592 593 594 |
# File 'lib/sentry-ruby.rb', line 591 def continue_trace(env, **) return nil unless initialized? get_current_hub.continue_trace(env, **) end |
permalink .csp_report_uri ⇒ String?
Returns an uri for security policy reporting that’s generated from the given DSN (To learn more about security policy reporting: docs.sentry.io/product/security-policy-reporting/)
It returns nil if
-
The SDK is not initialized yet.
-
The DSN is not provided or is invalid.
310 311 312 313 |
# File 'lib/sentry-ruby.rb', line 310 def csp_report_uri return unless initialized? configuration.csp_report_uri end |
permalink .exception_captured?(exc) ⇒ Boolean
Checks if the exception object has been captured by the SDK.
529 530 531 532 |
# File 'lib/sentry-ruby.rb', line 529 def exception_captured?(exc) return false unless initialized? !!exc.instance_variable_get(CAPTURED_SIGNATURE) end |
permalink .get_baggage ⇒ String?
Returns the baggage header for distributed tracing. Can be either from the currently active span or the propagation context.
564 565 566 567 |
# File 'lib/sentry-ruby.rb', line 564 def get_baggage return nil unless initialized? get_current_hub.get_baggage end |
permalink .get_current_client ⇒ Client?
Returns the current active client.
349 350 351 352 |
# File 'lib/sentry-ruby.rb', line 349 def get_current_client return unless initialized? get_current_hub.current_client end |
permalink .get_current_hub ⇒ Hub
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.
338 339 340 341 342 343 344 345 |
# File 'lib/sentry-ruby.rb', line 338 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_variable_get(THREAD_LOCAL) || clone_hub_to_current_thread end |
permalink .get_current_scope ⇒ Scope?
Returns the current active scope.
357 358 359 360 |
# File 'lib/sentry-ruby.rb', line 357 def get_current_scope return unless initialized? get_current_hub.current_scope end |
permalink .get_main_hub ⇒ Hub
Returns the main thread’s active hub.
318 319 320 321 322 323 |
# File 'lib/sentry-ruby.rb', line 318 def get_main_hub MUTEX.synchronize { @main_hub } rescue ThreadError # In some rare cases this may be called in a trap context so we need to handle it gracefully @main_hub end |
permalink .get_trace_propagation_headers ⇒ Hash?
Returns the a Hash containing sentry-trace and baggage. Can be either from the currently active span or the propagation context.
573 574 575 576 |
# File 'lib/sentry-ruby.rb', line 573 def get_trace_propagation_headers return nil unless initialized? get_current_hub.get_trace_propagation_headers end |
permalink .get_trace_propagation_meta ⇒ String
Returns the a Hash containing sentry-trace and baggage. Can be either from the currently active span or the propagation context.
582 583 584 585 |
# File 'lib/sentry-ruby.rb', line 582 def return "" unless initialized? get_current_hub. end |
permalink .get_traceparent ⇒ String?
Returns the traceparent (sentry-trace) header for distributed tracing. Can be either from the currently active span or the propagation context.
555 556 557 558 |
# File 'lib/sentry-ruby.rb', line 555 def get_traceparent return nil unless initialized? get_current_hub.get_traceparent end |
permalink .init {|config| ... } ⇒ void
This method returns an undefined value.
Initializes the SDK with given configuration.
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 |
# File 'lib/sentry-ruby.rb', line 238 def init(&block) config = Configuration.new yield(config) if block_given? config.detect_release apply_patches(config) config.validate client = Client.new(config) scope = Scope.new(max_breadcrumbs: config.) hub = Hub.new(client, scope) Thread.current.thread_variable_set(THREAD_LOCAL, hub) @main_hub = hub @background_worker = Sentry::BackgroundWorker.new(config) @session_flusher = config.session_tracking? ? Sentry::SessionFlusher.new(config, client) : nil @backpressure_monitor = config.enable_backpressure_handling ? Sentry::BackpressureMonitor.new(config, client) : nil @metrics_aggregator = config.metrics.enabled ? Sentry::Metrics::Aggregator.new(config, client) : nil exception_locals_tp.enable if config.include_local_variables at_exit { close } end |
permalink .initialized? ⇒ Boolean
Returns true if the SDK is initialized.
298 299 300 |
# File 'lib/sentry-ruby.rb', line 298 def initialized? !!get_main_hub end |
permalink .integrations ⇒ Hash{String=>Hash}
Returns a hash that contains all the integrations that have been registered to the main SDK.
131 132 133 |
# File 'lib/sentry-ruby.rb', line 131 def integrations @integrations ||= {} end |
permalink .last_event_id ⇒ String?
Returns the id of the lastly reported Sentry::Event.
521 522 523 524 |
# File 'lib/sentry-ruby.rb', line 521 def last_event_id return unless initialized? get_current_hub.last_event_id end |
permalink .register_integration(name, version) ⇒ Object
Registers the SDK integration with its name and version.
139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/sentry-ruby.rb', line 139 def register_integration(name, version) if initialized? logger.warn(LOGGER_PROGNAME) do <<~MSG Integration '#{name}' is loaded after the SDK is initialized, which can cause unexpected behavior. Please make sure all integrations are loaded before SDK initialization. MSG end end = { name: "sentry.ruby.#{name}", version: version }.freeze integrations[name.to_s] = end |
permalink .send_event ⇒ Object
[View source]
174 175 176 177 |
# File 'lib/sentry-ruby.rb', line 174 def send_event(*args) return unless initialized? get_current_client.send_event(*args) end |
permalink .set_context ⇒ Object
[View source]
220 221 222 223 |
# File 'lib/sentry-ruby.rb', line 220 def set_context(*args) return unless initialized? get_current_scope.set_context(*args) end |
permalink .set_extras ⇒ Object
[View source]
206 207 208 209 |
# File 'lib/sentry-ruby.rb', line 206 def set_extras(*args) return unless initialized? get_current_scope.set_extras(*args) end |
permalink .set_tags ⇒ Object
[View source]
199 200 201 202 |
# File 'lib/sentry-ruby.rb', line 199 def (*args) return unless initialized? get_current_scope.(*args) end |
permalink .set_user ⇒ Object
[View source]
213 214 215 216 |
# File 'lib/sentry-ruby.rb', line 213 def set_user(*args) return unless initialized? get_current_scope.set_user(*args) end |
permalink .start_transaction(**options) ⇒ Transaction?
Takes or initializes a new Sentry::Transaction and makes a sampling decision for it.
495 496 497 498 |
# File 'lib/sentry-ruby.rb', line 495 def start_transaction(**) return unless initialized? get_current_hub.start_transaction(**) end |
permalink .with_child_span(**attributes) {|child_span| ... } ⇒ Object
Records the block’s execution as a child of the current span. If the current scope doesn’t have a span, the block would still be executed but the yield param will be nil.
513 514 515 516 |
# File 'lib/sentry-ruby.rb', line 513 def with_child_span(**attributes, &block) return yield(nil) unless Sentry.initialized? get_current_hub.with_child_span(**attributes, &block) end |
permalink .with_exception_captured(**options, &block) ⇒ Object
Takes a block and evaluates it. If the block raised an exception, it reports the exception to Sentry and re-raises it. If the block ran without exception, it returns the evaluation result.
452 453 454 455 456 457 |
# File 'lib/sentry-ruby.rb', line 452 def with_exception_captured(**, &block) yield rescue Exception => e capture_exception(e, **) raise end |
permalink .with_scope {|scope| ... } ⇒ void
This method returns an undefined value.
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.
406 407 408 409 |
# File 'lib/sentry-ruby.rb', line 406 def with_scope(&block) return yield unless initialized? get_current_hub.with_scope(&block) end |
permalink .with_session_tracking(&block) ⇒ void
This method returns an undefined value.
Wrap a given block with session tracking. Aggregate sessions in minutely buckets will be recorded around this block and flushed every minute.
426 427 428 429 |
# File 'lib/sentry-ruby.rb', line 426 def with_session_tracking(&block) return yield unless initialized? get_current_hub.with_session_tracking(&block) end |