module Labkit::Tracing
Tracing
provides distributed tracing functionality
Constants
- GRPCInterceptor
GRPCInterceptor
is the deprecated name for GRPCClientInterceptor
Public Class Methods
connection_string()
click to toggle source
# File lib/labkit/tracing.rb, line 24 def self.connection_string ENV["GITLAB_TRACING"] end
enabled?()
click to toggle source
Tracing
is only enabled when the `GITLAB_TRACING` env var is configured.
# File lib/labkit/tracing.rb, line 20 def self.enabled? connection_string.present? end
sampled?()
click to toggle source
Check if the current request is being traced.
# File lib/labkit/tracing.rb, line 33 def self.sampled? context = OpenTracing.active_span&.context context&.respond_to?(:sampled?) && context&.sampled? end
stacktrace_operations()
click to toggle source
# File lib/labkit/tracing.rb, line 38 def self.stacktrace_operations @stacktrace_operations ||= Set.new(ENV["GITLAB_TRACING_INCLUDE_STACKTRACE"].to_s.split(",").map(&:strip)) end
tracing_url(service_name)
click to toggle source
This will provide a link into the distributed tracing for the current trace, if it has been captured.
# File lib/labkit/tracing.rb, line 48 def self.tracing_url(service_name) return unless tracing_url_enabled? correlation_id = Labkit::Correlation::CorrelationId.current_id.to_s # Avoid using `format` since it can throw TypeErrors # which we want to avoid on unsanitised env var input tracing_url_template.to_s .gsub("{{ correlation_id }}", correlation_id) .gsub("{{ service }}", service_name) end
tracing_url_enabled?()
click to toggle source
# File lib/labkit/tracing.rb, line 42 def self.tracing_url_enabled? enabled? && tracing_url_template.present? end
tracing_url_template()
click to toggle source
# File lib/labkit/tracing.rb, line 28 def self.tracing_url_template ENV["GITLAB_TRACING_URL"] end
with_tracing(**kwargs, &block)
click to toggle source
This will run a block with a span @param operation_name [String] The operation name for the span @param tags [Hash] Tags to assign to the span @param child_of [SpanContext, Span] SpanContext that acts as a parent to
the newly-started span. If a span instance is provided, its context is automatically substituted.
# File lib/labkit/tracing.rb, line 66 def self.with_tracing(**kwargs, &block) TracingUtils.with_tracing(**kwargs, &block) end