open-telemetry / opentelemetry-js

OpenTelemetry JavaScript Client
https://opentelemetry.io
Apache License 2.0
2.58k stars 746 forks source link

Premature close errors at end of HTTP request #4721

Open AkselAllas opened 2 months ago

AkselAllas commented 2 months ago

Steps to Reproduce

I have 2 services where this error keeps popping up on different endpoints It's non-fatal, traces still work.

Possibly this via this

Expected Result

Log lines of

GET TO https://service.tld/path
200 GET 100ms https://service.tld/path

Actual Result

GET TO https://service.tld/path
200 GET 100ms https://service.tld/path
Premature close

Full stacktrace:

Premature close Error: Premature close
    at new NodeError (node:internal/errors:405:5)
    at ServerResponse.onclose (node:internal/streams/end-of-stream:159:30)
    at /app/node_modules/@opentelemetry/context-async-hooks/src/AbstractAsyncHooksContextManager.ts:75:49
    at AsyncLocalStorage.run (node:async_hooks:338:14)
    at AsyncLocalStorageContextManager.with (/app/node_modules/@opentelemetry/context-async-hooks/src/AsyncLocalStorageContextManager.ts:40:36)
    at ServerResponse.contextWrapper (/app/node_modules/@opentelemetry/context-async-hooks/src/AbstractAsyncHooksContextManager.ts:75:26)
    at ServerResponse.emit (node:events:529:35)
    at ServerResponse.emit (node:domain:489:12)
    at emitCloseNT (node:_http_server:1020:10)
    at Socket.onServerResponseClose (node:_http_server:278:5)
    at Socket.emit (node:events:529:35)
    at Socket.emit (node:domain:489:12)
    at TCP.<anonymous> (node:net:350:12)
    at TCP.callbackTrampoline (node:internal/async_hooks:128:17) ExpressAdapter

and

Error [ERR_STREAM_PREMATURE_CLOSE]: Premature close
    at ServerResponse.onclose (node:internal/streams/end-of-stream:159:30)
    at /app/node_modules/@opentelemetry/context-async-hooks/build/src/AbstractAsyncHooksContextManager.js:50:55
    at AsyncLocalStorage.run (node:async_hooks:346:14)
    at AsyncLocalStorageContextManager.with (/app/node_modules/@opentelemetry/context-async-hooks/build/src/AsyncLocalStorageContextManager.js:33:40)
    at ServerResponse.contextWrapper (/app/node_modules/@opentelemetry/context-async-hooks/build/src/AbstractAsyncHooksContextManager.js:50:32)
    at ServerResponse.emit (node:events:531:35)
    at ServerResponse.emit (node:domain:488:12)
    at emitCloseNT (node:_http_server:1020:10)
    at Socket.onServerResponseClose (node:_http_server:278:5)
    at Socket.emit (node:events:531:35)

OpenTelemetry Setup Code

No response

package.json

"@opentelemetry/api": "1.7.0",
"@opentelemetry/core": "1.20.0",
"@opentelemetry/instrumentation-http": "0.47.0",

Relevant log output

No response

GlennGeenen commented 1 month ago

I see the same happening, we use gaxios which also uses node-fetch.

We're on: "@opentelemetry/core": "1.22.0"