Skip to content

Instantly share code, notes, and snippets.

@tsloughter
Last active January 29, 2021 20:31
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 tsloughter/ddd8653dc245b88c9d612fc5d85fe4e2 to your computer and use it in GitHub Desktop.
Save tsloughter/ddd8653dc245b88c9d612fc5d85fe4e2 to your computer and use it in GitHub Desktop.
test "create child Span in Task" do
:otel_batch_processor.set_exporter(:otel_exporter_pid, self())
OpenTelemetry.register_tracer(:test_tracer, "0.1.0")
# create the parent span
parent = Tracer.start_span("parent")
# make a new context with it as the active span
ctx = Tracer.set_current_span(Ctx.new(), parent)
# attach this context (put it in the process dictionary)
Ctx.attach(ctx)
# start the child and set it to current in an unattached context
child = Tracer.start_span("child")
ctx = Tracer.set_current_span(ctx, SpanCtx)
task = Task.async(
fn ->
# attach the context with the child span active to this process
Ctx.attach(ctx)
Span.end_span(child)
:hello
end)
ret = Task.await(task)
assert :hello = ret
span_ctx(span_id: parent_span_id) = Span.end_span(parent)
assert_receive {:span,
span(
name: "child",
parent_span_id: ^parent_span_id
)}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment