zio / zio-telemetry

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

OpenTelemetry span for ZStream #728

Open senia-psm opened 1 year ago

senia-psm commented 1 year ago

It is impossible to implement a proper span for a ZStream returning method.

It requires a version of Tracing::span for Zstream instead of ZIO.

grouzen commented 1 year ago

It may be related to https://github.com/zio/zio-telemetry/issues/722

grouzen commented 1 year ago

Tracing.spanScoped has been added recently in https://github.com/zio/zio-telemetry/pull/709. There is also a Discord thread with a discussion about it https://discord.com/channels/629491597070827530/639825316021272602/1113090265041862697. I mean, it could be a solution for your case, but I'm not sure exactly what issue you have. It would be nice if you added more context. Thanks!

senia-psm commented 1 year ago

@grouzen thank you for the update. The feature is merged in series/2.x, but I can;t find 2.x version with this feature. Are there any plans of publishing this feature?

For me it might be not enough (but there is a workaround - see below) - I have ZStream on top level, so I need the same option, but for spanFrom (spanFromScoped?).

I believe the idea with Scope would work - we can use it in ZStream.unwrapScoped.

My use case zio-http endpoint implementation returning ZStream of bytes. It should accept W3C headers and create a span using spanFrom with parent context from headers.

Possible workaround: using ZIO[,,ZStream[...]] I can create a main span with spanFrom and then a child span with spanScoped. The parent span might get closed before the child span and we can get invalid timings, but it shoudl be good enough.

grouzen commented 1 year ago

The feature is merged in series/2.x, but I can;t find 2.x version with this feature. Are there any plans of publishing this feature?

You can find it in 3.0.0-RC14 version. 2.x in the branch name means that it is based on ZIO 2.x version.

I believe the idea with Scope would work - we can use it in ZStream.unwrapScoped.

Right.

My use case zio-http endpoint implementation returning ZStream of bytes. It should accept W3C headers and create a span using spanFrom with parent context from headers.

I see. It's been a hot topic lately :) There are more threads have been going recently in Discord related to it:

All this interest from people makes me think about adding API for ZStream. It might be a good idea.