summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJan Provaznik <jprovaznik@gitlab.com>2019-05-02 07:01:14 +0000
committerBob Van Landuyt <bob@gitlab.com>2019-05-02 07:01:14 +0000
commit96750fac4c4060d0a9e321039cab3dcf52a31105 (patch)
treec5f0f735bc80021e39193dac3ca10026e138c948 /lib
parent2b3b0bb1847e5d910b3e5dc5e151f194c12d3907 (diff)
downloadgitlab-ce-96750fac4c4060d0a9e321039cab3dcf52a31105.tar.gz
Add opentracing integration for graphql
Extends existing graphql's tracer with opentracing measurements. Because it also adds Tracing::Graphql class (for opentracing), it also renames Graphql::Tracing class to Graphql::GenericTracing to minimize confusion with similar class names.
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/graphql/generic_tracing.rb (renamed from lib/gitlab/graphql/tracing.rb)22
1 files changed, 19 insertions, 3 deletions
diff --git a/lib/gitlab/graphql/tracing.rb b/lib/gitlab/graphql/generic_tracing.rb
index 6b505e4262b..936b22d5afa 100644
--- a/lib/gitlab/graphql/tracing.rb
+++ b/lib/gitlab/graphql/generic_tracing.rb
@@ -1,8 +1,11 @@
# frozen_string_literal: true
+# This class is used as a hook to observe graphql runtime events. From this
+# hook both gitlab metrics and opentracking measurements are generated
+
module Gitlab
module Graphql
- class Tracing < GraphQL::Tracing::PlatformTracing
+ class GenericTracing < GraphQL::Tracing::PlatformTracing
self.platform_keys = {
'lex' => 'graphql.lex',
'parse' => 'graphql.parse',
@@ -21,17 +24,30 @@ module Gitlab
end
def platform_trace(platform_key, key, data, &block)
+ tags = { platform_key: platform_key, key: key }
start = Gitlab::Metrics::System.monotonic_time
- yield
+ with_labkit_tracing(tags, &block)
ensure
duration = Gitlab::Metrics::System.monotonic_time - start
- graphql_duration_seconds.observe({ platform_key: platform_key, key: key }, duration)
+ graphql_duration_seconds.observe(tags, duration)
end
private
+ def with_labkit_tracing(tags, &block)
+ return yield unless Labkit::Tracing.enabled?
+
+ name = "#{tags[:platform_key]}.#{tags[:key]}"
+ span_tags = {
+ 'component' => 'web',
+ 'span.kind' => 'server'
+ }.merge(tags.stringify_keys)
+
+ Labkit::Tracing.with_tracing(operation_name: name, tags: span_tags, &block)
+ end
+
def graphql_duration_seconds
@graphql_duration_seconds ||= Gitlab::Metrics.histogram(
:graphql_duration_seconds,