Skip to content
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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

wzy9607
Copy link

@wzy9607 wzy9607 commented Mar 16, 2025

The current method of deciding url.scheme by req.TLS is incorrect, because req.TLS is ignored by http.Client.
https://pkg.go.dev/net/http#Request

	// This field is ignored by the HTTP client.
	TLS *tls.ConnectionState

Therfore the current method will consider every request as http request, unless user manually set the otherwise useless req.TLS field.

@wzy9607 wzy9607 requested review from dmathieu, a team and dashpole as code owners March 16, 2025 08:12
@github-actions github-actions bot requested a review from akats7 March 16, 2025 08:12
@@ -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),
Copy link
Member

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?

Copy link
Contributor

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dmathieu @wzy9607 any thoughts?

Copy link
Member

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

Copy link
Author

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.

Verified

This commit was signed with the committer’s verified signature.
wzy9607 Cattī Crūdēlēs
prefer `req.URL.Scheme` to `req.TLS`, since `req.TLS` is ignored by http.Client
@wzy9607 wzy9607 requested a review from dmathieu March 29, 2025 08:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants