update HttpSemanticConventions for Instrumentation.Http (part2)#4639
update HttpSemanticConventions for Instrumentation.Http (part2)#4639utpilla merged 21 commits intoopen-telemetry:mainfrom TimothyMothra:4484_http2
Conversation
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #4639 +/- ##
==========================================
+ Coverage 84.94% 84.99% +0.04%
==========================================
Files 314 314
Lines 12689 12706 +17
==========================================
+ Hits 10779 10799 +20
+ Misses 1910 1907 -3
|
| private static void VerifyActivityStartTags(string netPeerName, int? netPeerPort, string method, string url, Activity activity) | ||
| { | ||
| // New | ||
| Assert.NotNull(activity.TagObjects); | ||
| Assert.Equal(method, activity.GetTagValue(SemanticConventions.AttributeHttpRequestMethod)); | ||
| if (netPeerPort != null) | ||
| { | ||
| Assert.Equal(netPeerPort, activity.GetTagValue(SemanticConventions.AttributeServerPort)); | ||
| } | ||
|
|
||
| Assert.Equal(netPeerName, activity.GetTagValue(SemanticConventions.AttributeServerAddress)); | ||
|
|
||
| Assert.Equal(url, activity.GetTagValue(SemanticConventions.AttributeUrlFull)); | ||
|
|
||
| // Old | ||
| Assert.NotNull(activity.TagObjects); | ||
| Assert.Equal(method, activity.GetTagValue(SemanticConventions.AttributeHttpMethod)); | ||
| if (netPeerPort != null) | ||
| { | ||
| Assert.Equal(netPeerPort, activity.GetTagValue(SemanticConventions.AttributeNetPeerPort)); | ||
| } | ||
|
|
||
| Assert.Equal(netPeerName, activity.GetTagValue(SemanticConventions.AttributeNetPeerName)); | ||
|
|
||
| Assert.Equal(url, activity.GetTagValue(SemanticConventions.AttributeHttpUrl)); | ||
| } | ||
|
|
||
| private static void VerifyActivityStopTags(int statusCode, Activity activity) | ||
| { | ||
| // New | ||
| Assert.Equal(statusCode, activity.GetTagValue(SemanticConventions.AttributeHttpResponseStatusCode)); | ||
|
|
||
| // Old | ||
| Assert.Equal(statusCode, activity.GetTagValue(SemanticConventions.AttributeHttpStatusCode)); | ||
| } |
There was a problem hiding this comment.
These are the new validation methods
| private static void VerifyActivityStartTags(string netPeerName, int? netPeerPort, string method, string url, Activity activity) | ||
| { | ||
| Assert.NotNull(activity.TagObjects); | ||
| Assert.Equal(method, activity.GetTagValue(SemanticConventions.AttributeHttpRequestMethod)); | ||
| if (netPeerPort != null) | ||
| { | ||
| Assert.Equal(netPeerPort, activity.GetTagValue(SemanticConventions.AttributeServerPort)); | ||
| } | ||
|
|
||
| Assert.Equal(netPeerName, activity.GetTagValue(SemanticConventions.AttributeServerAddress)); | ||
|
|
||
| Assert.Equal(url, activity.GetTagValue(SemanticConventions.AttributeUrlFull)); | ||
| } | ||
|
|
||
| private static void VerifyActivityStopTags(int statusCode, Activity activity) | ||
| { | ||
| Assert.Equal(statusCode, activity.GetTagValue(SemanticConventions.AttributeHttpResponseStatusCode)); | ||
| } |
There was a problem hiding this comment.
These are the new validation methods
There was a problem hiding this comment.
Copying the entire test file doesn't look right. We really only need to test the new/dupe attributes for just the happy-path scenario. Could you check the attributes only for the happy-path case?
There was a problem hiding this comment.
This is the same approach we took for the AspNetCore library.
I can work on a new test that just evaluates the happy-path.
There was a problem hiding this comment.
I need more time for this. The attribute changes affect 3 different methods and there's not one test scenario that calls all three. I should have new tests by the end of today (Wed).
There was a problem hiding this comment.
A separate class is going to be necessary.
I tried adding a new test to the existing class, but because this is working with static objects, it breaks the other tests in this class.
There was a problem hiding this comment.
Discussed with Utkarsh, going to keep the separate test classes to avoid impacting the existing tests.
New classes will scope down to a single test.
| activity.SetTag(SemanticConventions.AttributeNetPeerName, request.RequestUri.Host); | ||
| if (!request.RequestUri.IsDefaultPort) | ||
| // see the spec https://github.com/open-telemetry/opentelemetry-specification/blob/v1.20.0/specification/trace/semantic_conventions/http.md | ||
| if (Options.HttpSemanticConvention.HasFlag(HttpSemanticConvention.Old)) |
There was a problem hiding this comment.
These could be extracted into boolean variables to avoid checking them repeatedly. This can be done in another PR.
There was a problem hiding this comment.
The pattern used in the other libraries won't work here because this is a static class.
There was a problem hiding this comment.
Interesting. I'm not sure why this class uses a static instance of the options.
However, you should still be able to extract them into static bool variables in this case and use them instead of checking if the enum has a flag repeatedly.
There was a problem hiding this comment.
Not just a static instance of the options, the entire class is static.
I changed the Options field to a property so I can use the setter to evaluate the booleans in this commit: b91509e
|
Need to update the existing CHANGELOG entry with this PR. It looks like we missed to add the previous PR in the CHANGELOG entry: |
|
I've corrected the links to the spec (new repo) in all comments and changelog. |
Design discussion issue #4484
Follow up to #4538
Previous PR updated Net Core implementation.
This PR makes the same changes for Net Fx.
Changes
Instrumentation.HttpHttpWebRequestActivitySource.netfx.csto emit new attributesThis was introduced in the previous PR. This is for server spans only, not client.
For review, pay attention to the helper methods at the bottom of the class near Line 200
VerifyActivityStartTags()andVerifyActivityStopTags()HttpWebRequestActivitySourceTestsNew.netfx.csto test the new attributes.This class can replace
HttpWebRequestActivitySourceTests.netfx.cswhen this library is GA.HttpWebRequestActivitySourceTestsDupe.netfx.csto test emitting both new and old attributes.This class can be deleted when this library is GA.
Merge requirement checklist
CHANGELOG.mdfiles updated for non-trivial changes