Skip to content
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

add a convenience function for span creation #1033

Merged
merged 2 commits into from
Jun 4, 2021

Conversation

ivantopo
Copy link
Contributor

@ivantopo ivantopo commented Jun 3, 2021

This PR brings a simple function to create a Span to wrap the execution of code blocks, with two special behaviors:

  • The function stores the created Span in the current context while the function is executed.
  • The function will always finish the Span after the wrapped code finishes execution, with special handling for Scala Futures and CompletionStage instances. If the wrapped code returns a Future or CompletionStage, the created Span will be finished when the returned Future/CompletionStage completes.

This function should be enough to replace the soon-to-be-deprecated functions in ScalaFutureInstrumentation. More info here: #1021.

Also, this simplifies cases where people want a simple Span for a block of code and end up having to write something like this:

Kamon.runWithSpan(Kamon.spanBuilder(....).start()) {

}

@ivantopo ivantopo requested a review from SimunKaracic June 3, 2021 18:17
@ivantopo ivantopo force-pushed the quick-span-creation-function branch from 4de0156 to 29a54d5 Compare June 3, 2021 18:23
Copy link
Contributor

@SimunKaracic SimunKaracic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, merge when ready

@ivantopo ivantopo changed the title add a convenient function for span creation add a convenience function for span creation Jun 4, 2021
}
} catch {
case NonFatal(t) =>
span.finish()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't .fail(t) be invoked before finishing the span?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's being handled by runWithSpan for this case, so no worries :)

@inline def runWithSpan[T](span: Span, finishSpan: Boolean)(f: => T): T = {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants