-
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
refactor(fetch): revert to original code in endSpanOnSuccess #3037
Conversation
); | ||
assert.strictEqual( | ||
attributes[keys[2]], | ||
redirectedUrl, |
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.
Does it make sense that the http.url
attribute's value is the url before the redirection, but http.host
is the host after the redirection? Feels strange.
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, you're right, it does indeed feel strange. As far as I can tell, it also does not follow the spec. There it states that:
Retries and redirects cause more than one physical HTTP request to be sent. A CLIENT span SHOULD be created for each one of these physical requests. No span is created corresponding to the "logical" (encompassing) request.
It looks like to me that we'd need to instrument fetch in a way that it creates spans on each redirect (in that case host.host
and http.url
should be the same). However, I have to admit that I do not know enough about the internals of fetch
right now to come up with a way to implement that. We should create an issue to track this, though.
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.
Since the discrepancy is introduced by this change, a better fix for now should be to just remove spanResponse
variable, and then implement proper redirection spans.
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.
Sounds good. If there's a way to create proper redirection spans we should do it 👍
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.
Doesn't look like it is possible, sadly.
Redirects are not exposed to APIs: https://fetch.spec.whatwg.org/#atomic-http-redirect-handling
There's a manual
redirect mode, but it can't be used in any useful way.
"manual"
Retrieves an opaque-redirect filtered response when a request is met with a redirect, to allow a service worker to replay the redirect offline. The response is otherwise indistinguishable from a network error, to not violate atomic HTTP redirect handling.
An opaque-redirect filtered response is a filtered response whose type is "opaqueredirect", status is 0, status message is the empty byte sequence, header list is empty, and body is null.
c653bd4
to
bd01667
Compare
Codecov Report
@@ Coverage Diff @@
## main #3037 +/- ##
==========================================
+ Coverage 93.09% 93.10% +0.01%
==========================================
Files 195 195
Lines 6386 6384 -2
Branches 1349 1348 -1
==========================================
- Hits 5945 5944 -1
+ Misses 441 440 -1
|
63a498f
to
f9ee378
Compare
@pichlermarc looks like you originally introduced this object in #2871 please look at this |
@Ugzuzg you're right, it does not make sense. I committed this by mistake in #2871. 😞 The code here is actually supposed to be the original code:
Back then, I must have been trying to figure out what caused the I can create a fix, or you can do it with this PR. |
@pichlermarc, the current change in the pull request behaves in the same way you're describing (with the addition of |
f9ee378
to
a635275
Compare
@Ugzuzg As it behaves the same I think we can keep this as is, thanks for working on this! 🙂 |
a635275
to
077d9fa
Compare
); | ||
assert.strictEqual( | ||
attributes[keys[2]], | ||
redirectedUrl, |
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, you're right, it does indeed feel strange. As far as I can tell, it also does not follow the spec. There it states that:
Retries and redirects cause more than one physical HTTP request to be sent. A CLIENT span SHOULD be created for each one of these physical requests. No span is created corresponding to the "logical" (encompassing) request.
It looks like to me that we'd need to instrument fetch in a way that it creates spans on each redirect (in that case host.host
and http.url
should be the same). However, I have to admit that I do not know enough about the internals of fetch
right now to come up with a way to implement that. We should create an issue to track this, though.
077d9fa
to
229d902
Compare
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.
Looks great! 🙂 Thanks for bringing this up and taking the time to fix it! 🙂
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.
Most of my comments have the same theme. The impl looks fine but the tests you added are very hard to read because of the indirect way you are accessing attribute values.
experimental/packages/opentelemetry-instrumentation-fetch/test/fetch.test.ts
Outdated
Show resolved
Hide resolved
experimental/packages/opentelemetry-instrumentation-fetch/test/fetch.test.ts
Outdated
Show resolved
Hide resolved
experimental/packages/opentelemetry-instrumentation-fetch/test/fetch.test.ts
Outdated
Show resolved
Hide resolved
experimental/packages/opentelemetry-instrumentation-fetch/test/fetch.test.ts
Outdated
Show resolved
Hide resolved
229d902
to
d8fb4f7
Compare
Nonblocking: an update to the PR title will be most helpful. |
experimental/packages/opentelemetry-instrumentation-fetch/src/fetch.ts
Outdated
Show resolved
Hide resolved
47ab8c2
to
de5270b
Compare
Not really a fix. I would retitle to |
de5270b
to
e9d7830
Compare
I meant the PR title not so much the commit 😄 |
Which problem is this PR solving?
This
spanResponse
object is not used for anything, and I can't figure out its purpose:opentelemetry-js/experimental/packages/opentelemetry-instrumentation-fetch/src/fetch.ts
Lines 324 to 334 in 0213d82
The override doesn't make sense, as it sets the same value already present in the initialised object:
opentelemetry-js/experimental/packages/opentelemetry-instrumentation-fetch/src/fetch.ts
Lines 330 to 334 in 0213d82
I have amended the code to what I think makes sense and was the original intention. Opening a PR to have a discussion.
Short description of the changes
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
Checklist: