lessless

lessless

Linking OpenTelemetry spans across processes

Hi,
I’m having a bit of a hard time making sense of linking child spans from the Oban to the parent span and I hope somebody can clear that out for me.

Here is roughly the code from the first pass

span_ctx = OpenTelemetry.Tracer.start_span(:parent)
Task.async(fn ->
  link = OpenTelemetry.link(span_ctx) |> IO.inspect(label: "link")
  OpenTelemetry.Tracer.with_span :"my-task", %{links: [link]} do
    :hello
  end
end)
:otel_span.end_span(span_ctx, :undefined)

In the output, I can see that traced_id inside link matches the second item from the span_ctx tuple, but in Zipkin, those are two different traces and “my-task” doesn’t have a parent.


iex(5)> span_ctx = OpenTelemetry.Tracer.start_span(:parent)
{:span_ctx, 98688298365639109931104546606962518618, 12736530893077507678, 1, [],
 true, false, true,
 {:otel_span_ets, #Function<2.133377841/1 in :otel_tracer_server.on_end/1>}}
iex(6)> Task.async(fn ->
...(6)>   link = OpenTelemetry.link(span_ctx) |> IO.inspect(label: "link")
...(6)>   OpenTelemetry.Tracer.with_span :"my-task", %{links: [link]} do
...(6)>     :hello
...(6)>   end
...(6)> end)
link: %{
  attributes: %{},
  span_id: 12736530893077507678,
  trace_id: 98688298365639109931104546606962518618,
  tracestate: []
}
%Task{
  mfa: {:erlang, :apply, 2},
  owner: #PID<0.887.0>,
  pid: #PID<0.899.0>,
  ref: #Reference<0.3396824287.1941766146.188407>
}
iex(7)> :otel_span.end_span(span_ctx, :undefined)
{:span_ctx, 98688298365639109931104546606962518618, 12736530893077507678, 1, [],
 true, false, false,
 {:otel_span_ets, #Function<2.133377841/1 in :otel_tracer_server.on_end/1>}}
iex(8)>

Second pass

I attempted to start_span / end_span instead of with_span but the same result was the same - two uncorrelated spans



span_ctx = OpenTelemetry.Tracer.start_span(:parent) |> IO.inspect(label: "parent_ctx")
Task.async(fn ->
  link = OpenTelemetry.link(span_ctx) |> IO.inspect(label: "link")
  child_span_ctx = OpenTelemetry.Tracer.start_span(:child_async, %{links: [link]})  |> IO.inspect(label: "child span ctx")
  Process.sleep(20)
  :otel_span.end_span(child_span_ctx, :undefined)
end)
:otel_span.end_span(span_ctx, :undefined)

However I noticed that child span doesn’t have anything in relation to the parent span

Third pass

I briefly looked at the otel_span.erl and decided to put parent span as a current span before start a new span in the child process and it worked

span_ctx = OpenTelemetry.Tracer.start_span(:parent) |> IO.inspect(label: "parent_ctx")
Task.async(fn ->
  OpenTelemetry.Tracer.set_current_span(span_ctx)
  OpenTelemetry.Tracer.with_span(:child_third_pass) do
    Process.sleep(20)
  end
end)
:otel_span.end_span(span_ctx, :undefined)

Am I confused about the role of the links?

First Post!

kanishka

kanishka

It’s been a few years, but I think the interpretation of “link” is up to the renderer to decide how to show the relationship, so parent seems closer to what you want.

In other languages, you also have to be careful to thread the parent span along properly as you switch between threads. Usually threading through the span between function calls gets noisy, so each language uses their language specific idiom for propagating a value for one thread between function calls implicitly. I haven’t thought about how a tracer would be implemented in elixir.

Where Next?

Popular in Questions Top

siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID&lt;0.412.0&gt; terminating ** (Postgrex.Error) FATAL...
New
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
ycv005
I have followed this StackOverflow post to install the specific version of Erlang. And When I am running mix ecto.setup then getting fol...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 record...
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New

Other popular topics Top

stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
chrismccord
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
New
RisingFromAshes
I've read in another post that it may be possible with a router helper - but I couldn't find an appropriate one, and tbh, I'm still just ...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
AstonJ
We’ve put together this wiki for Phoenix LiveView - please feel free to add any info you feel is worth including. What is Phoenix LiveV...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New

We're in Beta

About us Mission Statement