-
Notifications
You must be signed in to change notification settings - Fork 821
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-http): close server span when response finishes #3407
fix(instrumentation-http): close server span when response finishes #3407
Conversation
e2a7b61
to
bca9b9a
Compare
bca9b9a
to
336e7bd
Compare
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #3407 +/- ##
==========================================
+ Coverage 92.99% 93.72% +0.72%
==========================================
Files 241 248 +7
Lines 7096 7567 +471
Branches 1494 1581 +87
==========================================
+ Hits 6599 7092 +493
+ Misses 497 475 -22
|
@open-telemetry/javascript-approvers we need more reviews here. |
Therefore this results in a behavior change because the hook called now in Also the span duration changes. Consider someone passes a large amount of data to |
Even Previously we were ending the response when the |
I haven't tested but I guess the diff can be significant if you pass a large chunk to end or write very fast to a stream and the JS stream buffers a lot data (not the kernel). |
To track user code time, people (usually web frameworks instrumentation) can create nested spans (like layers and middlewares) to track exact processing time. As the |
IIUC, in the case of connection abort after |
const http = require("http");
http.createServer((req, res) => {
console.log("onRequest")
req.on("error", (e) => console.log("REQ error:", e.message));
req.on("aborted", () => console.log("REQ aborted"));
req.on("close", () => console.log("REQ close"));
req.on("end", () => console.log("REQ end"));
res.on("error", (e) => console.log("RES error:", e.message));
res.on("close", () => console.log("RES close"));
res.on("finish", () => console.log("RES finish"));
setTimeout(() => {
console.log("calling end")
res.end();
}, 2000);
}).listen(8000);
const cltReq = http.get("http://localhost:8000");
cltReq.on("error", () => {});
setTimeout(() => cltReq.destroy(), 1000); with node 18.12.1 on windows this results in
==> no finsish nor an error event on response but a close event |
@Flarna thanks for sharing. Seems like we should distinguish early |
# Conflicts: # experimental/CHANGELOG.md # experimental/packages/opentelemetry-instrumentation-http/src/http.ts # experimental/packages/opentelemetry-instrumentation-http/test/functionals/http-enable.test.ts
@Flarna updated with test coverage on premature closes. PTAL again, thank you! |
Which problem is this PR solving?
Close server span when the
ServerResponse
emits'close'
event.Fixes #3104
Short description of the changes
ServerResponse.end()
writes data to the socket asynchronously. The span should be closed when the response has been sent.Type of change
How Has This Been Tested?
responseHook
can be used to set additional attributes whenServerResponse.end
is called.Checklist: