-
Notifications
You must be signed in to change notification settings - Fork 722
otelhttptrace: fix false positive errors in otelhttptrace for http.receive span #8299
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
base: main
Are you sure you want to change the base?
Conversation
492a3b1 to
8320979
Compare
|
@dmathieu Since this PR has a pending CLA label, here's a FYI that I signed it. This PR can now be reviewed |
| // this error is passed to the PutIdleConn callback when http.Transport's HTTP 1.1 connection pool is full | ||
| // It's not an error per se, but rather a control flow error used for connection pooling logic in net/http internals | ||
| // corresponds to errTooManyIdleHost in net/http/internal/transport.go | ||
| const poolReturnErr = "too many idle connections" |
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.
Could you move those constants at the package level?
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.
done
| // non-nil err in this callback is one of the following net/http errors: errTooManyIdleHost, errBrokenConn, errCloseIdle | ||
| // All of those are internal. No reason to mark the span as error if we encounter them | ||
| // net/http doesn't export said errors, so we can only match against their strings | ||
| if strings.Contains(err.Error(), poolReturnErr) || |
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.
Doing ct.end twice is a bit misleading.
How about checking for err == nil in this condition as well?
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.
done
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #8299 +/- ##
=====================================
Coverage 82.3% 82.3%
=====================================
Files 193 193
Lines 13769 13779 +10
=====================================
+ Hits 11334 11344 +10
Misses 2030 2030
Partials 405 405
🚀 New features to boost your workflow:
|
|
This will need a changelog entry. |
Added one in the recent commit |
9931da9 to
b18867d
Compare
b18867d to
6b277bc
Compare
|
@dmathieu FYI: I've implemented the changes proposed by code review |
Related issue: #8216
Problem
We use httptrace for our http client. Very frequently we observe traces being marked as "error" due to "http: putIdleConn: too many idle connections for host" in the http.receive span.
This error is a part of an internal mechanism in net/http to pool http connections.
Transport keeps a per-host pool of idle keep-alive sockets.
In tryPutIdleConn, after a request finishes, the connection is returned to that pool. If the pool already holds MaxIdleConnsPerHost entries (default 2 if you don’t override it), the function returns errTooManyIdleHost, and the connection is immediately closed instead of being cached.
This is not a client issue and not even an error(just a part of the pooling flow) and shouldn't mark traces as erroring
Implementation
In this PR, we explicitly ignore the errors that can be passed by http.Transport to the PutIdleConn callback(which is used by ClientTrace). Since the errors are unexported, we have to match the error strings.
I've also added tests for two of three possible erorrs. The third one, errCloseIdle cannot be reliably reproduced in tests without introduing a flaky test, so I decided to omit the test for it.