Loading lib/labkit/tracing.rb +11 −1 Original line number Diff line number Diff line Loading @@ -5,13 +5,13 @@ 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? Loading Loading @@ -43,5 +43,15 @@ module Labkit .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 lib/labkit/tracing/grpc_interceptor.rb +1 −2 Original line number Diff line number Diff line Loading @@ -9,7 +9,6 @@ module Labkit # GRPCInterceptor is a client-side GRPC interceptor # for instrumenting GRPC calls with distributed tracing class GRPCInterceptor < GRPC::ClientInterceptor include Common include Singleton def request_response(request:, call:, method:, metadata:) Loading @@ -33,7 +32,7 @@ module Labkit def wrap_with_tracing(method, grpc_type, metadata) tags = { "component" => "grpc", "span.kind" => "client", "grpc.method" => method, "grpc.type" => grpc_type } in_tracing_span(operation_name: "grpc:#{method}", tags: tags) do |span| TracingUtils.with_tracing(operation_name: "grpc:#{method}", tags: tags) do |span| OpenTracing.inject(span.context, OpenTracing::FORMAT_TEXT_MAP, metadata) yield Loading lib/labkit/tracing/rack_middleware.rb +2 −4 Original line number Diff line number Diff line Loading @@ -10,8 +10,6 @@ module Labkit # instrumenting incoming http requests into a Rails/Rack # server class RackMiddleware include Common REQUEST_METHOD = "REQUEST_METHOD" def initialize(app) Loading @@ -21,10 +19,10 @@ module Labkit def call(env) method = env[REQUEST_METHOD] context = tracer.extract(OpenTracing::FORMAT_RACK, env) context = TracingUtils.tracer.extract(OpenTracing::FORMAT_RACK, env) tags = { "component" => "rack", "span.kind" => "server", "http.method" => method, "http.url" => self.class.build_sanitized_url_from_env(env) } in_tracing_span(operation_name: "http:#{method}", child_of: context, tags: tags) do |span| TracingUtils.with_tracing(operation_name: "http:#{method}", child_of: context, tags: tags) do |span| @app.call(env).tap { |status_code, _headers, _body| span.set_tag("http.status_code", status_code) } end end Loading lib/labkit/tracing/rails/rails_common.rb +1 −2 Original line number Diff line number Diff line Loading @@ -9,7 +9,6 @@ module Labkit # functionality for the rails instrumentation classes module RailsCommon extend ActiveSupport::Concern include Labkit::Tracing::Common class_methods do def create_unsubscriber(subscriptions) Loading @@ -20,7 +19,7 @@ module Labkit def generate_span_for_notification(operation_name, start, finish, payload, tags) exception = payload[:exception] postnotify_span(operation_name, start, finish, tags: tags, exception: exception) TracingUtils.postnotify_span(operation_name, start, finish, tags: tags, exception: exception) end end end Loading lib/labkit/tracing/sidekiq/client_middleware.rb +2 −3 Original line number Diff line number Diff line Loading @@ -14,10 +14,9 @@ module Labkit SPAN_KIND = "client" def call(_worker_class, job, _queue, _redis_pool) in_tracing_span(operation_name: "sidekiq:#{job["class"]}", tags: tags_from_job(job, SPAN_KIND)) do |span| TracingUtils.with_tracing(operation_name: "sidekiq:#{job["class"]}", tags: tags_from_job(job, SPAN_KIND)) do |span| # Inject the details directly into the job tracer .inject(span.context, OpenTracing::FORMAT_TEXT_MAP, job) TracingUtils.tracer.inject(span.context, OpenTracing::FORMAT_TEXT_MAP, job) yield end Loading Loading
lib/labkit/tracing.rb +11 −1 Original line number Diff line number Diff line Loading @@ -5,13 +5,13 @@ 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? Loading Loading @@ -43,5 +43,15 @@ module Labkit .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
lib/labkit/tracing/grpc_interceptor.rb +1 −2 Original line number Diff line number Diff line Loading @@ -9,7 +9,6 @@ module Labkit # GRPCInterceptor is a client-side GRPC interceptor # for instrumenting GRPC calls with distributed tracing class GRPCInterceptor < GRPC::ClientInterceptor include Common include Singleton def request_response(request:, call:, method:, metadata:) Loading @@ -33,7 +32,7 @@ module Labkit def wrap_with_tracing(method, grpc_type, metadata) tags = { "component" => "grpc", "span.kind" => "client", "grpc.method" => method, "grpc.type" => grpc_type } in_tracing_span(operation_name: "grpc:#{method}", tags: tags) do |span| TracingUtils.with_tracing(operation_name: "grpc:#{method}", tags: tags) do |span| OpenTracing.inject(span.context, OpenTracing::FORMAT_TEXT_MAP, metadata) yield Loading
lib/labkit/tracing/rack_middleware.rb +2 −4 Original line number Diff line number Diff line Loading @@ -10,8 +10,6 @@ module Labkit # instrumenting incoming http requests into a Rails/Rack # server class RackMiddleware include Common REQUEST_METHOD = "REQUEST_METHOD" def initialize(app) Loading @@ -21,10 +19,10 @@ module Labkit def call(env) method = env[REQUEST_METHOD] context = tracer.extract(OpenTracing::FORMAT_RACK, env) context = TracingUtils.tracer.extract(OpenTracing::FORMAT_RACK, env) tags = { "component" => "rack", "span.kind" => "server", "http.method" => method, "http.url" => self.class.build_sanitized_url_from_env(env) } in_tracing_span(operation_name: "http:#{method}", child_of: context, tags: tags) do |span| TracingUtils.with_tracing(operation_name: "http:#{method}", child_of: context, tags: tags) do |span| @app.call(env).tap { |status_code, _headers, _body| span.set_tag("http.status_code", status_code) } end end Loading
lib/labkit/tracing/rails/rails_common.rb +1 −2 Original line number Diff line number Diff line Loading @@ -9,7 +9,6 @@ module Labkit # functionality for the rails instrumentation classes module RailsCommon extend ActiveSupport::Concern include Labkit::Tracing::Common class_methods do def create_unsubscriber(subscriptions) Loading @@ -20,7 +19,7 @@ module Labkit def generate_span_for_notification(operation_name, start, finish, payload, tags) exception = payload[:exception] postnotify_span(operation_name, start, finish, tags: tags, exception: exception) TracingUtils.postnotify_span(operation_name, start, finish, tags: tags, exception: exception) end end end Loading
lib/labkit/tracing/sidekiq/client_middleware.rb +2 −3 Original line number Diff line number Diff line Loading @@ -14,10 +14,9 @@ module Labkit SPAN_KIND = "client" def call(_worker_class, job, _queue, _redis_pool) in_tracing_span(operation_name: "sidekiq:#{job["class"]}", tags: tags_from_job(job, SPAN_KIND)) do |span| TracingUtils.with_tracing(operation_name: "sidekiq:#{job["class"]}", tags: tags_from_job(job, SPAN_KIND)) do |span| # Inject the details directly into the job tracer .inject(span.context, OpenTracing::FORMAT_TEXT_MAP, job) TracingUtils.tracer.inject(span.context, OpenTracing::FORMAT_TEXT_MAP, job) yield end Loading