-
Notifications
You must be signed in to change notification settings - Fork 125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Q: how to propagate ecto context from/to custom worker metrics? #425
Comments
def handle_service_event(name, metrics, metadata, other) do
[_ | [function | _] = span_name] = Enum.reverse(name)
span_id = span_name |> Enum.reverse() |> Enum.join(".")
OpenTelemetry.Tracer.start_span(span_id, %{})
|> OpenTelemetry.Span.end_span()
OpenTelemetry.Ctx.clear()
end This is just creating a trace after the fact, so you aren't actually running a trace when your ecto queries are running. You'll have to handle the start event to start the span, attach, etc and a stop event to end the span. If this is app code and not a library, we suggest just using otel directly. It would remove a lot of the complexity. |
Oh, OK, that makes sense, basically need to wrap Ecto calls with span for correct parent context to kick in. Kind of like:
And if we want to keep using separate OTEL logic that just tracks ecto telemetry, it would need to look something like:
If that is correct, then I'd still like to see if how this would be done without changing domain logic. OpenTelemetry.Tracer.start_span(span_id, %{
attributes: %{some: data},
start_time: :opentelemetry.timestamp()
}) And for handling ecto OpenTelemetry.Tracer.end_span(:opentelemetry.timestamp())
OpenTelemetry.Ctx.clear() But something is not working correctly there, likely context is not correctly set. And one thing that came to mind: how can we be sure that handling ecto telemetry |
Trying this approach with something like: defmodule YAAPP.Telemetry do
def telemetry_start(namespace, event, metadata) do
OpenTelemetry.Tracer.start_span([namespace | [event]], %{
start_time: :opentelemetry.timestamp(),
kind: :server
})
start_time = System.monotonic_time()
execute_telemetry_event(namespace, [event | [:start]], metadata)
{namespace, event, start_time, metadata}
end
def telemetry_stop({namespace, event, start_time, metadata}, new_metadata \\ %{}) do
metadata = Map.merge(metadata, new_metadata)
result = execute_telemetry_event(namespace, [event | [:stop]], metadata)
OpenTelemetry.Tracer.end_span(:opentelemetry.timestamp())
result
end
defp execute_telemetry_event(namespace, event, metadata) do
:telemetry.execute([:yaapp, namespace | event], %{}, metadata)
end
end Idea is to use telemetry start/stop functions to start/stop OTEL span too. But that is also not working, at least as far as I can tell. Any pointers there? If it helps, %{
{:otel_tracer, :span_ctx} => :undefined
} |
So first up, apologies for making this a feature request kind of issue.
I have workers (GenServer) which emit custom telemetry events and use Ecto.
Spans from those workers telemetry are not connected to related Ecto spans.
Currently it looks like this (genserver setup and actual measurements omitted for brevity).
Basically we emit telemetry events from worker and attach to them to be able to emit open telemetry spans.
While this works, it does not connect ecto spans with the worker spans.
And ideally, those would be connected / parented correctly.
I tried fetching current context in
YAAPP.Telemetry
, e.g. viaOpenTelemetry.Ctx.get_current()
andOpentelemetryProcessPropagator.fetch_parent_ctx(1, :"$callers")
and propagating via telemetry event metadata. But, those are empty, as expected. Tried then to wrap telemetry event in an otel span, like this:But, that also did not work. E.g. I still don't see correct parenting of those traces (in Grafana/Tempo for my case).
Any suggestions? 🙇🏼
The text was updated successfully, but these errors were encountered: