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

[HttpClient & HttpWebRequest] Set network protocol version from response object #5043

Conversation

vishweshbankwar
Copy link
Member

@vishweshbankwar vishweshbankwar commented Nov 10, 2023

Fixes #4928

Changes

We are currently setting network.protocol.version using the version that was specified in request object. However, the final version depends on the version negotiated with the server. The PR updates to use version from response object. In case of no response, network.protocol.version will not be set.

Please provide a brief description of the changes here.

Merge requirement checklist

  • CONTRIBUTING guidelines followed (nullable enabled, static analysis, etc.)
  • Unit tests added/updated
  • Appropriate CHANGELOG.md files updated for non-trivial changes
  • Changes in public API reviewed (if applicable)

Copy link

codecov bot commented Nov 10, 2023

Codecov Report

Merging #5043 (0399ac1) into main (c337d1e) will increase coverage by 0.16%.
The diff coverage is 84.61%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #5043      +/-   ##
==========================================
+ Coverage   83.32%   83.48%   +0.16%     
==========================================
  Files         296      296              
  Lines       12473    12481       +8     
==========================================
+ Hits        10393    10420      +27     
+ Misses       2080     2061      -19     
Flag Coverage Δ
unittests 83.48% <84.61%> (+0.16%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
...tp/Implementation/HttpHandlerDiagnosticListener.cs 73.50% <100.00%> (ø)
...ementation/HttpHandlerMetricsDiagnosticListener.cs 90.14% <100.00%> (ø)
...plementation/HttpWebRequestActivitySource.netfx.cs 82.60% <81.81%> (-0.12%) ⬇️

... and 6 files with indirect coverage changes

@vishweshbankwar vishweshbankwar marked this pull request as ready for review November 11, 2023 00:01
@vishweshbankwar vishweshbankwar requested a review from a team as a code owner November 11, 2023 00:01
Copy link

@antonfirsov antonfirsov left a comment

Choose a reason for hiding this comment

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

Conceptually LGTM, I'm not familiar with implementation details.

@cijothomas
Copy link
Member

[5]: network.protocol.version refers to the version of the protocol used and might be different from the protocol client's version. If the HTTP client has a version of 0.27.2, but sends HTTP version 1.1, this attribute should be set to 1.1.

The above wording from https://github.com/open-telemetry/semantic-conventions/blob/main/docs/http/http-metrics.md#metric-httpclientrequestduration, does not mention that this attribute will not be set if no response received. Should we clarify it ? What if the otel convention is expecting to populate the client's version in such case, instead of not populating at all?

@antonfirsov
Copy link

What if the otel convention is expecting to populate the client's version in such case, instead of not populating at all?

The spec says it's Recommended (vs Required), which in my understanding means that an implementation is allowed to omit it with an explanation.

@cijothomas
Copy link
Member

What if the otel convention is expecting to populate the client's version in such case, instead of not populating at all?

The spec says it's Recommended (vs Required), which in my understanding means that an implementation is allowed to omit it with an explanation.

I suggest we need to clarify it from semantic conventions. It does not say "Recommended. Populate if a response is obtained, else omit"... Given it clarifies those for certain other attributes, its best to clarify instead of assuming.

Optional attributes can cause issues like this open-telemetry/semantic-conventions#492, so want to make this sure this is not falling into that category from sem. convention standpoint, but only from .NET implementation only.

@vishweshbankwar
Copy link
Member Author

What if the otel convention is expecting to populate the client's version in such case, instead of not populating at all?

The spec says it's Recommended (vs Required), which in my understanding means that an implementation is allowed to omit it with an explanation.

I suggest we need to clarify it from semantic conventions. It does not say "Recommended. Populate if a response is obtained, else omit"... Given it clarifies those for certain other attributes, its best to clarify instead of assuming.

Optional attributes can cause issues like this open-telemetry/semantic-conventions#492, so want to make this sure this is not falling into that category from sem. convention standpoint, but only from .NET implementation only.

I have opened open-telemetry/semantic-conventions#520 to get the clarification.

@vishweshbankwar
Copy link
Member Author

While we wait for the spec clarity, I think it is ok to consider getting this change merged. Because, in our current state we are not setting the version correctly and this PR is addressing that part.

@cijothomas
Copy link
Member

While we wait for the spec clarity, I think it is ok to consider getting this change merged. Because, in our current state we are not setting the version correctly and this PR is addressing that part.

Please put a TODO in the metrics instrumentation code linking to the spec issue, and proceed with this PR.

Copy link
Member

@cijothomas cijothomas left a comment

Choose a reason for hiding this comment

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

Looks good. We may need adjustment based on clarifications, if any, arising from semantic conventions.

@vishweshbankwar
Copy link
Member Author

@@ -267,6 +269,7 @@ private static void AddExceptionTags(Exception exception, Activity activity, out

if (tracingEmitNewAttributes)
{
activity.SetTag(SemanticConventions.AttributeNetworkProtocolVersion, HttpTagHelper.GetProtocolVersionString(protocolVersion));
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this meant to be set twice?
It's set here (line 272) in the AddExceptionTags and also the out parameter is used to set it again at Line 543.

It's also odd to me that it's being set in the AddExceptionTags helper method. This may be a candidate for refactor in the future.

Copy link
Member Author

Choose a reason for hiding this comment

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

line 543 sets it on metric.

Copy link
Contributor

@utpilla utpilla left a comment

Choose a reason for hiding this comment

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

HttpWebRequestActivitySource.netfx.cs needs to be refactored to make the code simpler to follow. Not blocking this PR.

@utpilla utpilla merged commit e904994 into open-telemetry:main Nov 15, 2023
70 checks passed
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.

network.protocol.version - Should it be request.version or response.version?
5 participants