I'm finding SpanCaptureReporter too brittle, with tests flaking out when :oc_reporter waits longer than expected and calls report/2 with spans from preceding tests after the current test calls attach/0.
Workaround:
defmodule MyApp.Module do
use ExUnit.Case, async: false
test "sends traces" do
SpanCaptureReporter.attach()
on_exit(make_ref(), &SpanCaptureReporter.detach/0)
began_monotonic = :erlang.monotonic_time()
# ... do the work ...
spans =
SpanCaptureReporter.collect()
|> Enum.filter(fn span ->
{native_time, _} = span.start_time
native_time >= began_monotonic
end)
# ... check the spans ...