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

gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
makeitrein
Hey all, just started picking up Elixir last week and am writing a scraper as a learning project. Baby step #1 is extracting the number ...
New
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list....
New
Fl4m3Ph03n1x
Background Let’s assume I have a typical GenServer that receives messages as requests, does some operation in a DB and returns responses....
New
gonzofish
I’m currently trying to understand how to join three tables using Ecto. All the examples I’ve seen use 2, so maybe I’m just missing somet...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? https://hexdocs.pm/ecto/Ecto.Repo.h...
New
lucidguppy
I have a super simple question about elixir - how would I take a file like this foo bar baz and output a new file that enumerates th...
New

Other popular topics Top

shahryarjb
Hello, I get Persian date from my client and convert it to normal calendar like this: def jalali_string_to_miladi_english_number(persi...
New
sergio
In Ruby, I can go: User.find_by(email: "foobar@email.com").update(email: "hello@email.com") How can I do something similar in Elixir? ...
New
srinivasu
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call th...
New
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 45766 226
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
johnnyicon
Hi all, I've just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I'm trying to use Postg...
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
josevalim
Hi everyone, One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers' Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New

We're in Beta

About us Mission Statement