typelevel / otel4s

An OpenTelemetry library for Scala based on Cats-Effect
https://typelevel.org/otel4s
Apache License 2.0
162 stars 30 forks source link

IO(doStuff).trace("", Attributes(...)) syntax #536

Open lhns opened 4 months ago

lhns commented 4 months ago

trace4cats has this nice extension syntax that allows to introduce tracing into a code base without adding much clutter:

IO(doStuff).trace("", Attributes(...))

I would love for something like this to be in otel4s but it would add another way to do things.

iRevive commented 4 months ago

That could be useful.

@NthPortal what do you think? Do you have similar use cases at work?

I guess we can make extension syntax available via imports:

import org.typelevel.otel4s.metrics.syntax._ // metrics only syntax
import org.typelevel.otel4s.trace.syntax._ // trace only syntax
import org.typelevel.otel4s.syntax._ // metrics and trace syntax
NthPortal commented 4 months ago

originally I was going to say that I don't object particularly, but I realised that it would require another set of macros (or lose the optimisation), so I'm not sure if it's a great idea

lhns commented 4 months ago

Maybe a scala-3-only inline def?

iRevive commented 4 months ago

We already have macro definitions for both Scala 2 and Scala 3. With some refactoring, we can make it work.

As I mentioned here, perhaps we can launch experimental modules with no guarantee of binary compatibility.