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:
Diffstat (limited to 'lib/gitlab/graphql/tracers/logger_tracer.rb')
-rw-r--r--lib/gitlab/graphql/tracers/logger_tracer.rb58
1 files changed, 58 insertions, 0 deletions
diff --git a/lib/gitlab/graphql/tracers/logger_tracer.rb b/lib/gitlab/graphql/tracers/logger_tracer.rb
new file mode 100644
index 00000000000..c7ba56824db
--- /dev/null
+++ b/lib/gitlab/graphql/tracers/logger_tracer.rb
@@ -0,0 +1,58 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module Graphql
+ module Tracers
+ # This tracer writes logs for certain trace events.
+ # It reads duration metadata written by TimerTracer.
+ class LoggerTracer
+ def self.use(schema)
+ schema.tracer(self.new)
+ end
+
+ def trace(key, data)
+ result = yield
+
+ case key
+ when "execute_query"
+ log_execute_query(**data)
+ end
+
+ result
+ end
+
+ private
+
+ def log_execute_query(query: nil, duration_s: 0)
+ # execute_query should always have :query, but we're just being defensive
+ return unless query
+
+ analysis_info = query.context[:gl_analysis]&.transform_keys { |key| "query_analysis.#{key}" }
+ info = {
+ trace_type: 'execute_query',
+ query_fingerprint: query.fingerprint,
+ duration_s: duration_s,
+ operation_name: query.operation_name,
+ operation_fingerprint: query.operation_fingerprint,
+ is_mutation: query.mutation?,
+ variables: clean_variables(query.provided_variables),
+ query_string: query.query_string
+ }
+
+ info.merge!(::Gitlab::ApplicationContext.current)
+ info.merge!(analysis_info) if analysis_info
+
+ ::Gitlab::GraphqlLogger.info(info)
+ end
+
+ def clean_variables(variables)
+ filtered = ActiveSupport::ParameterFilter
+ .new(::Rails.application.config.filter_parameters)
+ .filter(variables)
+
+ filtered&.to_s
+ end
+ end
+ end
+ end
+end