-
Notifications
You must be signed in to change notification settings - Fork 825
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
fix(instrumentation-fetch, instrumentation-xml-http-request) content length attributes now prese #5230
Conversation
Other options exploredWe explored several other options in trying to solve this issue. Exposing a new helper method, refactoring the content length attribute code to fetch and http and our preferred method one where we passed a flag down through a parameter. New Helper methodIn this option we exposed a new helper method to handle the content length attributes. This would then be called from both the /**
* Helper function for adding content length attributes to a network span
* @param span
* @param resource
*/
export function addSpanContentLengthAttributes(
span: api.Span,
resource: PerformanceEntries
): void {
const encodedLength = resource[PTN.ENCODED_BODY_SIZE];
if (encodedLength !== undefined) {
span.setAttribute(SEMATTRS_HTTP_RESPONSE_CONTENT_LENGTH, encodedLength);
}
const decodedLength = resource[PTN.DECODED_BODY_SIZE];
// Spec: Not set if transport encoding not used (in which case encoded and decoded sizes match)
if (decodedLength !== undefined && encodedLength !== decodedLength) {
span.setAttribute(
SEMATTRS_HTTP_RESPONSE_CONTENT_LENGTH_UNCOMPRESSED,
decodedLength
);
}
} This would be called as such inside the if (!this.getConfig().ignoreNetworkEvents) {
addSpanNetworkEvents(childSpan, corsPreFlightRequest);
} else {
addSpanContentLenthAttributes(childSpan, corsPreFlightRequest);
} Pros:
Cons:
Moving logic into librariesThis involved moving the logic that adds content length attributes into the private _findResourceAndAddNetworkEvents(
xhrMem: XhrMem,
span: api.Span,
spanUrl?: string,
startTime?: api.HrTime,
endTime?: api.HrTime
): void {
//...
if (!this.getConfig().ignoreNetworkEvents) {
addSpanNetworkEvents(span, mainRequest);
}
this._addSpanContentLenthAttributes(span, mainRequest);
}
}
/**
* Add content length attributes to a network span
* @param span
* @param resource
*/
private _addSpanContentLenthAttributes(
span: api.Span,
resource: PerformanceEntries
): void {
const encodedLength = resource[PTN.ENCODED_BODY_SIZE];
if (encodedLength !== undefined) {
span.setAttribute(SEMATTRS_HTTP_RESPONSE_CONTENT_LENGTH, encodedLength);
}
const decodedLength = resource[PTN.DECODED_BODY_SIZE];
// Spec: Not set if transport encoding not used (in which case encoded and decoded sizes match)
if (decodedLength !== undefined && encodedLength !== decodedLength) {
span.setAttribute(
SEMATTRS_HTTP_RESPONSE_CONTENT_LENGTH_UNCOMPRESSED,
decodedLength
);
}
} Pros:
Cons:
Adding optional parameter to disable network events (Chosen)We move the logic from the calls to the method into the Pros:
Cons:
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #5230 +/- ##
==========================================
+ Coverage 94.60% 94.65% +0.05%
==========================================
Files 315 315
Lines 8011 8012 +1
Branches 1617 1617
==========================================
+ Hits 7579 7584 +5
+ Misses 432 428 -4 |
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.
thanks for fixing this 🙂
semantic-conventions/CHANGELOG.md
Outdated
* bug: content length attributes no longer get removed with `ignoreNetworkEvents: true` being set [#5229](https://github.com/open-telemetry/opentelemetry-js/issues/5229) | ||
|
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.
ah, that's the wrong changelog - it should go into CHANGELOG.md
in the repository root 🙂
*/ | ||
export function addSpanNetworkEvents( | ||
span: api.Span, | ||
resource: PerformanceEntries | ||
resource: PerformanceEntries, | ||
ignoreNetworkEvents = false |
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.
hmm, that's really unfortunate.
I'd really like to avoid carrying this forward to 2.0 - @arriIsHere would you mind opening a follow-up PR towards the next
branch later to implement option 1 "new helper method" from this comment there? It adds one more function but we'll be able to get rid of the body-size side-effect in this function, which I think cleans it up a bit.
I plans to move @opentelemetry/instrumentation-xhr
and @opentelemetry/instrumentation-fetch
into the same package as a follow up, which may even let us drop these functions from the public API of @opentelemetry/sdk-trace-web
since they're not really SDK functions. That'd also go a long way of discouraging the anti-pattern of direct depending on the SDK for instrumentation.
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.
Absolutely! I can finish that up this morning.
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.
awesome, thank you 🙂
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.
@pichlermarc opened #5257 against next
Which problem is this PR solving?
http.response_content_length
andhttp.response_content_length_uncompressed
attributes are not present on network spans frominstrumentation-xml-http-request
andinstrumentation-fetch
plugins when theignoreNetworkEvents
configuration property is set totrue
This PR changes
addSpanNetworkEvents
to include the options to skip over adding network events but still include the previously mentioned properties.Fixes #5229
Short description of the changes
By skipping over the call to
addSpanNetworkEvents
the mentioned attributes were not getting added to the main and preflight network spans. We move the logic from the calls to the method into theaddSpanNetworkEvents
call itself with a third boolean parameter. This will disable adding network events spans while still adding the attributes.While fixing this we considered several different changes, we went with adding an optional paramiter to
addSpanNetworkEvents
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
Automated unit tests were written as well as testing with the fetch and xhr examples to verify the attributes are being added with the proposed code.
Checklist: