lib/opentelemetry/instrumentation/rack/middlewares/tracer_middleware.rb in opentelemetry-instrumentation-rack-0.13.0 vs lib/opentelemetry/instrumentation/rack/middlewares/tracer_middleware.rb in opentelemetry-instrumentation-rack-0.14.0

- old
+ new

@@ -47,15 +47,24 @@ EMPTY_HASH = {}.freeze def initialize(app) @app = app + @untraced_endpoints = config[:untraced_endpoints].is_a?(Array) ? config[:untraced_endpoints] : [] end - def call(env) # rubocop:disable Metrics/AbcSize + def call(env) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength + if untraced_request?(env) + OpenTelemetry::Common::Utilities.untraced do + return @app.call(env) + end + end original_env = env.dup - extracted_context = OpenTelemetry.propagation.http.extract(env) + extracted_context = OpenTelemetry.propagation.extract( + env, + getter: OpenTelemetry::Context::Propagation.rack_env_getter + ) frontend_context = create_frontend_span(env, extracted_context) # restore extracted context in this process: OpenTelemetry::Context.with_current(frontend_context || extracted_context) do request_span_name = create_request_span_name(env['REQUEST_URI'] || original_env['PATH_INFO']) @@ -73,9 +82,13 @@ ensure finish_span(frontend_context) end private + + def untraced_request?(env) + @untraced_endpoints.include?(env['PATH_INFO']) + end # return Context with the frontend span as the current span def create_frontend_span(env, extracted_context) request_start_time = OpenTelemetry::Instrumentation::Rack::Util::QueueTime.get_request_start(env)