Module: Labkit::Tracing

Defined in:
lib/labkit/tracing.rb,
lib/labkit/tracing/grpc.rb,
lib/labkit/tracing/rails.rb,
lib/labkit/tracing/redis.rb,
lib/labkit/tracing/factory.rb,
lib/labkit/tracing/external_http.rb,
lib/labkit/tracing/tracing_utils.rb,
lib/labkit/tracing/jaeger_factory.rb,
lib/labkit/tracing/tracing_common.rb,
lib/labkit/tracing/rack_middleware.rb,
lib/labkit/tracing/grpc_interceptor.rb,
lib/labkit/tracing/rails/action_view.rb,
lib/labkit/tracing/rails/active_record.rb,
lib/labkit/tracing/rails/active_support.rb,
lib/labkit/tracing/abstract_instrumenter.rb,
lib/labkit/tracing/grpc/client_interceptor.rb,
lib/labkit/tracing/grpc/server_interceptor.rb,
lib/labkit/tracing/redis/redis_interceptor.rb,
lib/labkit/tracing/rails/action_view/subscriber.rb,
lib/labkit/tracing/rails/active_record/subscriber.rb,
lib/labkit/tracing/redis/redis_interceptor_helper.rb,
lib/labkit/tracing/rails/active_support/subscriber.rb,
lib/labkit/tracing/external_http/request_instrumenter.rb,
lib/labkit/tracing/rails/active_record/sql_instrumenter.rb,
lib/labkit/tracing/rails/active_support/cache_read_instrumenter.rb,
lib/labkit/tracing/rails/action_view/render_partial_instrumenter.rb,
lib/labkit/tracing/rails/active_support/cache_write_instrumenter.rb,
lib/labkit/tracing/rails/action_view/render_template_instrumenter.rb,
lib/labkit/tracing/rails/active_support/cache_delete_instrumenter.rb,
lib/labkit/tracing/rails/action_view/render_collection_instrumenter.rb,
lib/labkit/tracing/rails/active_support/cache_generate_instrumenter.rb,
lib/labkit/tracing/rails/active_support/cache_fetch_hit_instrumenter.rb

Overview

Tracing provides distributed tracing functionality

Defined Under Namespace

Modules: ExternalHttp, GRPC, Rails, Redis, TracingCommon Classes: AbstractInstrumenter, Factory, JaegerFactory, RackMiddleware, TracingUtils

Constant Summary collapse

GRPCInterceptor =

GRPCInterceptor is the deprecated name for GRPCClientInterceptor

GRPC::ClientInterceptor

Class Method Summary collapse

Class Method Details

.connection_stringObject



24
25
26
# File 'lib/labkit/tracing.rb', line 24

def self.connection_string
  ENV["GITLAB_TRACING"]
end

.enabled?Boolean

Tracing is only enabled when the ‘GITLAB_TRACING` env var is configured.

Returns:

  • (Boolean)


20
21
22
# File 'lib/labkit/tracing.rb', line 20

def self.enabled?
  connection_string.present?
end

.sampled?Boolean

Check if the current request is being traced.

Returns:

  • (Boolean)


33
34
35
36
# File 'lib/labkit/tracing.rb', line 33

def self.sampled?
  context = OpenTracing.active_span&.context
  context&.respond_to?(:sampled?) && context&.sampled?
end

.stacktrace_operationsObject



38
39
40
# 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) ⇒ Object

This will provide a link into the distributed tracing for the current trace, if it has been captured.



48
49
50
51
52
53
54
55
56
57
58
# 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?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/labkit/tracing.rb', line 42

def self.tracing_url_enabled?
  enabled? && tracing_url_template.present?
end

.tracing_url_templateObject



28
29
30
# File 'lib/labkit/tracing.rb', line 28

def self.tracing_url_template
  ENV["GITLAB_TRACING_URL"]
end

.with_tracing(**kwargs, &block) ⇒ Object

This will run a block with a span

Parameters:

  • operation_name (String)

    The operation name for the span

  • tags (Hash)

    Tags to assign to the span

  • 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.



66
67
68
# File 'lib/labkit/tracing.rb', line 66

def self.with_tracing(**kwargs, &block)
  TracingUtils.with_tracing(**kwargs, &block)
end