From 4cfc4aab9c96d6d1b7986504ea44d2c074beea4f Mon Sep 17 00:00:00 2001 From: Andy Fleming <721038+andyfleming@users.noreply.github.com> Date: Fri, 12 Apr 2024 20:13:18 -0700 Subject: [PATCH] chore: Updates HTTP attributes Based on https://opentelemetry.io/docs/specs/semconv/http/http-spans/#http-server-semantic-conventions and https://github.com/open-telemetry/semantic-conventions/blob/main/model/trace/http.yaml --- .../rack/middlewares/tracer_middleware.rb | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/instrumentation/rack/lib/opentelemetry/instrumentation/rack/middlewares/tracer_middleware.rb b/instrumentation/rack/lib/opentelemetry/instrumentation/rack/middlewares/tracer_middleware.rb index 608728ac6..9a9bad105 100644 --- a/instrumentation/rack/lib/opentelemetry/instrumentation/rack/middlewares/tracer_middleware.rb +++ b/instrumentation/rack/lib/opentelemetry/instrumentation/rack/middlewares/tracer_middleware.rb @@ -124,13 +124,14 @@ def tracer def request_span_attributes(env:) attributes = { - 'http.method' => env['REQUEST_METHOD'], - 'http.host' => env['HTTP_HOST'] || 'unknown', - 'http.scheme' => env['rack.url_scheme'], - 'http.target' => env['QUERY_STRING'].empty? ? env['PATH_INFO'] : "#{env['PATH_INFO']}?#{env['QUERY_STRING']}" + 'http.request.method' => env['REQUEST_METHOD'], + 'server.address' => env['HTTP_HOST'] || 'unknown', + 'url.scheme' => env['rack.url_scheme'], + 'url.path' => env['PATH_INFO'] } - attributes['http.user_agent'] = env['HTTP_USER_AGENT'] if env['HTTP_USER_AGENT'] + attributes['url.query'] = env['QUERY_STRING'] unless env['QUERY_STRING'].empty? + attributes['user_agent.original'] = env['HTTP_USER_AGENT'] if env['HTTP_USER_AGENT'] attributes.merge!(allowed_request_headers(env)) end @@ -153,7 +154,7 @@ def create_request_span_name(request_uri_or_path_info, env) def set_attributes_after_request(span, status, headers, _response) span.status = OpenTelemetry::Trace::Status.error unless (100..499).cover?(status.to_i) - span.set_attribute('http.status_code', status) + span.set_attribute('http.response.status_code', status) # NOTE: if data is available, it would be good to do this: # set_attribute('http.route', ...