From 57a8859a11fe0c2cbd68deb83a2d2857c245fd2f Mon Sep 17 00:00:00 2001 From: Andrew Newdigate Date: Mon, 7 Jan 2019 12:40:54 +0200 Subject: Conditionally initialize the global opentracing tracer This change will instantiate an OpenTracing tracer and configure it as the global tracer when the GITLAB_TRACING environment variable is configured. GITLAB_TRACING takes a "connection string"-like value, encapsulating the driver (eg jaeger, etc) and options for the driver. Since each service, whether it's written in Ruby or Golang, uses the same connection-string, it should be very easy to configure all services in a cluster, or even a single development machine to be setup to use tracing. Note that this change does not include instrumentation or propagation changes as this is a way of breaking a previous larger change into components. The instrumentation and propagation changes will follow in separate changes. --- config/initializers/tracing.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 config/initializers/tracing.rb (limited to 'config') diff --git a/config/initializers/tracing.rb b/config/initializers/tracing.rb new file mode 100644 index 00000000000..be95f30d075 --- /dev/null +++ b/config/initializers/tracing.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +if Gitlab::Tracing.enabled? + require 'opentracing' + + # In multi-processed clustered architectures (puma, unicorn) don't + # start tracing until the worker processes are spawned. This works + # around issues when the opentracing implementation spawns threads + Gitlab::Cluster::LifecycleEvents.on_worker_start do + tracer = Gitlab::Tracing::Factory.create_tracer(Gitlab.process_name, Gitlab::Tracing.connection_string) + OpenTracing.global_tracer = tracer if tracer + end +end -- cgit v1.2.3