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

HTTPClientAttributesFromHTTPRequest always sets http.scheme to http #3528

Closed
gdavison opened this issue Dec 8, 2022 · 2 comments · Fixed by #3577
Closed

HTTPClientAttributesFromHTTPRequest always sets http.scheme to http #3528

gdavison opened this issue Dec 8, 2022 · 2 comments · Fixed by #3577
Labels
bug Something isn't working

Comments

@gdavison
Copy link

gdavison commented Dec 8, 2022

Description

Calling HTTPClientAttributesFromHTTPRequest always sets the attribute http.scheme to http, even when the URL uses the https scheme.

(*SemanticConventions).httpBasicAttributesFromHTTPRequest checks for the presence of a value in request.TLS to set the value of http.scheme. However, this is not set on the client side, so will always be unset:

TLS allows HTTP servers and other software to record information about the TLS connection on which the request was received. This field is not filled in by ReadRequest. The HTTP server in this package sets the field for TLS-enabled connections before invoking a handler; otherwise it leaves the field nil. This field is ignored by the HTTP client.

Environment

  • OS: macOS
  • Architecture: amd64
  • Go Version: 1.19
  • opentelemetry-go version: v1.11.2

Steps To Reproduce

  1. Create an HTTP request pointing to an HTTPS URL
  2. Call HTTPClientAttributesFromHTTPRequest on the request
  3. Check value of http.scheme

Expected behavior

http.scheme should be set to https.

@gdavison gdavison added the bug Something isn't working label Dec 8, 2022
@fatsheep9146
Copy link
Contributor

Thanks for reporting this. @gdavison

I think that according to the description of http.scheme from https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/http.md#http-server-semantic-conventions

Attribute Type Description Examples Requirement Level
http.scheme string The URI scheme identifying the used protocol. http; https Required

Should we derive this field from request.URL?

For example

        
	if request.URL.Scheme == "https"  {
		attrs = append(attrs, sc.HTTPSchemeHTTPS)
	} else {
		attrs = append(attrs, sc.HTTPSchemeHTTP)
	}

@MrAlias

@MrAlias
Copy link
Contributor

MrAlias commented Jan 6, 2023

The changes introduced in #3499 align our implementation with the specification. We no longer add the http.schema attribute to HTTP client spans.

This attribute is still added to server spans. The most reliable way to detect if TLS was used for the request the server is serving is still to check if the TLS field is non-nil, which is still done.

The only thing that still needs to be addressed is the net.peer.port determination. We should use the request URL there to make a best effort in determining if the target port should be included or not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants