Skip to content

Commit 5168831

Browse files
committed
Fix: refactors
1 parent 69239d1 commit 5168831

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

instrumentation/rack/lib/opentelemetry/instrumentation/rack/middlewares/dup/event_handler.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,10 @@ def request_span_attributes(env)
199199
}
200200

201201
attributes['url.query'] = env['QUERY_STRING'] unless env['QUERY_STRING'].empty?
202-
attributes['http.user_agent'] = env['HTTP_USER_AGENT'] if env['HTTP_USER_AGENT']
202+
if env['HTTP_USER_AGENT']
203+
attributes['http.user_agent'] = env['HTTP_USER_AGENT']
204+
attributes['user_agent.original'] = env['HTTP_USER_AGENT']
205+
end
203206
attributes.merge!(extract_request_headers(env))
204207
attributes
205208
end

instrumentation/rack/lib/opentelemetry/instrumentation/rack/middlewares/dup/tracer_middleware.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ def request_span_attributes(env:)
127127
attributes = {
128128
'http.method' => env['REQUEST_METHOD'],
129129
'http.host' => env['HTTP_HOST'] || 'unknown',
130+
'server.address' => env['HTTP_HOST'] || 'unknown',
130131
'http.scheme' => env['rack.url_scheme'],
131132
'http.target' => env['QUERY_STRING'].empty? ? env['PATH_INFO'] : "#{env['PATH_INFO']}?#{env['QUERY_STRING']}",
132133
'http.request.method' => env['REQUEST_METHOD'],
@@ -135,6 +136,10 @@ def request_span_attributes(env:)
135136
}
136137

137138
attributes['url.query'] = env['QUERY_STRING'] unless env['QUERY_STRING'].empty?
139+
if env['HTTP_USER_AGENT']
140+
attributes['http.user_agent'] = env['HTTP_USER_AGENT']
141+
attributes['user_agent.original'] = env['HTTP_USER_AGENT']
142+
end
138143
attributes.merge!(allowed_request_headers(env))
139144
end
140145

@@ -151,7 +156,7 @@ def create_request_span_name(request_uri_or_path_info, env)
151156
if (implementation = config[:url_quantization])
152157
implementation.call(request_uri_or_path_info, env)
153158
else
154-
env['REQUEST_METHOD'].to_s
159+
env['REQUEST_METHOD']
155160
end
156161
end
157162

instrumentation/rack/lib/opentelemetry/instrumentation/rack/middlewares/stable/tracer_middleware.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ def tracer
126126
def request_span_attributes(env:)
127127
attributes = {
128128
'http.request.method' => env['REQUEST_METHOD'],
129-
'http.host' => env['HTTP_HOST'] || 'unknown',
129+
'server.address' => env['HTTP_HOST'] || 'unknown',
130130
'url.scheme' => env['rack.url_scheme'],
131131
'url.path' => env['PATH_INFO']
132132
}
@@ -149,7 +149,7 @@ def create_request_span_name(request_uri_or_path_info, env)
149149
if (implementation = config[:url_quantization])
150150
implementation.call(request_uri_or_path_info, env)
151151
else
152-
env['REQUEST_METHOD'].to_s
152+
env['REQUEST_METHOD']
153153
end
154154
end
155155

0 commit comments

Comments
 (0)