Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-03-16 21:18:33 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2021-03-16 21:18:33 +0300
commitf64a639bcfa1fc2bc89ca7db268f594306edfd7c (patch)
treea2c3c2ebcc3b45e596949db485d6ed18ffaacfa1 /lib/gitlab/error_tracking
parentbfbc3e0d6583ea1a91f627528bedc3d65ba4b10f (diff)
Add latest changes from gitlab-org/gitlab@13-10-stable-eev13.10.0-rc40
Diffstat (limited to 'lib/gitlab/error_tracking')
-rw-r--r--lib/gitlab/error_tracking/context_payload_generator.rb66
-rw-r--r--lib/gitlab/error_tracking/detailed_error.rb2
-rw-r--r--lib/gitlab/error_tracking/error.rb2
-rw-r--r--lib/gitlab/error_tracking/error_collection.rb2
-rw-r--r--lib/gitlab/error_tracking/error_event.rb2
-rw-r--r--lib/gitlab/error_tracking/log_formatter.rb55
-rw-r--r--lib/gitlab/error_tracking/processor/context_payload_processor.rb18
-rw-r--r--lib/gitlab/error_tracking/project.rb2
-rw-r--r--lib/gitlab/error_tracking/repo.rb2
-rw-r--r--lib/gitlab/error_tracking/stack_trace_highlight_decorator.rb2
10 files changed, 153 insertions, 0 deletions
diff --git a/lib/gitlab/error_tracking/context_payload_generator.rb b/lib/gitlab/error_tracking/context_payload_generator.rb
new file mode 100644
index 00000000000..c99283b3d20
--- /dev/null
+++ b/lib/gitlab/error_tracking/context_payload_generator.rb
@@ -0,0 +1,66 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module ErrorTracking
+ class ContextPayloadGenerator
+ def self.generate(exception, extra = {})
+ new.generate(exception, extra)
+ end
+
+ def generate(exception, extra = {})
+ {
+ extra: extra_payload(exception, extra),
+ tags: tags_payload,
+ user: user_payload
+ }
+ end
+
+ private
+
+ def extra_payload(exception, extra)
+ inline_extra = exception.try(:sentry_extra_data)
+ if inline_extra.present? && inline_extra.is_a?(Hash)
+ extra = extra.merge(inline_extra)
+ end
+
+ sanitize_request_parameters(extra)
+ end
+
+ def sanitize_request_parameters(parameters)
+ filter = ActiveSupport::ParameterFilter.new(::Rails.application.config.filter_parameters)
+ filter.filter(parameters)
+ end
+
+ def tags_payload
+ extra_tags_from_env.merge!(
+ program: Gitlab.process_name,
+ locale: I18n.locale,
+ feature_category: current_context['meta.feature_category'],
+ Labkit::Correlation::CorrelationId::LOG_KEY.to_sym => Labkit::Correlation::CorrelationId.current_id
+ )
+ end
+
+ def user_payload
+ {
+ username: current_context['meta.user']
+ }
+ end
+
+ # Static tags that are set on application start
+ def extra_tags_from_env
+ Gitlab::Json.parse(ENV.fetch('GITLAB_SENTRY_EXTRA_TAGS', '{}')).to_hash
+ rescue => e
+ Gitlab::AppLogger.debug("GITLAB_SENTRY_EXTRA_TAGS could not be parsed as JSON: #{e.class.name}: #{e.message}")
+
+ {}
+ end
+
+ def current_context
+ # In case Gitlab::ErrorTracking is used when the app starts
+ return {} unless defined?(::Gitlab::ApplicationContext)
+
+ ::Gitlab::ApplicationContext.current.to_h
+ end
+ end
+ end
+end
diff --git a/lib/gitlab/error_tracking/detailed_error.rb b/lib/gitlab/error_tracking/detailed_error.rb
index 5d272efa64a..d0b3fc176aa 100644
--- a/lib/gitlab/error_tracking/detailed_error.rb
+++ b/lib/gitlab/error_tracking/detailed_error.rb
@@ -1,5 +1,7 @@
# frozen_string_literal: true
+# This should be in the ErrorTracking namespace. For more details, see:
+# https://gitlab.com/gitlab-org/gitlab/-/issues/323342
module Gitlab
module ErrorTracking
class DetailedError
diff --git a/lib/gitlab/error_tracking/error.rb b/lib/gitlab/error_tracking/error.rb
index 6bfb9dae610..a256f87ec3d 100644
--- a/lib/gitlab/error_tracking/error.rb
+++ b/lib/gitlab/error_tracking/error.rb
@@ -1,5 +1,7 @@
# frozen_string_literal: true
+# This should be in the ErrorTracking namespace. For more details, see:
+# https://gitlab.com/gitlab-org/gitlab/-/issues/323342
module Gitlab
module ErrorTracking
class Error
diff --git a/lib/gitlab/error_tracking/error_collection.rb b/lib/gitlab/error_tracking/error_collection.rb
index 56bcb671363..d01064bb677 100644
--- a/lib/gitlab/error_tracking/error_collection.rb
+++ b/lib/gitlab/error_tracking/error_collection.rb
@@ -1,5 +1,7 @@
# frozen_string_literal: true
+# This should be in the ErrorTracking namespace. For more details, see:
+# https://gitlab.com/gitlab-org/gitlab/-/issues/323342
module Gitlab
module ErrorTracking
class ErrorCollection
diff --git a/lib/gitlab/error_tracking/error_event.rb b/lib/gitlab/error_tracking/error_event.rb
index 015d2c0ead0..d80289f6bc9 100644
--- a/lib/gitlab/error_tracking/error_event.rb
+++ b/lib/gitlab/error_tracking/error_event.rb
@@ -1,5 +1,7 @@
# frozen_string_literal: true
+# This should be in the ErrorTracking namespace. For more details, see:
+# https://gitlab.com/gitlab-org/gitlab/-/issues/323342
module Gitlab
module ErrorTracking
class ErrorEvent
diff --git a/lib/gitlab/error_tracking/log_formatter.rb b/lib/gitlab/error_tracking/log_formatter.rb
new file mode 100644
index 00000000000..d004c4e20bb
--- /dev/null
+++ b/lib/gitlab/error_tracking/log_formatter.rb
@@ -0,0 +1,55 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module ErrorTracking
+ class LogFormatter
+ # Note: all the accesses to Raven's contexts here are to keep the
+ # backward-compatibility to Sentry's built-in integrations. In future,
+ # they can be removed.
+ def generate_log(exception, context_payload)
+ payload = {}
+
+ Gitlab::ExceptionLogFormatter.format!(exception, payload)
+ append_user_to_log!(payload, context_payload)
+ append_tags_to_log!(payload, context_payload)
+ append_extra_to_log!(payload, context_payload)
+
+ payload
+ end
+
+ private
+
+ def append_user_to_log!(payload, context_payload)
+ user_context = Raven.context.user.merge(context_payload[:user])
+ user_context.each do |key, value|
+ payload["user.#{key}"] = value
+ end
+ end
+
+ def append_tags_to_log!(payload, context_payload)
+ tags_context = Raven.context.tags.merge(context_payload[:tags])
+ tags_context.each do |key, value|
+ payload["tags.#{key}"] = value
+ end
+ end
+
+ def append_extra_to_log!(payload, context_payload)
+ extra = Raven.context.extra.merge(context_payload[:extra])
+ extra = extra.except(:server)
+
+ # The extra value for sidekiq is a hash whose keys are strings.
+ if extra[:sidekiq].is_a?(Hash) && extra[:sidekiq].key?('args')
+ sidekiq_extra = extra.delete(:sidekiq)
+ sidekiq_extra['args'] = Gitlab::ErrorTracking::Processor::SidekiqProcessor.loggable_arguments(
+ sidekiq_extra['args'], sidekiq_extra['class']
+ )
+ payload["extra.sidekiq"] = sidekiq_extra
+ end
+
+ extra.each do |key, value|
+ payload["extra.#{key}"] = value
+ end
+ end
+ end
+ end
+end
diff --git a/lib/gitlab/error_tracking/processor/context_payload_processor.rb b/lib/gitlab/error_tracking/processor/context_payload_processor.rb
new file mode 100644
index 00000000000..5185205e94e
--- /dev/null
+++ b/lib/gitlab/error_tracking/processor/context_payload_processor.rb
@@ -0,0 +1,18 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module ErrorTracking
+ module Processor
+ class ContextPayloadProcessor < ::Raven::Processor
+ # This processor is added to inject application context into Sentry
+ # events generated by Sentry built-in integrations. When the
+ # integrations are re-implemented and use Gitlab::ErrorTracking, this
+ # processor should be removed.
+ def process(payload)
+ context_payload = Gitlab::ErrorTracking::ContextPayloadGenerator.generate(nil, {})
+ payload.deep_merge!(context_payload)
+ end
+ end
+ end
+ end
+end
diff --git a/lib/gitlab/error_tracking/project.rb b/lib/gitlab/error_tracking/project.rb
index 93e81da5034..a4ed8831e38 100644
--- a/lib/gitlab/error_tracking/project.rb
+++ b/lib/gitlab/error_tracking/project.rb
@@ -1,5 +1,7 @@
# frozen_string_literal: true
+# This should be in the ErrorTracking namespace. For more details, see:
+# https://gitlab.com/gitlab-org/gitlab/-/issues/323342
module Gitlab
module ErrorTracking
class Project
diff --git a/lib/gitlab/error_tracking/repo.rb b/lib/gitlab/error_tracking/repo.rb
index 50611943bac..e88ac58ff0f 100644
--- a/lib/gitlab/error_tracking/repo.rb
+++ b/lib/gitlab/error_tracking/repo.rb
@@ -1,5 +1,7 @@
# frozen_string_literal: true
+# This should be in the ErrorTracking namespace. For more details, see:
+# https://gitlab.com/gitlab-org/gitlab/-/issues/323342
module Gitlab
module ErrorTracking
class Repo
diff --git a/lib/gitlab/error_tracking/stack_trace_highlight_decorator.rb b/lib/gitlab/error_tracking/stack_trace_highlight_decorator.rb
index 1e490e52c43..24f4c2a2dcf 100644
--- a/lib/gitlab/error_tracking/stack_trace_highlight_decorator.rb
+++ b/lib/gitlab/error_tracking/stack_trace_highlight_decorator.rb
@@ -1,5 +1,7 @@
# frozen_string_literal: true
+# This should be in the ErrorTracking namespace. For more details, see:
+# https://gitlab.com/gitlab-org/gitlab/-/issues/323342
module Gitlab
module ErrorTracking
module StackTraceHighlightDecorator