Module: Labkit::Tracing Private
- 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/railtie.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/auto_initialize.rb,
lib/labkit/tracing/rack_middleware.rb,
lib/labkit/tracing/grpc_interceptor.rb,
lib/labkit/tracing/rails/action_view.rb,
lib/labkit/tracing/adapters/base_span.rb,
lib/labkit/tracing/rails/active_record.rb,
lib/labkit/tracing/adapters/base_tracer.rb,
lib/labkit/tracing/open_tracing_factory.rb,
lib/labkit/tracing/rails/active_support.rb,
lib/labkit/tracing/abstract_instrumenter.rb,
lib/labkit/tracing/open_telemetry_factory.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/adapters/opentracing_span.rb,
lib/labkit/tracing/adapters/opentelemetry_span.rb,
lib/labkit/tracing/adapters/opentracing_tracer.rb,
lib/labkit/tracing/rails/action_view/subscriber.rb,
lib/labkit/tracing/adapters/opentelemetry_tracer.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
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Tracing provides distributed tracing functionality
Defined Under Namespace
Modules: Adapters, AutoInitialize, ExternalHttp, GRPC, Rails, Redis, TracingCommon Classes: AbstractInstrumenter, Factory, JaegerFactory, OpenTelemetryFactory, OpenTracingFactory, RackMiddleware, Railtie, TracingUtils
Constant Summary collapse
- DEFAULT_SERVICE_NAME =
:'labkit-service'- GRPCInterceptor =
GRPCInterceptor is the deprecated name for GRPCClientInterceptor
GRPC::ClientInterceptor
Class Method Summary collapse
- .connection_string ⇒ Object
-
.current_span ⇒ OpenTelemetry::Trace::Span?
Returns the currently active span from OpenTelemetry.
-
.enabled? ⇒ Boolean
Tracing is only enabled when the
GITLAB_TRACINGenv var is configured. - .opentracing_connection?(connection_string = ENV["GITLAB_TRACING"]) ⇒ Boolean
- .otlp_connection?(connection_string = ENV["GITLAB_TRACING"]) ⇒ Boolean
-
.sampled? ⇒ Boolean
Check if the current request is being traced.
- .stacktrace_operations ⇒ Object
-
.tracer ⇒ Object
Returns the underlying tracer implementation from the tracing library in use.
-
.tracing_url(service_name) ⇒ String?
Generates a URL to view the current trace in a tracing UI.
-
.tracing_url_enabled? ⇒ Boolean
Checks if tracing URL generation is enabled.
-
.tracing_url_template ⇒ String?
Returns the tracing URL template from the GITLAB_TRACING_URL environment variable.
-
.with_tracing(**kwargs, &block) ⇒ Object
This will run a block with a span.
Class Method Details
.connection_string ⇒ Object
44 45 46 |
# File 'lib/labkit/tracing.rb', line 44 def self.connection_string ENV["GITLAB_TRACING"] end |
.current_span ⇒ OpenTelemetry::Trace::Span?
Returns the currently active span from OpenTelemetry. This provides direct access to the OpenTelemetry span API.
154 155 156 157 158 159 |
# File 'lib/labkit/tracing.rb', line 154 def self.current_span return nil if opentracing_connection? require "opentelemetry/sdk" OpenTelemetry::Trace.current_span end |
.enabled? ⇒ Boolean
Tracing is only enabled when the GITLAB_TRACING env var is configured.
40 41 42 |
# File 'lib/labkit/tracing.rb', line 40 def self.enabled? connection_string.present? end |
.opentracing_connection?(connection_string = ENV["GITLAB_TRACING"]) ⇒ Boolean
52 53 54 |
# File 'lib/labkit/tracing.rb', line 52 def self.opentracing_connection?(connection_string = ENV["GITLAB_TRACING"]) connection_string.to_s.start_with?("#{OpenTracingFactory::OPENTRACING_SCHEME}://") end |
.otlp_connection?(connection_string = ENV["GITLAB_TRACING"]) ⇒ Boolean
48 49 50 |
# File 'lib/labkit/tracing.rb', line 48 def self.otlp_connection?(connection_string = ENV["GITLAB_TRACING"]) connection_string.to_s.start_with?("#{OpenTelemetryFactory::OTLP_SCHEME}://") end |
.sampled? ⇒ Boolean
Check if the current request is being traced.
68 69 70 71 |
# File 'lib/labkit/tracing.rb', line 68 def self.sampled? context = TracingUtils.tracer.active_span&.context context&.respond_to?(:sampled?) && context&.sampled? end |
.stacktrace_operations ⇒ Object
73 74 75 |
# File 'lib/labkit/tracing.rb', line 73 def self.stacktrace_operations @stacktrace_operations ||= Set.new(ENV["GITLAB_TRACING_INCLUDE_STACKTRACE"].to_s.split(",").map(&:strip)) end |
.tracer ⇒ Object
Returns the underlying tracer implementation from the tracing library in use. This provides direct access to the native tracer API when LabKit’s abstraction is insufficient for advanced use cases.
132 133 134 |
# File 'lib/labkit/tracing.rb', line 132 def self.tracer TracingUtils.tracer.tracer end |
.tracing_url(service_name) ⇒ String?
This method is only useful with OpenTracing and Jaeger. It does not work with OpenTelemetry backends because:
-
Uses correlation_id (GitLab-specific request ID) instead of trace_id (W3C standard)
-
Modern tracing UIs (Jaeger with OTLP, Grafana Tempo, etc.) expect trace_id for lookups
-
Only Jaeger’s legacy OpenTracing integration supports correlation_id-based URLs
Generates a URL to view the current trace in a tracing UI.
This method substitutes correlation_id } and service } placeholders in the GITLAB_TRACING_URL template with the current correlation ID and provided service name.
107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/labkit/tracing.rb', line 107 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
This method is only useful with OpenTracing and Jaeger. It does not work with OpenTelemetry backends, as they expect trace_id (W3C standard) rather than correlation_id (GitLab-specific) for trace lookups.
Checks if tracing URL generation is enabled.
85 86 87 |
# File 'lib/labkit/tracing.rb', line 85 def self.tracing_url_enabled? enabled? && tracing_url_template.present? end |
.tracing_url_template ⇒ String?
This method is only useful with OpenTracing and Jaeger. It does not work with OpenTelemetry backends, as they expect trace_id (W3C standard) rather than correlation_id (GitLab-specific) for trace lookups.
Returns the tracing URL template from the GITLAB_TRACING_URL environment variable.
63 64 65 |
# File 'lib/labkit/tracing.rb', line 63 def self.tracing_url_template ENV["GITLAB_TRACING_URL"] end |
.with_tracing(**kwargs, &block) ⇒ Object
This will run a block with a span
167 168 169 |
# File 'lib/labkit/tracing.rb', line 167 def self.with_tracing(**kwargs, &block) TracingUtils.with_tracing(**kwargs, &block) end |