Closed NthPortal closed 1 month ago
If the Tracer
is noop, the noop SpanBuilder will be used under the hood. However, more is needed to solve the allocation problem.
What if we make addAttribute(s)
arguments call-by-name?
No attributes will be allocated if the Tracer
is noop:
val spanOps =
t.spanBuilder("server foo bar")
.withSpanKind(SpanKind.Server)
.addAttributes(Attribute("foo", "bar"))
.build
We can also use a macro, but it would be slightly more complicated.
Ah, we cannot use call-by-name with the varargs. So macro is the only choice.
While we can add a spanKind
to the tracer, it would be beneficial to have a truly zero-allocation noop SpanBuilder, I believe.
I can take care of the macro part.
because the
Tracer
macros do not support setting theSpanKind
, if you want to set theSpanKind
and also avoid creatingAttribute
s when theTracer
is disabled, you need to faff about with conditionals andTracer#meta
a bunch. for example:it's annoying and makes the code substantially less readable. it might seem a little bloaty, but I think we can add support for
SpanKind
to theTracer
macros without too much extra effort or code to maintain. I intend to work on this shortly (though it's stealable if someone wants)