-
Notifications
You must be signed in to change notification settings - Fork 765
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
update HttpSemanticConventions for Instrumentation.Http (part2) #4639
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
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are the new validation methods
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The pattern used in the other libraries won't work here because this is a static class.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.Http
HttpWebRequestActivitySource.netfx.cs
to 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.cs
to test the new attributes.This class can replace
HttpWebRequestActivitySourceTests.netfx.cs
when this library is GA.HttpWebRequestActivitySourceTestsDupe.netfx.cs
to test emitting both new and old attributes.This class can be deleted when this library is GA.
Merge requirement checklist
CHANGELOG.md
files updated for non-trivial changes