Created
May 24, 2019 18:52
-
-
Save GregMefford/0155b5350128d70dd82cb90e3383b97a to your computer and use it in GitHub Desktop.
Spandex Asynchronous Tracing Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule MyApp.Tracer do | |
@moduledoc "Spandex Tracer" | |
use Spandex.Tracer, otp_app: :my_app | |
def async(func) do | |
case current_context() do | |
{:ok, tracer_ctx} -> | |
Task.async(fn -> | |
continue_trace("async", tracer_ctx, resource: "Task.async", service: :my_app_async) | |
try do | |
func.() | |
after | |
finish_trace() | |
end | |
end) | |
{:error, _reason} -> | |
Task.async(fn -> func.() end) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment