lessless

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:

Any advices how to approach this?

Marked As Solved

sorentwo

sorentwo

Oban Core Team

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

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

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:

  1. Attach a regular telemetry hook to ALL of the Oban internal events.
  2. In that hook, set an open telemetry context value of like “oban_internal: true”
  3. Configure your opentelemtry lib to use a custom sampler
  4. 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

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

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

sorentwo

Oban Core Team

Good to know! Sorry, I wrote that without checking that it worked because I don’t currently use OpenTelemetry :slightly_smiling_face:

Where Next?

Popular in Questions Top

Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
Tee
can someone please explain to me how Enum.reduce works with maps
New
Kurisu
For example for a current url like http://localhost:4000/cosmetic/products?_utf8=✓&query=perfume&page=2, I would like to get: ...
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
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
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 records...
New
yawaramin
In the Dialyzer docs ( dialyzer — OTP 29.0.2 (dialyzer 6.0.1) ), there is a way to turn off a specific warning for a function: -dialyzer...
New
vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New

Other popular topics Top

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
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 36352 110
New
boundedvariable
I am going through the kafka architecture. All the features what the kafka is providing are already in Erlang. I would like hear your opi...
New
komlanvi
Hi everyone, I was playing with phoenix liveView but I run into an issue. I have a form and want to validate each input text when the te...
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New
sergio
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
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