Module: Gitlab::ErrorTracking

Defined in:
lib/gitlab/error_tracking.rb,
lib/gitlab/error_tracking/repo.rb,
lib/gitlab/error_tracking/error.rb,
lib/gitlab/error_tracking/logger.rb,
lib/gitlab/error_tracking/project.rb,
lib/gitlab/error_tracking/error_event.rb,
lib/gitlab/error_tracking/log_formatter.rb,
lib/gitlab/error_tracking/detailed_error.rb,
lib/gitlab/error_tracking/error_collection.rb,
lib/gitlab/error_tracking/error_repository.rb,
lib/gitlab/error_tracking/context_payload_generator.rb,
lib/gitlab/error_tracking/processor/sidekiq_processor.rb,
lib/gitlab/error_tracking/processor/sanitizer_processor.rb,
lib/gitlab/error_tracking/processor/grpc_error_processor.rb,
lib/gitlab/error_tracking/stack_trace_highlight_decorator.rb,
lib/gitlab/error_tracking/error_repository/open_api_strategy.rb,
lib/gitlab/error_tracking/processor/context_payload_processor.rb,
lib/gitlab/error_tracking/processor/concerns/processes_exceptions.rb,
lib/gitlab/error_tracking/processor/sanitize_error_message_processor.rb

Defined Under Namespace

Modules: Processor, StackTraceHighlightDecorator Classes: ContextPayloadGenerator, DetailedError, Error, ErrorCollection, ErrorEvent, ErrorRepository, LogFormatter, Logger, Project, Repo

Constant Summary collapse

CUSTOM_FINGERPRINTING =

Exceptions in this group will receive custom Sentry fingerprinting

%w[
  Acme::Client::Error::BadNonce
  Acme::Client::Error::NotFound
  Acme::Client::Error::RateLimited
  Acme::Client::Error::Timeout
  Acme::Client::Error::UnsupportedOperation
  ActiveRecord::ConnectionTimeoutError
  Gitlab::RequestContext::RequestDeadlineExceeded
  GRPC::DeadlineExceeded
  JIRA::HTTPError
  Rack::Timeout::RequestTimeoutException
].freeze
PROCESSORS =
[
  ::Gitlab::ErrorTracking::Processor::SidekiqProcessor,
  ::Gitlab::ErrorTracking::Processor::GrpcErrorProcessor,
  ::Gitlab::ErrorTracking::Processor::ContextPayloadProcessor,
  ::Gitlab::ErrorTracking::Processor::SanitizeErrorMessageProcessor,
  # IMPORTANT: this processor must stay at the bottom, right before
  # sending the event to Sentry.
  ::Gitlab::ErrorTracking::Processor::SanitizerProcessor
].freeze

Class Method Summary collapse

Class Method Details

.configure(&block) ⇒ Object



30
31
32
33
# File 'lib/gitlab/error_tracking.rb', line 30

def configure(&block)
  configure_raven(&block)
  configure_sentry(&block)
end

.configure_ravenObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/gitlab/error_tracking.rb', line 35

def configure_raven
  Raven.configure do |config|
    config.dsn = sentry_dsn
    config.release = Gitlab.revision
    config.current_environment = Gitlab.config.sentry.environment

    # Sanitize fields based on those sanitized from Rails.
    config.sanitize_fields = Rails.application.config.filter_parameters.map(&:to_s)

    # Sanitize authentication headers
    config.sanitize_http_headers = %w[Authorization Private-Token]
    config.before_send = method(:before_send_raven)

    yield config if block_given?
  end
end

.configure_sentryObject



52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/gitlab/error_tracking.rb', line 52

def configure_sentry
  Sentry.init do |config|
    config.dsn = new_sentry_dsn
    config.release = Gitlab.revision
    config.environment = new_sentry_environment
    config.before_send = method(:before_send_sentry)
    config.background_worker_threads = 0
    config.send_default_pii = true
    config.traces_sample_rate = 0.2 if Gitlab::Utils.to_boolean(ENV['ENABLE_SENTRY_PERFORMANCE_MONITORING'])

    yield config if block_given?
  end
end

.log_and_raise_exception(exception, extra = {}) ⇒ Object

This should be used when you want to log the exception and passthrough exception handling: rescue and raise to be catched in upper layers of the application.

If the exception implements the method ‘sentry_extra_data` and that method returns a Hash, then the return value of that method will be merged into `extra`. Exceptions can use this mechanism to provide structured data to sentry in addition to their message and back-trace.



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

def log_and_raise_exception(exception, extra = {})
  process_exception(exception, extra: extra, trackers: [Logger])

  raise exception
end

.log_exception(exception, extra = {}) ⇒ Object

This should be used when you only want to log the exception, but not send it to Sentry.

If the exception implements the method ‘sentry_extra_data` and that method returns a Hash, then the return value of that method will be merged into `extra`. Exceptions can use this mechanism to provide structured data to sentry in addition to their message and back-trace.



116
117
118
# File 'lib/gitlab/error_tracking.rb', line 116

def log_exception(exception, extra = {})
  process_exception(exception, extra: extra, trackers: [Logger])
end

.track_and_raise_exception(exception, extra = {}) ⇒ Object

This should be used when you want to passthrough exception handling: rescue and raise to be catched in upper layers of the application.

If the exception implements the method ‘sentry_extra_data` and that method returns a Hash, then the return value of that method will be merged into `extra`. Exceptions can use this mechanism to provide structured data to sentry in addition to their message and back-trace.



73
74
75
76
77
# File 'lib/gitlab/error_tracking.rb', line 73

def track_and_raise_exception(exception, extra = {})
  process_exception(exception, extra: extra)

  raise exception
end

.track_and_raise_for_dev_exception(exception, extra = {}) ⇒ Object

This can be used for investigating exceptions that can be recovered from in code. The exception will still be raised in development and test environments.

That way we can track down these exceptions with as much information as we need to resolve them.

If the exception implements the method ‘sentry_extra_data` and that method returns a Hash, then the return value of that method will be merged into `extra`. Exceptions can use this mechanism to provide structured data to sentry in addition to their message and back-trace.

Provide an issue URL for follow up. as ‘issue_url: ’gitlab.com/gitlab-org/gitlab/issues/111’‘



93
94
95
96
97
# File 'lib/gitlab/error_tracking.rb', line 93

def track_and_raise_for_dev_exception(exception, extra = {})
  process_exception(exception, extra: extra)

  raise exception if should_raise_for_dev?
end

.track_exception(exception, extra = {}) ⇒ Object

This should be used when you only want to track the exception.

If the exception implements the method ‘sentry_extra_data` and that method returns a Hash, then the return value of that method will be merged into `extra`. Exceptions can use this mechanism to provide structured data to sentry in addition to their message and back-trace.



105
106
107
# File 'lib/gitlab/error_tracking.rb', line 105

def track_exception(exception, extra = {})
  process_exception(exception, extra: extra)
end