lib/opentracing/instrumentation/rack/trace_middleware.rb in opentracing-instrumentation-0.1.1 vs lib/opentracing/instrumentation/rack/trace_middleware.rb in opentracing-instrumentation-0.1.2
- old
+ new
@@ -5,20 +5,22 @@
module OpenTracing
module Instrumentation
module Rack
# TraceMiddleware observer rack requests.
class TraceMiddleware
+ DEFAULT_COMMAND_NAME_BUILDER = StaticCommandNameBuilder.new
+
def initialize(
app,
logger: nil,
- command_name: 'rack',
+ command_name_builder: DEFAULT_COMMAND_NAME_BUILDER,
http_tagger: HttpTagger.new,
tracer: OpenTracing.global_tracer
)
@app = app
@logger = logger
- @command_name = command_name
+ @command_name_builder = command_name_builder
@http_tagger = http_tagger
@tracer = tracer
end
def call(env)
@@ -40,11 +42,12 @@
attr_reader :logger
def trace_request(env)
extracted_ctx = tracer.extract(OpenTracing::FORMAT_RACK, env)
logger&.info('Tracing context extracted') if extracted_ctx
+ command_name = @command_name_builder.build_command_name(env)
tracer.start_active_span(
- @command_name,
+ command_name,
child_of: extracted_ctx,
tags: request_tags(env),
) do |scope|
yield(scope.span)
end