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/context_payload_generator.rb,
lib/gitlab/error_tracking/processor/sidekiq_processor.rb,
lib/gitlab/error_tracking/processor/grpc_error_processor.rb,
lib/gitlab/error_tracking/stack_trace_highlight_decorator.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, 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
].freeze

Class Method Summary collapse

Class Method Details

.configure(&block) ⇒ Object


27
28
29
30
# File 'lib/gitlab/error_tracking.rb', line 27

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

.configure_ravenObject


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

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


49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/gitlab/error_tracking.rb', line 49

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

    yield config if block_given?
  end
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.


112
113
114
# File 'lib/gitlab/error_tracking.rb', line 112

def log_exception(exception, extra = {})
  process_exception(exception, extra: extra)
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.


69
70
71
72
73
# File 'lib/gitlab/error_tracking.rb', line 69

def track_and_raise_exception(exception, extra = {})
  process_exception(exception, sentry: true, 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'`


89
90
91
92
93
# File 'lib/gitlab/error_tracking.rb', line 89

def track_and_raise_for_dev_exception(exception, extra = {})
  process_exception(exception, sentry: true, 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.


101
102
103
# File 'lib/gitlab/error_tracking.rb', line 101

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