2019-07-07 11:18:12 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-07-31 22:56:46 +05:30
|
|
|
# This class is used as a hook to observe graphql runtime events. From this
|
|
|
|
# hook both gitlab metrics and opentracking measurements are generated
|
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
module Gitlab
|
|
|
|
module Graphql
|
2019-07-31 22:56:46 +05:30
|
|
|
class GenericTracing < GraphQL::Tracing::PlatformTracing
|
2019-07-07 11:18:12 +05:30
|
|
|
self.platform_keys = {
|
|
|
|
'lex' => 'graphql.lex',
|
|
|
|
'parse' => 'graphql.parse',
|
|
|
|
'validate' => 'graphql.validate',
|
|
|
|
'analyze_query' => 'graphql.analyze',
|
|
|
|
'analyze_multiplex' => 'graphql.analyze',
|
|
|
|
'execute_multiplex' => 'graphql.execute',
|
|
|
|
'execute_query' => 'graphql.execute',
|
|
|
|
'execute_query_lazy' => 'graphql.execute',
|
|
|
|
'execute_field' => 'graphql.execute',
|
|
|
|
'execute_field_lazy' => 'graphql.execute'
|
|
|
|
}
|
|
|
|
|
|
|
|
def platform_field_key(type, field)
|
|
|
|
"#{type.name}.#{field.name}"
|
|
|
|
end
|
|
|
|
|
|
|
|
def platform_trace(platform_key, key, data, &block)
|
2019-07-31 22:56:46 +05:30
|
|
|
tags = { platform_key: platform_key, key: key }
|
2019-07-07 11:18:12 +05:30
|
|
|
start = Gitlab::Metrics::System.monotonic_time
|
|
|
|
|
2019-07-31 22:56:46 +05:30
|
|
|
with_labkit_tracing(tags, &block)
|
2019-07-07 11:18:12 +05:30
|
|
|
ensure
|
|
|
|
duration = Gitlab::Metrics::System.monotonic_time - start
|
|
|
|
|
2019-07-31 22:56:46 +05:30
|
|
|
graphql_duration_seconds.observe(tags, duration)
|
2019-07-07 11:18:12 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2019-07-31 22:56:46 +05:30
|
|
|
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
|
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
def graphql_duration_seconds
|
|
|
|
@graphql_duration_seconds ||= Gitlab::Metrics.histogram(
|
|
|
|
:graphql_duration_seconds,
|
|
|
|
'GraphQL execution time'
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|