with_span
macro
with_span
can take a context as the first argument. so in some cases you don't need to attach the context, just do Tracer.with_span ctx, name, %{}, do ...
link
attribute will be more clean :thumbsup:
:undefined
when calling OpenTelemetry.link/1
, I still get an error during the span creationwith_span
macro: def link do
Tracer.with_span "parent" do
parent = Tracer.current_span_ctx()
task =
Task.async(fn ->
Tracer.with_span "child", %{links: [OpenTelemetry.link(parent)]} do
:hello
end
end)
Task.await(task)
end
end
{:opentelemetry_exporter_trace_service_pb, :is_empty_string, [:undefined],
[
file: '/test/deps/opentelemetry_exporter/apps/opentelemetry_exporter/src/opentelemetry_exporter_trace_service_pb.erl',
line: 928
]},
%{
...,
"opentelemetry": {:git, "https://github.com/open-telemetry/opentelemetry-erlang.git", "fc25e7a7adb0ab217f1c2616e580e49c4cea541f", [sparse: "apps/opentelemetry"]},
"opentelemetry_api": {:git, "https://github.com/open-telemetry/opentelemetry-erlang.git", "fc25e7a7adb0ab217f1c2616e580e49c4cea541f", [sparse: "apps/opentelemetry_api"]},
"opentelemetry_exporter": {:git, "https://github.com/open-telemetry/opentelemetry-erlang.git", "fc25e7a7adb0ab217f1c2616e580e49c4cea541f", [sparse: "apps/opentelemetry_exporter"]},
}
def parent do
Tracer.with_span "parent" do
parent_ctx = Ctx.get_current()
task =
Task.async(fn ->
Tracer.with_span parent_ctx, "child", %{} do
Tracer.with_span "sub child" do
Process.sleep(2_000)
end
Process.sleep(1_000)
end
end)
Task.await(task)
end
end
Produces:
InstrumentationLibrarySpans #0
InstrumentationLibrary
Span #0
Trace ID : 3590104f363edf2915ab7dea675346f7
Parent ID :
ID : d1b85fe9bb49f1a7
Name : parent
Kind : SPAN_KIND_INTERNAL
Start time : 2021-02-02 16:32:06.285669427 +0000 UTC
End time : 2021-02-02 16:32:09.28805425 +0000 UTC
Status code : STATUS_CODE_UNSET
Status message :
Span #1
Trace ID : 3590104f363edf2915ab7dea675346f7
Parent ID : d1b85fe9bb49f1a7
ID : 7d04026e36f93266
Name : child
Kind : SPAN_KIND_INTERNAL
Start time : 2021-02-02 16:32:06.2857683 +0000 UTC
End time : 2021-02-02 16:32:09.287856878 +0000 UTC
Status code : STATUS_CODE_UNSET
Status message :
Span #2
Trace ID : 3590104f363edf2915ab7dea675346f7
Parent ID : 7d04026e36f93266
ID : 7e3223982ba56037
Name : sub child
Kind : SPAN_KIND_INTERNAL
Start time : 2021-02-02 16:32:06.285813566 +0000 UTC
End time : 2021-02-02 16:32:08.286844333 +0000 UTC
Status code : STATUS_CODE_UNSET
Status message :
Which seems ok
Ctx.get_current()
what should be the first argument?
with_span
macro attaches it back at the end so any call to this GenServer with sub part containing a with_span
will get the last set context as a parent
detach
but it doesn't really have an effect on the outcome so I keep forgetting to fix that