lib/opentelemetry/instrumentation/rack/middlewares/tracer_middleware.rb in opentelemetry-instrumentation-rack-0.8.0 vs lib/opentelemetry/instrumentation/rack/middlewares/tracer_middleware.rb in opentelemetry-instrumentation-rack-0.9.0
- old
+ new
@@ -49,11 +49,11 @@
def initialize(app)
@app = app
end
- def call(env)
+ def call(env) # rubocop:disable Metrics/AbcSize
original_env = env.dup
extracted_context = OpenTelemetry.propagation.http.extract(env)
frontend_context = create_frontend_span(env, extracted_context)
# restore extracted context in this process:
@@ -61,12 +61,14 @@
request_span_name = create_request_span_name(env['REQUEST_URI'] || original_env['PATH_INFO'])
request_span_kind = frontend_context.nil? ? :server : :internal
tracer.in_span(request_span_name,
attributes: request_span_attributes(env: env),
kind: request_span_kind) do |request_span|
- @app.call(env).tap do |status, headers, response|
- set_attributes_after_request(request_span, status, headers, response)
+ OpenTelemetry::Instrumentation::Rack.with_span(request_span) do
+ @app.call(env).tap do |status, headers, response|
+ set_attributes_after_request(request_span, status, headers, response)
+ end
end
end
end
ensure
finish_span(frontend_context)
@@ -101,10 +103,11 @@
def request_span_attributes(env:)
{
'http.method' => env['REQUEST_METHOD'],
'http.host' => env['HTTP_HOST'] || 'unknown',
'http.scheme' => env['rack.url_scheme'],
- 'http.target' => fullpath(env)
+ 'http.target' => fullpath(env),
+ 'http.user_agent' => env['HTTP_USER_AGENT']
}.merge(allowed_request_headers(env))
end
# e.g., "/webshop/articles/4?s=1":
def fullpath(env)