When instrumenting a project your application should only depend on the OpenTelemetry API application, found in directory apps/opentelemetry_api of this repo which is published as the hex package opentelemetry_api.
This is confusing - since to instrumnet my project, isn’t it supposed to use SDK, not API? e.g. SDK actually holds the implementation, and sdk depends on api, not vice versa
with_span
to the code
Aha probably the confusion is whether “application” is of the end-user project (e.g. project to run a web service), or my library package (e.g. HTTP library “application”). Is there any good terminology in Erlang?
https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/library-guidelines.md uses “final application” vs “third party libraries/frameworks” btw.
For traces to actually be tracked, propagated and exported, the opentelemetry Application must be included as a dependency of your project, likely as part of a Release and not as a dependency of an individual Application within the Release.
What’s the reason? I guess it is to start and supervise opentelemetry
application (SDK) at the top level, not a child of a specific application. Is it correct?
main
do I cause the same issue ?
Hey there :)
Playing around with Elixir I can't figure out how to set the parent span for a new span declared in an anonymous function in a Task.async
.
I tried something like this:
OpenTelemetry.Tracer.with_span "span_1" do
span_ctx = OpenTelemetry.Tracer.current_span_ctx()
task =
Task.async(fn ->
OpenTelemetry.Tracer.with_span "span_2", %{parent: span_ctx} do
nil
end
end)
...
end
But the parent option does not seem to do anything.
Can you please help me on what I am probably doing wrong here?
SpanCtx = ?start_span(<<"child">>),
Ctx = otel_ctx:get_current(),
proc_lib:start_link(fun() ->
otel_ctx:attach(Ctx),
?set_current_span(SpanCtx)
%% do work here
end),
SpanCtx = ?current_span_ctx,
proc_lib:spawn_link(fun() ->
Link = opentelemetry:link(SpanCtx),
?with_span(<<"other-process">>, #{links => [Link]},
fun() -> ok end)
end),
:undefined
when doing parent_link = OpenTelemetry.link(parent)
.
ctx = Tracer.set_current_span(ctx, SpanCtx)
by ctx = Tracer.set_current_span(ctx, parent)
and also tried to end the parent span:defmodule Test do
alias OpenTelemetry.{Ctx, Span, Tracer}
require OpenTelemetry.Tracer
def child do
parent_ctx = Ctx.new()
# create the parent span
parent = Tracer.start_span("parent")
# make a new context with it as the active span
ctx = Tracer.set_current_span(parent_ctx, 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, child)
task =
Task.async(fn ->
# attach the context with the child span active to this process
Ctx.attach(ctx)
Process.sleep(2_000)
return = :ok
Span.end_span(child)
return
end)
return = Task.await(task)
Process.sleep(1_000)
Span.end_span(parent)
return
end
end
InstrumentationLibrarySpans #0
InstrumentationLibrary
Span #0
Trace ID : afcfd96292df82aecfec73112021a913
Parent ID :
ID : 47baabdfc4371036
Name : parent
Kind : SPAN_KIND_INTERNAL
Start time : 2021-02-01 10:42:38.169498618 +0000 UTC
End time : 2021-02-01 10:42:41.182688894 +0000 UTC
Status code : STATUS_CODE_UNSET
Status message :
Span #1
Trace ID : afcfd96292df82aecfec73112021a913
Parent ID : 47baabdfc4371036
ID : 09e6b2017ab2872e
Name : child
Kind : SPAN_KIND_INTERNAL
Start time : 2021-02-01 10:42:38.174677904 +0000 UTC
End time : 2021-02-01 10:42:40.18240293 +0000 UTC
Status code : STATUS_CODE_UNSET
Status message :