-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
core-trace: SpanBuilder
use macro to preserve laziness
#734
Conversation
1cc19cb
to
61b69fd
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I love this. on the surface, it seems like we've made things much more complicated, but:
- no more
Tracer.Meta
- substantial deduplication of
SpanBuilder
implementations - huge simplification of the Scala 3
TracerMacro
core/common/src/main/scala/org/typelevel/otel4s/meta/InstrumentMeta.scala
Outdated
Show resolved
Hide resolved
|
||
// if the optimization is not applied, the compilation will fail with | ||
// Method too large: org/typelevel/otel4s/... | ||
// Scala 3 compiler optimizes chained calls out of the box |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's very kind of them
@@ -59,7 +58,7 @@ private[otel4s] trait TracerMacro[F[_]] { | |||
inline name: String, | |||
inline attributes: Attribute[_]* | |||
): SpanOps[F] = | |||
${ TracerMacro.span('self, 'name, 'attributes) } | |||
spanBuilder(name).addAttributes(attributes).build |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I love how the only sense in which this is even a macro now is that everything is inline
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, exactly. Scala 3 macro feels much better now.
d0078b6
to
daae6f7
Compare
daae6f7
to
22ff66b
Compare
Fixes #725.
Let's take a look at how the following code will be unwrapped:
Scala 2 (chained calls are optimized manually by the macro):
The Scala 3 chained calls aren't optimized:
It's not the end of the world for Scala 3, JIT compiler will inline the if statements in the runtime, but still sad that we produce non-optimized code.
Pros
Cons