Loading lib/labkit/tracing/README.md +7 −13 Original line number Diff line number Diff line Loading @@ -143,13 +143,12 @@ The simplest initialization uses GITLAB_TRACING configuration only: # In your application initializer (e.g., config/initializers/tracing.rb) if Labkit::Tracing.enabled? # REQUIRED: Create the tracer to actually collect traces tracer = Labkit::Tracing::Factory.create_tracer("my-service", ENV["GITLAB_TRACING"]) Labkit::Tracing::Factory.create_tracer("my-service", ENV["GITLAB_TRACING"]) # For OpenTracing/Jaeger: Set as global tracer OpenTracing.global_tracer = tracer if tracer # For OpenTelemetry/OTLP: Factory.create_tracer configures it globally # The tracer provider is set automatically - no additional setup needed # Factory.create_tracer configures the tracer globally for both: # - OpenTelemetry/OTLP: Sets OpenTelemetry.tracer_provider # - OpenTracing/Jaeger: Sets OpenTracing.global_tracer # No additional setup needed end ``` Loading Loading @@ -554,11 +553,7 @@ end if Labkit::Tracing.enabled? # REQUIRED: Initialize the tracer to collect and export traces # Without this, instrumentation runs but traces aren't sent anywhere tracer = Labkit::Tracing::Factory.create_tracer("my-rails-app", ENV["GITLAB_TRACING"]) # For OpenTracing/Jaeger, set the global tracer # For OpenTelemetry/OTLP, this is already configured globally by create_tracer OpenTracing.global_tracer = tracer if tracer Labkit::Tracing::Factory.create_tracer("my-rails-app", ENV["GITLAB_TRACING"]) # Instrument Rails components Rails.application.config.after_initialize do Loading Loading @@ -616,8 +611,7 @@ This step is **required** - setting `GITLAB_TRACING` alone is not enough: ```ruby # config/initializers/tracing.rb if Labkit::Tracing.enabled? tracer = Labkit::Tracing::Factory.create_tracer("my-service", ENV["GITLAB_TRACING"]) OpenTracing.global_tracer = tracer if tracer # For OpenTracing/Jaeger Labkit::Tracing::Factory.create_tracer("my-service", ENV["GITLAB_TRACING"]) end ``` Loading lib/labkit/tracing/jaeger_factory.rb +11 −5 Original line number Diff line number Diff line Loading @@ -4,6 +4,7 @@ require "active_support" require "active_support/core_ext" require "jaeger/client" require "opentracing" module Labkit module Tracing Loading Loading @@ -31,7 +32,7 @@ module Labkit kwargs = { service_name: service_name, sampler: get_sampler(options[:sampler], options[:sampler_param]), reporter: get_reporter(service_name, options[:http_endpoint], options[:udp_endpoint], headers), reporter: get_reporter(service_name, options[:http_endpoint], options[:udp_endpoint], headers) }.compact extra_params = options.except(:sampler, :sampler_param, :http_endpoint, :udp_endpoint, :strict_parsing, :debug) Loading @@ -43,7 +44,12 @@ module Labkit warn message end Jaeger::Client.build(**kwargs) tracer = Jaeger::Client.build(**kwargs) # Set as global tracer for consistency with OpenTelemetry behavior OpenTracing.global_tracer = tracer if tracer tracer end def self.build_headers(options) Loading @@ -60,7 +66,7 @@ module Labkit headers["Authorization"] = "Basic " + Base64.strict_encode64("#{user}:#{password}") end return headers headers end private_class_method :build_headers Loading Loading @@ -92,7 +98,7 @@ module Labkit private_class_method :get_reporter def self.get_http_sender(encoder, address, headers) Jaeger::HttpSender.new(url: address, headers: headers, encoder: encoder, logger: Logger.new(STDOUT)) Jaeger::HttpSender.new(url: address, headers: headers, encoder: encoder, logger: Logger.new($stdout)) end private_class_method :get_http_sender Loading @@ -101,7 +107,7 @@ module Labkit host = pair[0] port = pair[1] ? pair[1].to_i : DEFAULT_UDP_PORT Jaeger::UdpSender.new(host: host, port: port, encoder: encoder, logger: Logger.new(STDOUT)) Jaeger::UdpSender.new(host: host, port: port, encoder: encoder, logger: Logger.new($stdout)) end private_class_method :get_udp_sender end Loading spec/labkit/tracing/jaeger_factory_spec.rb +8 −1 Original line number Diff line number Diff line Loading @@ -12,6 +12,13 @@ describe Labkit::Tracing::JaegerFactory do it "yields control" do expect { |b| tracer.start_active_span("operation_name", &b) }.to yield_control end it "sets OpenTracing.global_tracer" do # Verify the tracer was created and is a Jaeger tracer expect(tracer).to be_a(Jaeger::Tracer) # Verify global_tracer is also a Jaeger tracer (not the default no-op) expect(OpenTracing.global_tracer).to be_a(Jaeger::Tracer) end end context "when processing default connections" do Loading Loading @@ -72,7 +79,7 @@ describe Labkit::Tracing::JaegerFactory do described_class.create_tracer( service_name, debug: "1", http_endpoint: "https://foo:bar@observe.gitlab.com", http_endpoint: "https://foo:bar@observe.gitlab.com" ) end end Loading Loading
lib/labkit/tracing/README.md +7 −13 Original line number Diff line number Diff line Loading @@ -143,13 +143,12 @@ The simplest initialization uses GITLAB_TRACING configuration only: # In your application initializer (e.g., config/initializers/tracing.rb) if Labkit::Tracing.enabled? # REQUIRED: Create the tracer to actually collect traces tracer = Labkit::Tracing::Factory.create_tracer("my-service", ENV["GITLAB_TRACING"]) Labkit::Tracing::Factory.create_tracer("my-service", ENV["GITLAB_TRACING"]) # For OpenTracing/Jaeger: Set as global tracer OpenTracing.global_tracer = tracer if tracer # For OpenTelemetry/OTLP: Factory.create_tracer configures it globally # The tracer provider is set automatically - no additional setup needed # Factory.create_tracer configures the tracer globally for both: # - OpenTelemetry/OTLP: Sets OpenTelemetry.tracer_provider # - OpenTracing/Jaeger: Sets OpenTracing.global_tracer # No additional setup needed end ``` Loading Loading @@ -554,11 +553,7 @@ end if Labkit::Tracing.enabled? # REQUIRED: Initialize the tracer to collect and export traces # Without this, instrumentation runs but traces aren't sent anywhere tracer = Labkit::Tracing::Factory.create_tracer("my-rails-app", ENV["GITLAB_TRACING"]) # For OpenTracing/Jaeger, set the global tracer # For OpenTelemetry/OTLP, this is already configured globally by create_tracer OpenTracing.global_tracer = tracer if tracer Labkit::Tracing::Factory.create_tracer("my-rails-app", ENV["GITLAB_TRACING"]) # Instrument Rails components Rails.application.config.after_initialize do Loading Loading @@ -616,8 +611,7 @@ This step is **required** - setting `GITLAB_TRACING` alone is not enough: ```ruby # config/initializers/tracing.rb if Labkit::Tracing.enabled? tracer = Labkit::Tracing::Factory.create_tracer("my-service", ENV["GITLAB_TRACING"]) OpenTracing.global_tracer = tracer if tracer # For OpenTracing/Jaeger Labkit::Tracing::Factory.create_tracer("my-service", ENV["GITLAB_TRACING"]) end ``` Loading
lib/labkit/tracing/jaeger_factory.rb +11 −5 Original line number Diff line number Diff line Loading @@ -4,6 +4,7 @@ require "active_support" require "active_support/core_ext" require "jaeger/client" require "opentracing" module Labkit module Tracing Loading Loading @@ -31,7 +32,7 @@ module Labkit kwargs = { service_name: service_name, sampler: get_sampler(options[:sampler], options[:sampler_param]), reporter: get_reporter(service_name, options[:http_endpoint], options[:udp_endpoint], headers), reporter: get_reporter(service_name, options[:http_endpoint], options[:udp_endpoint], headers) }.compact extra_params = options.except(:sampler, :sampler_param, :http_endpoint, :udp_endpoint, :strict_parsing, :debug) Loading @@ -43,7 +44,12 @@ module Labkit warn message end Jaeger::Client.build(**kwargs) tracer = Jaeger::Client.build(**kwargs) # Set as global tracer for consistency with OpenTelemetry behavior OpenTracing.global_tracer = tracer if tracer tracer end def self.build_headers(options) Loading @@ -60,7 +66,7 @@ module Labkit headers["Authorization"] = "Basic " + Base64.strict_encode64("#{user}:#{password}") end return headers headers end private_class_method :build_headers Loading Loading @@ -92,7 +98,7 @@ module Labkit private_class_method :get_reporter def self.get_http_sender(encoder, address, headers) Jaeger::HttpSender.new(url: address, headers: headers, encoder: encoder, logger: Logger.new(STDOUT)) Jaeger::HttpSender.new(url: address, headers: headers, encoder: encoder, logger: Logger.new($stdout)) end private_class_method :get_http_sender Loading @@ -101,7 +107,7 @@ module Labkit host = pair[0] port = pair[1] ? pair[1].to_i : DEFAULT_UDP_PORT Jaeger::UdpSender.new(host: host, port: port, encoder: encoder, logger: Logger.new(STDOUT)) Jaeger::UdpSender.new(host: host, port: port, encoder: encoder, logger: Logger.new($stdout)) end private_class_method :get_udp_sender end Loading
spec/labkit/tracing/jaeger_factory_spec.rb +8 −1 Original line number Diff line number Diff line Loading @@ -12,6 +12,13 @@ describe Labkit::Tracing::JaegerFactory do it "yields control" do expect { |b| tracer.start_active_span("operation_name", &b) }.to yield_control end it "sets OpenTracing.global_tracer" do # Verify the tracer was created and is a Jaeger tracer expect(tracer).to be_a(Jaeger::Tracer) # Verify global_tracer is also a Jaeger tracer (not the default no-op) expect(OpenTracing.global_tracer).to be_a(Jaeger::Tracer) end end context "when processing default connections" do Loading Loading @@ -72,7 +79,7 @@ describe Labkit::Tracing::JaegerFactory do described_class.create_tracer( service_name, debug: "1", http_endpoint: "https://foo:bar@observe.gitlab.com", http_endpoint: "https://foo:bar@observe.gitlab.com" ) end end Loading