-
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
Replace SpanBuilder#wrapResource
API
#273
Conversation
9da52cb
to
35bd769
Compare
there is an argument that the entirety of |
ec21382
to
e8b6044
Compare
Looking at this some more, the only way to directly access the |
I'm firmly against removing For example, I can do the following: tracer.span("my-span").use { span =>
for {
isSuccess <- someLogic
_ <- span.addAttribute(Attribute("success", isSuccess))
} yield ()
} With |
java/trace/src/main/scala/org/typelevel/otel4s/java/trace/SpanBuilderImpl.scala
Outdated
Show resolved
Hide resolved
I like the direction. The moment we limited tracing to Local semantics, If someone needs it, a similar tracing (acquire, use, release) can be achieved with a few lines utility method. |
pushed a commit where
I think I agree that it's still worth keeping edit: they cannot be |
.spanResource("Start up") | ||
.use { case (_, nt /* natural transformation */ ) => | ||
for { | ||
_ <- nt(tracer.span("acquire").surround(IO.sleep(50.millis))) | ||
_ <- nt { | ||
tracer.span("use").surround { | ||
userIdAlg | ||
.getAllUsersForInstitution( | ||
"9902181e-1d8d-4e00-913d-51532b493f1b" | ||
) | ||
.flatMap(IO.println) | ||
} | ||
} | ||
_ <- nt(tracer.span("release").surround(IO.sleep(100.millis))) | ||
} yield () | ||
} |
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 concerned that my original commit implemented this incorrectly (before I'd quite understood things), but nothing caught it. is there a way we can run the examples and make sure they're correct?
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.
Hmm. sbt-doctest can make unit tests out of scaladoc comments, but I don't know of anything that tests the output of examples.
I've pretty much done the simplification (you can see it at https://github.com/NthPortal/otel4s/tree/Tracer-simplify/R1), but I'm holding off on PRing it until everything is hashed out in this PR |
In Natchez, there's a near 1:1 relationship between things you can do on a span and things you can do on a |
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.
Nice work!
core/trace/src/main/scala-2/org/typelevel/otel4s/trace/TracerMacro.scala
Outdated
Show resolved
Hide resolved
.spanResource("Start up") | ||
.use { case (_, nt /* natural transformation */ ) => | ||
for { | ||
_ <- nt(tracer.span("acquire").surround(IO.sleep(50.millis))) | ||
_ <- nt { | ||
tracer.span("use").surround { | ||
userIdAlg | ||
.getAllUsersForInstitution( | ||
"9902181e-1d8d-4e00-913d-51532b493f1b" | ||
) | ||
.flatMap(IO.println) | ||
} | ||
} | ||
_ <- nt(tracer.span("release").surround(IO.sleep(100.millis))) | ||
} yield () | ||
} |
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.
Hmm. sbt-doctest can make unit tests out of scaladoc comments, but I don't know of anything that tests the output of examples.
Hm, it's a nice question. We can keep some conversation here #89, to make things easier |
core/trace/src/main/scala/org/typelevel/otel4s/trace/SpanOps.scala
Outdated
Show resolved
Hide resolved
java/trace/src/test/scala/org/typelevel/otel4s/java/trace/TracerSuite.scala
Outdated
Show resolved
Hide resolved
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 like the current changes, thanks for the contribution!
There are a few leftovers (e.g. remove Result
type member, etc) I can take care of.
too late ;) |
core/trace/src/main/scala-2/org/typelevel/otel4s/trace/TracerMacro.scala
Outdated
Show resolved
Hide resolved
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.
Looks good. Only one change is up for discussion.
core/trace/src/main/scala/org/typelevel/otel4s/trace/SpanOps.scala
Outdated
Show resolved
Hide resolved
core/trace/src/main/scala/org/typelevel/otel4s/trace/Tracer.scala
Outdated
Show resolved
Hide resolved
@@ -105,9 +136,3 @@ trait SpanOps[F[_]] { | |||
*/ | |||
def surround[A](fa: F[A]): F[A] |
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.
this can still be final ... = use(_ => fa)
, will change momentarily
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.
It's not final on Resource
itself. I wonder whether that implies possible optimizations. But I can't imagine any offhand.
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.
technically you can optimise the no-op implementation slightly by not creating a wrapper Function1
around the F[A]
to pass to use
, but honestly I still feel it's cleaner to have it be final. it can be made not final in a minor release if minds are changed later. or someone can make a PR after this is merged. or if others also want it non-final, I can add another fixup commit to this PR
core/trace/src/main/scala/org/typelevel/otel4s/trace/SpanOps.scala
Outdated
Show resolved
Hide resolved
if no one else has any objections within a couple days, I'll autosquash so this can be ready to merge |
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.
This is tremendous, both the code and review discussion. I should take vacations more often!
Replace `SpanBuilder#wrapResource` with `SpanOps#resource:Resource[F,F~>F]`, which no longer automatically provides 'acquire', 'use' and 'release' spans. This API change allows further simplification of the API in future commits.
Add `SpanOps.Res` type for the return type of `SpanOps#resource`, for clearer, more evolvable and more documentable API.
b50c18c
to
caeea8d
Compare
Thanks for the contribution @NthPortal! |
@iRevive thank you for reviewing this PR and collaborating with me! |
Replace
SpanBuilder#wrapResource
withSpanOps#resource:Resource[F,F~>F]
, which no longer automaticallyprovides 'acquire', 'use' and 'release' spans.
This API change allows further simplification of the API in future commits.
This PR is a follow-up to the discussion on #261.
rebase -i --autosquash
before merge