Skip to content

Instantly share code, notes, and snippets.

@GregMefford
Created May 24, 2019 18:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GregMefford/0155b5350128d70dd82cb90e3383b97a to your computer and use it in GitHub Desktop.
Save GregMefford/0155b5350128d70dd82cb90e3383b97a to your computer and use it in GitHub Desktop.
Spandex Asynchronous Tracing Example
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