-
Notifications
You must be signed in to change notification settings - Fork 622
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
otelhttp: Correctly set url.scheme
attr in http client metrics.
#6938
base: main
Are you sure you want to change the base?
Conversation
80ab9e0
to
0a5a380
Compare
@@ -510,7 +510,7 @@ func (n CurrentHTTPClient) MetricAttributes(req *http.Request, statusCode int, a | |||
attributes = append(attributes, | |||
semconvNew.HTTPRequestMethodKey.String(standardizeHTTPMethod(req.Method)), | |||
semconvNew.ServerAddress(requestHost), | |||
n.scheme(req.TLS != nil), | |||
n.scheme(req.URL), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about passing req
here, so the method can fallback to the req.TLS
value, and then http
if the URL isn't set?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we're passing the request directly we do also get the ability to account for proxies by checking the headers. Also leads to the question though of if a proxy or alb terminates TLS, whats the correct scheme to set.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also leads to the question though of if a proxy or alb terminates TLS, whats the correct scheme to set.
Let's leave that out for now. The semantic conventions also don't answer this clearly.
I have opened open-telemetry/semantic-conventions#2009
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added fallback to req.TLS
.
prefer `req.URL.Scheme` to `req.TLS`, since `req.TLS` is ignored by http.Client
0a5a380
to
ebdf055
Compare
The current method of deciding
url.scheme
byreq.TLS
is incorrect, becausereq.TLS
is ignored byhttp.Client
.https://pkg.go.dev/net/http#Request
Therfore the current method will consider every request as http request, unless user manually set the otherwise useless
req.TLS
field.