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/sequel.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/cron/slug.rb,
lib/sentry/interface.rb,
lib/sentry/linecache.rb,
lib/sentry/log_event.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/metric_event.rb,
lib/sentry/configuration.rb,
lib/sentry/envelope/item.rb,
lib/sentry/backtrace/line.rb,
lib/sentry/check_in_event.rb,
lib/sentry/std_lib_logger.rb,
lib/sentry/vernier/output.rb,
lib/sentry/data_collection.rb,
lib/sentry/rufus_scheduler.rb,
lib/sentry/session_flusher.rb,
lib/sentry/excon/middleware.rb,
lib/sentry/log_event_buffer.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/structured_logger.rb,
lib/sentry/transaction_event.rb,
lib/sentry/cron/configuration.rb,
lib/sentry/interfaces/request.rb,
lib/sentry/interfaces/threads.rb,
lib/sentry/cron/fugit_schedule.rb,
lib/sentry/cron/monitor_config.rb,
lib/sentry/metric_event_buffer.rb,
lib/sentry/propagation_context.rb,
lib/sentry/backpressure_monitor.rb,
lib/sentry/interfaces/exception.rb,
lib/sentry/interfaces/mechanism.rb,
lib/sentry/cron/monitor_schedule.rb,
lib/sentry/interfaces/stacktrace.rb,
lib/sentry/cron/monitor_check_ins.rb,
lib/sentry/telemetry_event_buffer.rb,
lib/sentry/debug_structured_logger.rb,
lib/sentry/rack/capture_exceptions.rb,
lib/sentry/transport/configuration.rb,
lib/sentry/breadcrumb/sentry_logger.rb,
lib/sentry/job_extensions/extension.rb,
lib/sentry/threaded_periodic_worker.rb,
lib/sentry/transport/http_transport.rb,
lib/sentry/transport/debug_transport.rb,
lib/sentry/transport/dummy_transport.rb,
lib/sentry/interfaces/single_exception.rb,
lib/sentry/interfaces/stacktrace_builder.rb,
lib/sentry/transport/spotlight_transport.rb,
lib/sentry/data_collection/key_value_collection.rb
Defined Under Namespace
Modules: Cron, Excon, Faraday, Integrable, JobExtensions, Metrics, Net, Puma, Rack, Rake, RufusScheduler, Sequel, StdLibLogger, TestHelper, Vernier Classes: Attachment, BackgroundWorker, BackpressureMonitor, Backtrace, Baggage, Breadcrumb, BreadcrumbBuffer, CheckInEvent, Client, Configuration, DSN, DataCollection, DebugLogFile, DebugStructuredLogger, DebugTransport, DummyTransport, Envelope, Error, ErrorEvent, Event, ExceptionInterface, ExternalError, HTTPTransport, Hub, Interface, LineCache, LogEvent, Logger, Mechanism, MetricEvent, Profiler, PropagationContext, Redis, ReleaseDetector, RequestInterface, Scope, Session, SessionFlusher, SingleExceptionInterface, SizeExceededError, Span, SpotlightTransport, StacktraceBuilder, StacktraceInterface, StructuredLogger, StructuredLoggingConfiguration, 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 logger session_flusher backpressure_monitor exception_locals_tp ].freeze
- VERSION =
"7.3.0"
Class Attribute Summary collapse
- .background_worker ⇒ BackgroundWorker
-
.backpressure_monitor ⇒ Object
readonly
Returns the value of attribute backpressure_monitor.
-
.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_feature_flag(name, result) ⇒ void
Records a feature flag evaluation on the current scope and active span.
-
.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_log(message, **options) ⇒ LogEvent?
Captures a log event and sends 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.
- .clear_external_propagation_context ⇒ Object
-
.clone_hub_to_current_thread ⇒ void
Clones the main hub and stores it for the current execution context (the current thread, or the current fiber when
config.hub_isolation_levelis:fiber). -
.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: https://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_external_propagation_context ⇒ Array<String>?
Returns the external propagation context (trace_id, span_id) if a callback is registered.
-
.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.
-
.logger ⇒ StructuredLogger
Returns the structured logger instance that implements Sentry's SDK telemetry logs protocol.
-
.metrics ⇒ Metrics
Returns the metrics API for capturing custom metrics.
-
.register_external_propagation_context(&callback) ⇒ void
Registers a callback function that retrieves the current external propagation context.
-
.register_integration(name, version) ⇒ Object
Registers the SDK integration with its name and version.
- .remove_attribute ⇒ Object
- .send_event ⇒ Object
- .set_attribute ⇒ Object
- .set_attributes ⇒ 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
.background_worker ⇒ BackgroundWorker
90 91 92 |
# File 'lib/sentry-ruby.rb', line 90 def background_worker @background_worker end |
.backpressure_monitor ⇒ Object (readonly)
Returns the value of attribute backpressure_monitor.
98 99 100 |
# File 'lib/sentry-ruby.rb', line 98 def backpressure_monitor @backpressure_monitor end |
.session_flusher ⇒ Object (readonly)
Returns the value of attribute session_flusher.
94 95 96 |
# File 'lib/sentry-ruby.rb', line 94 def session_flusher @session_flusher end |
Class Method Details
.add_attachment ⇒ Object
269 270 271 272 |
# File 'lib/sentry-ruby.rb', line 269 def (**opts) return unless initialized? get_current_scope.(**opts) end |
.add_breadcrumb(breadcrumb, **options) ⇒ Breadcrumb?
Takes an instance of Sentry::Breadcrumb and stores it to the current active scope.
367 368 369 370 |
# File 'lib/sentry-ruby.rb', line 367 def (, **) return unless initialized? get_current_hub.(, **) end |
.add_feature_flag(name, result) ⇒ void
This method returns an undefined value.
Records a feature flag evaluation on the current scope and active span. Only boolean results are recorded.
233 234 235 236 |
# File 'lib/sentry-ruby.rb', line 233 def add_feature_flag(name, result) return unless initialized? get_current_scope.add_feature_flag(name, result) end |
.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.
608 609 610 |
# File 'lib/sentry-ruby.rb', line 608 def add_global_event_processor(&block) Scope.add_global_event_processor(&block) end |
.capture_check_in(slug, status, **options) ⇒ String?
Captures a check-in and sends it to Sentry via the currently active hub.
528 529 530 531 |
# File 'lib/sentry-ruby.rb', line 528 def capture_check_in(slug, status, **) return unless initialized? get_current_hub.capture_check_in(slug, status, **) end |
.capture_event(event) ⇒ Event?
Takes an instance of Sentry::Event and dispatches it to the currently active hub.
512 513 514 515 |
# File 'lib/sentry-ruby.rb', line 512 def capture_event(event) return unless initialized? get_current_hub.capture_event(event) end |
.capture_exception(exception, **options) {|scope| ... } ⇒ Event?
Takes an exception and reports it to Sentry via the currently active hub.
476 477 478 479 |
# File 'lib/sentry-ruby.rb', line 476 def capture_exception(exception, **, &block) return unless initialized? get_current_hub.capture_exception(exception, **, &block) end |
.capture_log(message, **options) ⇒ LogEvent?
Captures a log event and sends it to Sentry via the currently active hub. This is the underlying method used by the StructuredLogger class.
548 549 550 551 |
# File 'lib/sentry-ruby.rb', line 548 def capture_log(, **) return unless initialized? get_current_hub.capture_log_event(, **) end |
.capture_message(message, **options) {|scope| ... } ⇒ Event?
Takes a message string and reports it to Sentry via the currently active hub.
504 505 506 507 |
# File 'lib/sentry-ruby.rb', line 504 def (, **, &block) return unless initialized? get_current_hub.(, **, &block) end |
.clear_external_propagation_context ⇒ Object
733 734 735 |
# File 'lib/sentry-ruby.rb', line 733 def clear_external_propagation_context @external_propagation_context_callback = nil end |
.clone_hub_to_current_thread ⇒ void
This method returns an undefined value.
Clones the main hub and stores it for the current execution context
(the current thread, or the current fiber when config.hub_isolation_level
is :fiber).
406 407 408 409 |
# File 'lib/sentry-ruby.rb', line 406 def clone_hub_to_current_thread return unless initialized? set_current_hub_internal(get_main_hub.clone) end |
.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.
303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 |
# File 'lib/sentry-ruby.rb', line 303 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 client = get_current_client client.configuration.run_after_close_callbacks client.flush client.log_event_buffer.kill client.metric_event_buffer.kill if client.configuration.data_collection.collect_stack_frame_variables? exception_locals_tp.disable end end @background_worker.shutdown MUTEX.synchronize do @main_hub = nil set_current_hub_internal(nil) end end |
.configuration ⇒ Object
170 171 172 173 |
# File 'lib/sentry-ruby.rb', line 170 def configuration return unless initialized? get_current_client.configuration end |
.configure_scope {|scope| ... } ⇒ void
This method returns an undefined value.
Takes a block and yields the current active scope.
422 423 424 425 |
# File 'lib/sentry-ruby.rb', line 422 def configure_scope(&block) return unless initialized? get_current_hub.configure_scope(&block) end |
.continue_trace(env, **options) ⇒ Transaction?
Continue an incoming trace from a rack env like hash.
652 653 654 655 |
# File 'lib/sentry-ruby.rb', line 652 def continue_trace(env, **) return nil unless initialized? get_current_hub.continue_trace(env, **) end |
.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: https://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.
349 350 351 352 |
# File 'lib/sentry-ruby.rb', line 349 def csp_report_uri return unless initialized? configuration.csp_report_uri end |
.exception_captured?(exc) ⇒ Boolean
Checks if the exception object has been captured by the SDK.
590 591 592 593 |
# File 'lib/sentry-ruby.rb', line 590 def exception_captured?(exc) return false unless initialized? !!exc.instance_variable_get(CAPTURED_SIGNATURE) end |
.get_baggage ⇒ String?
Returns the baggage header for distributed tracing. Can be either from the currently active span or the propagation context.
625 626 627 628 |
# File 'lib/sentry-ruby.rb', line 625 def get_baggage return nil unless initialized? get_current_hub.get_baggage end |
.get_current_client ⇒ Client?
Returns the current active client.
388 389 390 391 |
# File 'lib/sentry-ruby.rb', line 388 def get_current_client return unless initialized? get_current_hub.current_client end |
.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.
377 378 379 380 381 382 383 384 |
# File 'lib/sentry-ruby.rb', line 377 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 get_current_hub_internal || clone_hub_to_current_thread end |
.get_current_scope ⇒ Scope?
Returns the current active scope.
396 397 398 399 |
# File 'lib/sentry-ruby.rb', line 396 def get_current_scope return unless initialized? get_current_hub.current_scope end |
.get_external_propagation_context ⇒ Array<String>?
Returns the external propagation context (trace_id, span_id) if a callback is registered.
724 725 726 727 728 729 730 731 |
# File 'lib/sentry-ruby.rb', line 724 def get_external_propagation_context return nil unless @external_propagation_context_callback @external_propagation_context_callback.call rescue => e sdk_logger&.debug(LOGGER_PROGNAME) { "Error getting external propagation context: #{e.}" } if initialized? nil end |
.get_main_hub ⇒ Hub
Returns the main thread's active hub.
357 358 359 360 361 362 |
# File 'lib/sentry-ruby.rb', line 357 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 |
.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.
634 635 636 637 |
# File 'lib/sentry-ruby.rb', line 634 def get_trace_propagation_headers return nil unless initialized? get_current_hub.get_trace_propagation_headers end |
.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.
643 644 645 646 |
# File 'lib/sentry-ruby.rb', line 643 def return "" unless initialized? get_current_hub. end |
.get_traceparent ⇒ String?
Returns the traceparent (sentry-trace) header for distributed tracing. Can be either from the currently active span or the propagation context.
616 617 618 619 |
# File 'lib/sentry-ruby.rb', line 616 def get_traceparent return nil unless initialized? get_current_hub.get_traceparent end |
.init {|config| ... } ⇒ void
This method returns an undefined value.
Initializes the SDK with given configuration.
280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 |
# File 'lib/sentry-ruby.rb', line 280 def init(&block) config = Configuration.new(&block) config.detect_release apply_patches(config) config.validate client = Client.new(config) scope = Scope.new(max_breadcrumbs: config.) hub = Hub.new(client, scope) @hub_isolation_level = config.hub_isolation_level set_current_hub_internal(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 exception_locals_tp.enable if config.data_collection.collect_stack_frame_variables? at_exit { close } end |
.initialized? ⇒ Boolean
Returns true if the SDK is initialized.
337 338 339 |
# File 'lib/sentry-ruby.rb', line 337 def initialized? !!get_main_hub end |
.integrations ⇒ Hash{String=>Hash}
Returns a hash that contains all the integrations that have been registered to the main SDK.
134 135 136 |
# File 'lib/sentry-ruby.rb', line 134 def integrations @integrations ||= {} end |
.last_event_id ⇒ String?
Returns the id of the lastly reported Sentry::Event.
582 583 584 585 |
# File 'lib/sentry-ruby.rb', line 582 def last_event_id return unless initialized? get_current_hub.last_event_id end |
.logger ⇒ StructuredLogger
Returns the structured logger instance that implements Sentry's SDK telemetry logs protocol.
669 670 671 |
# File 'lib/sentry-ruby.rb', line 669 def logger @logger ||= configuration.structured_logging.logger_class.new(configuration) end |
.metrics ⇒ Metrics
Returns the metrics API for capturing custom metrics.
681 682 683 |
# File 'lib/sentry-ruby.rb', line 681 def metrics Metrics end |
.register_external_propagation_context(&callback) ⇒ void
This method returns an undefined value.
Registers a callback function that retrieves the current external propagation context. This is used by OpenTelemetry integration to provide trace_id and span_id from OTel context.
717 718 719 |
# File 'lib/sentry-ruby.rb', line 717 def register_external_propagation_context(&callback) @external_propagation_context_callback = callback end |
.register_integration(name, version) ⇒ Object
Registers the SDK integration with its name and version.
142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/sentry-ruby.rb', line 142 def register_integration(name, version) if initialized? sdk_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 |
.remove_attribute ⇒ Object
262 263 264 265 |
# File 'lib/sentry-ruby.rb', line 262 def remove_attribute(key) return unless initialized? get_current_scope.remove_attribute(key) end |
.send_event ⇒ Object
177 178 179 180 |
# File 'lib/sentry-ruby.rb', line 177 def send_event(*args) return unless initialized? get_current_client.send_event(*args) end |
.set_attribute ⇒ Object
253 254 255 256 |
# File 'lib/sentry-ruby.rb', line 253 def set_attribute(key, value, unit: nil) return unless initialized? get_current_scope.set_attribute(key, value, unit: unit) end |
.set_attributes ⇒ Object
242 243 244 245 |
# File 'lib/sentry-ruby.rb', line 242 def set_attributes(attributes_hash) return unless initialized? get_current_scope.set_attributes(attributes_hash) end |
.set_context ⇒ Object
223 224 225 226 |
# File 'lib/sentry-ruby.rb', line 223 def set_context(*args) return unless initialized? get_current_scope.set_context(*args) end |
.set_extras ⇒ Object
209 210 211 212 |
# File 'lib/sentry-ruby.rb', line 209 def set_extras(*args) return unless initialized? get_current_scope.set_extras(*args) end |
.set_tags ⇒ Object
202 203 204 205 |
# File 'lib/sentry-ruby.rb', line 202 def (*args) return unless initialized? get_current_scope.(*args) end |
.set_user ⇒ Object
216 217 218 219 |
# File 'lib/sentry-ruby.rb', line 216 def set_user(*args) return unless initialized? get_current_scope.set_user(*args) end |
.start_transaction(**options) ⇒ Transaction?
Takes or initializes a new Sentry::Transaction and makes a sampling decision for it.
556 557 558 559 |
# File 'lib/sentry-ruby.rb', line 556 def start_transaction(**) return unless initialized? get_current_hub.start_transaction(**) end |
.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.
574 575 576 577 |
# File 'lib/sentry-ruby.rb', line 574 def with_child_span(**attributes, &block) return yield(nil) unless Sentry.initialized? get_current_hub.with_child_span(**attributes, &block) end |
.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.
493 494 495 496 497 498 |
# File 'lib/sentry-ruby.rb', line 493 def with_exception_captured(**, &block) yield rescue Exception => e capture_exception(e, **) raise end |
.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.
447 448 449 450 |
# File 'lib/sentry-ruby.rb', line 447 def with_scope(&block) return yield unless initialized? get_current_hub.with_scope(&block) end |
.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.
467 468 469 470 |
# File 'lib/sentry-ruby.rb', line 467 def with_session_tracking(&block) return yield unless initialized? get_current_hub.with_session_tracking(&block) end |