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/timer_tracer.rb')
-rw-r--r--lib/gitlab/graphql/tracers/timer_tracer.rb31
1 files changed, 31 insertions, 0 deletions
diff --git a/lib/gitlab/graphql/tracers/timer_tracer.rb b/lib/gitlab/graphql/tracers/timer_tracer.rb
new file mode 100644
index 00000000000..326620a22bc
--- /dev/null
+++ b/lib/gitlab/graphql/tracers/timer_tracer.rb
@@ -0,0 +1,31 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module Graphql
+ module Tracers
+ # This graphql-ruby tracer records duration for trace events and merges
+ # the duration into the trace event's metadata. This way, separate tracers
+ # can all use the same duration information.
+ #
+ # NOTE: TimerTracer should be applied last **after** other tracers, so
+ # that it runs first (similar to function composition)
+ class TimerTracer
+ def self.use(schema)
+ schema.tracer(self.new)
+ end
+
+ def trace(key, data)
+ start_time = Gitlab::Metrics::System.monotonic_time
+
+ result = yield
+
+ duration_s = Gitlab::Metrics::System.monotonic_time - start_time
+
+ data[:duration_s] = duration_s
+
+ result
+ end
+ end
+ end
+ end
+end