async-http-client icon indicating copy to clipboard operation
async-http-client copied to clipboard

async functions don't add request ID metadata

Open 0xTim opened this issue 4 months ago • 3 comments

When sending an HTTPClient.Request it sets metadata on the logger, such as ahc-request-id. When using HTTPClientRequest (i.e. using the async APIs) this metadata is not set on the logger.

0xTim avatar Aug 19 '25 21:08 0xTim

Yeah this looks like an oversight. I think it should be fairly easy for someone who isn't me to fix this issue, but I'll try to schedule some time for it.

Lukasa avatar Aug 27 '25 13:08 Lukasa

I took a look at this and wrote a fix here https://github.com/swift-server/async-http-client/compare/main...ptoffy:async-http-client:add-logger-metadata. However, I think there's a bigger issue here because while the logger is propagated correctly through the execution pipeline, it is never actually used and no logs are emitted at all. In fact if you run the test I've added it fails because there's no logs being collected. I'm not sure if this is intentional or not, but since HTTPClient.Request does log stuff it does seem like an oversight. I've got a reproducer here https://github.com/ptoffy/ahc-logging-test, happy to open a separate issue about this

ptoffy avatar Aug 29 '25 10:08 ptoffy

That seems like a bug worth filing all of its own. We'd appreciate committing the test too!

Lukasa avatar Aug 29 '25 11:08 Lukasa