lib/labkit/tracing.rb in gitlab-labkit-0.1.2 vs lib/labkit/tracing.rb in gitlab-labkit-0.2.0

- old
+ new

@@ -3,17 +3,17 @@ require "active_support/all" module Labkit # Tracing provides distributed tracing functionality module Tracing - autoload :Common, "labkit/tracing/common" autoload :Factory, "labkit/tracing/factory" autoload :GRPCInterceptor, "labkit/tracing/grpc_interceptor" autoload :JaegerFactory, "labkit/tracing/jaeger_factory" autoload :RackMiddleware, "labkit/tracing/rack_middleware" autoload :Rails, "labkit/tracing/rails" autoload :Sidekiq, "labkit/tracing/sidekiq" + autoload :TracingUtils, "labkit/tracing/tracing_utils" # Tracing is only enabled when the `GITLAB_TRACING` env var is configured. def self.enabled? connection_string.present? end @@ -40,8 +40,18 @@ # 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 + + # 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. + def self.with_tracing(**kwargs, &block) + TracingUtils.with_tracing(**kwargs, &block) end end end