Skip to content

Commit

Permalink
chore: Updates HTTP attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
andyfleming committed Apr 13, 2024
1 parent 394a5d7 commit 4cfc4aa
Showing 1 changed file with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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', ...
Expand Down

0 comments on commit 4cfc4aa

Please sign in to comment.