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

Discrepancy between OTel semantic conventions and built-in System.Net metrics #97395

Closed
xakep139 opened this issue Jan 23, 2024 · 10 comments
Closed

Comments

@xakep139
Copy link
Contributor

Current implementation of

internal sealed class MetricsHandler : HttpMessageHandlerStage

has a discrepancy with OpenTelemetry semantic conventions: server.port is required, but it's set only when a port isn't a default one:

One more thing not related to OTel: the documentation says that network.protocol.version is always present, but it's added only when a response is available. I created a PR to fix the documentation (dotnet/docs#39223), but I'm wondering wether it should be fixed on the implementation side, and the docs are correct.

@ghost ghost added the untriaged New issue has not been triaged by the area owner label Jan 23, 2024
@ghost
Copy link

ghost commented Jan 23, 2024

Tagging subscribers to this area: @dotnet/ncl
See info in area-owners.md if you want to be subscribed.

Issue Details

Current implementation of

internal sealed class MetricsHandler : HttpMessageHandlerStage

has a discrepancy with OpenTelemetry semantic conventions: server.port is required, but it's set only when a port isn't a default one:

One more thing not related to OTel: the documentation says that network.protocol.version is always present, but it's added only when a response is available. I created a PR to fix the documentation (dotnet/docs#39223), but I'm wondering wether it should be fixed on the implementation side, and the docs are correct.

Author: xakep139
Assignees: -
Labels:

area-System.Net.Http, untriaged

Milestone: -

@xakep139
Copy link
Contributor Author

cc @antonfirsov @CarnaViire

@antonfirsov
Copy link
Member

server.port is required, but it's set only when a port isn't a default one

There is a note in the dotnet-specific part of spec:

server.port is not reported when it matches a default one for provided scheme (443 for https and 80 for http)

@lmolkova do you happen to remember why did we specify & implement it like this originally? How did we justify that in this case Required doesn't mean always present in open-telemetry/semantic-conventions#283?

We can certainly think about making server.port always present in 9.0, but we should do it across all the metrics, not just duration and it would be a breaking change. @xakep139 are you facing any practical issues because of the way this works today?

network.protocol.version [...] but I'm wondering wether it should be fixed on the implementation side

It's not possible to include network.protocol.version when there is no response, because of implementation constraints, at least not with the current design that doesn't bake request metrics into SocketsHttpHandler. An HttpResponseMessage is needed to fetch the actual negotiated HTTP version. When an exception is being thrown by the underlying handler, there is no response object to work with.

@xakep139
Copy link
Contributor Author

I'm trying to understand whether it's a gap in OTel SemConv, or it was a miss on the .NET implementation side.
Now I understand the limitation, and wondering how other SDKs (i.e. programming languages) might follow the semantic conventions if a request might fail even without being sent (e.g. a DNS resolution has failed). In that case the negotiated HTTP version won't be known, right?
@cijothomas @reyang FYI

@antonfirsov
Copy link
Member

Triage: we should decide if we want to change the server.port behavior.

@antonfirsov antonfirsov removed the untriaged New issue has not been triaged by the area owner label Jan 26, 2024
@antonfirsov antonfirsov added this to the 9.0.0 milestone Jan 26, 2024
@lmolkova
Copy link

lmolkova commented Feb 2, 2024

@lmolkova do you happen to remember why did we specify & implement it like this originally? How did we justify that in this case Required doesn't mean always present in open-telemetry/semantic-conventions#283?

the port was changed after .NET metrics were completely frozen (there were some corner cases where we didn't set url.scheme and server.port making things ambiguous and maybe some other issues) - here's an existing issue on it #94829

@lmolkova
Copy link

lmolkova commented Feb 2, 2024

@antonfirsov, regarding your comment here:

dotnet/docs#39223 (comment)

IMO this would be misleading. Imagine the following scenario:

A user sets request.Version = 2.0
It falls back to 1.1 during negotiation, and an HTTP/1.1 connection starts serving the request
Something goes wrong in the middle (eg. invalid response) and an exception is thrown
Telemetry would log network.protocol.version=2.0 which was not the actual protocol version used for the failing communication attempt

I agree it's misleading, but not having it is also misleading:

  • A user sets (incorrectly) request.Version = foo/42
  • Server only supports bar/123 and dies in attempt to serve this bogus request and never responds
  • User tries to understand why a certain subset of requests fail and does not see foo/42 anywhere

I think we might have a small problem in otel semconv where we have one attribute for something ambiguous. Let me create a spec issue on it - update open-telemetry/semantic-conventions#686

@antonfirsov
Copy link
Member

Server only supports bar/123 and dies in attempt to serve this bogus request and never responds

This will result in an HttpRequestException with HttpRequestError.VersionNegotiationError and also logged in error.type, so users won't be left clueless. Note that HttpRequestMessage.Version alone is not sufficient to troubleshoot such problems, VersionPolicy is also needed, which makes this information hard to standardize (like you mention in open-telemetry/semantic-conventions#686 (comment), okhttp uses an array of allowed protocols). Also, we do emit this info in our event logs and IMO such diagnostic information belongs more to logging than to metrics.

@lmolkova
Copy link

lmolkova commented Feb 5, 2024

@antonfirsov makes sense, thank you

@xakep139 xakep139 changed the title Discrepanciy between OTel semantic conventions and built-in System.Net metrics Discrepancy between OTel semantic conventions and built-in System.Net metrics Feb 16, 2024
@MihaZupan
Copy link
Member

Looks like the version part has been answered - #97395 (comment).

Closing this as a dupe of #94829 to continue tracking the default server.port part.

@github-actions github-actions bot locked and limited conversation to collaborators Jul 6, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants