zio / zio-telemetry

ZIO-powered OpenTelemetry library
https://zio.dev/zio-telemetry
Apache License 2.0
113 stars 55 forks source link

OpenTelemetry: integration with zio-http, parent span ends immidiately for the response stream #722

Open grouzen opened 1 year ago

grouzen commented 1 year ago

Reported in Discord channel: https://discord.com/channels/629491597070827530/639825316021272602/1120329881318862848

I am currently trying to integrate zio-http with zio-opentelemetry. While we use relatively old versions of both, I am unable to e.g. create a span for each request I receive that ends only when the response body stream completes. With several hacks I do manage to create a child span for the response stream, but the parent span ends where it begins. I come here to ask if there is an already premade solution to this, even if it necessitates an upgrade of the libraries.

grouzen commented 1 year ago

Worth trying to implement this scenario for the latest zio-http, zio-opentelemetry and zio2.

grouzen commented 1 year ago

In the original Discord thread, I suggested using ZIO Http Middleware to solve the issue and it turned out that another person took the same approach and shared his solution. Here is an example of such middleware: https://gist.github.com/tjarvstrand/aceb00102a2fa21fd6c7b6f4fe431be9. I hope it might be helpful.