lessless
Ignore Oban-related traces in OpenTelemetry for Ecto
Hello,
I want to ignore Oban-related traces in Ecto OpenTelemetry which comes in two flavours:
- queries against
oban_*tables - interactions with bulti-in functions like
pg_notify- oban/lib/oban/notifiers/postgres.ex at main · oban-bg/oban · GitHub
Any advices how to approach this?
Marked As Solved
sorentwo
All requests are made with Oban.Repo, which wraps calls with custom options as seen here: oban/lib/oban/repo.ex at main · oban-bg/oban · GitHub. Notice there is an oban: true field that you can detect in functions like prepare_query/3, as well as oban_conf in telemetry options which could theoretically be used to ignore Oban emitted events.
Unfortunately, it looks like OpenTelemetryEcto doesn’t have a way to ignore certain events (yet).
You could add a small wrapper module to your application, like this:
defmodule MyApp.OpenTelemetryEcto do
@moduledoc """
A wrapper around OpenTelemetryEcto that filters out queries generated by Oban.
"""
def setup(event_prefix, config \\ []) do
event = event_prefix ++ [:query]
:telemetry.attach({OpenTelemetryEcto, event}, event, &__MODULE__.handle_event/4, config)
end
@doc false
def handle_event(_event, _measure, %{oban_config: _}, _config) do
:ok
end
def handle_event(event, measure, meta, config) do
OpenTelemetryEcto.handle_event(event, measure, meta, config)
end
end
Also Liked
benwilson512
We just went through this, it’s a bit involved. I’m on my phone so I’ll have to show code later but here is a high level answer:
- Attach a regular telemetry hook to ALL of the Oban internal events.
- In that hook, set an open telemetry context value of like “oban_internal: true”
- Configure your opentelemtry lib to use a custom sampler
- in your sampler, drop all traces where the trace context is Oban internal
As I said, a bit involved. I’ll be able to provide our code later.
benwilson512
After playing with this locally this clause is slightly wrong, it needs to be:
# filter out oban tagged values
def handle_event(event, measure, %{options: options} = meta, config) do
if Keyword.has_key?(options, :oban_conf) do
:ok
else
OpentelemetryEcto.handle_event(event, measure, meta, config)
end
end
sorentwo
Good to know! Sorry, I wrote that without checking that it worked because I don’t currently use OpenTelemetry ![]()
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance









