-
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-experimental: add @withSpan
macro
#675
core-trace-experimental: add @withSpan
macro
#675
Conversation
9b10452
to
0edcafa
Compare
ensureImplicitExist( | ||
q"_root_.org.typelevel.otel4s.AttributeKey.KeySelect[$tpt]", | ||
e => | ||
s"the argument [${name.decodedName}] cannot be used as an attribute. The type [$tpt] is not supported.${e.getMessage}" | ||
) |
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.
Since KeySelect is sealed there's no way to define a spanAttribute
for an unsupported type, normally we'd create an Attribute manually like
case class Foo(value: String)
val attribute = Attribute("foo.value", foo.value)
This means we can't use the macro at all if we require one attribute that is unsupported. Would it be sensible to expose some way of contramapping an existing KeySelect?
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.
Though thinking about it still won't be possible without some other function from value => key type 😢
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.
Valid points. The macro wouldn't work with newtypes/type aliases.
I guess we can provide some utility methods to lift arbitrary types into the Attribute.
sorry it's taken me so long to have a look at this; I'll try to give a proper review this coming week |
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'm not really familiar enough with macros (annotation or otherwise) to give the implementations a confident approval, but the tests look correct and quite thorough to me. Nice work!
I don't quite understand the concern about case-insensitive name collision; they're in separate directories, so I'm not clear on how it would be a problem, and would personally prefer the shorter/simpler names
* the custom name of the attribute to use. If not specified, the name of the | ||
* parameter will be used | ||
*/ | ||
class spanAttribute(@unused name: String = "") extends StaticAnnotation { |
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.
should this be marked @compileTimeOnly
as well?
Closing in favor of typelevel/otel4s-experimental#1. |
An experimental implementation of the #550.
OpenTelemetry Java offers similar functionality using reflections and AOP https://opentelemetry.io/docs/languages/java/automatic/annotations/.
Before we start
The functionality exists in a separate
otel4s-core-trace-experimental
module.How it works
The body of a method annotated with
@withSpan
will be wrapped into a span:The macro works with variables too:
Summary
Pros
Cons
@spanAttribute
contributes to the visual noiseQuestions
1) Why
@withSpan
and@spanAttribute
instead of@span
and@attribute
?If I recall correctly, problems can arise in case-insensitive systems because we already have
Span
andAttribute
.However, if that is not the case, I would prefer
@span
and@attribute
.2) Should the macro capture source information?
We can easily add source attributes to the span, such as
Attribute("source.file", "some/path/Service.scala")
andAttribute("source.line", 123L)
.