jmurphyweb
Help understanding Ecto Telemetry events (according to Appsignal)
I’m trying to understand more about the telemetry events emitted from a poorly performing query.
I’m looking at the AppSignal dashboard which records the events and puts them into a timeline.
The query has many preloads, but they don’t seem to show up in the timeline:



My questions:
- Why is only one of the preloads showing up in each of the screenshots above?
- Is that dead-time between the first query and the last preload just time spend doing the preloads? Is that expected? if not is this likely a telemetry events issue or an appsignal issue?
The offending code:
# in data_plugs
@decorate transaction_event()
def add_project_offers_to_conn(conn, _ops) do
project = conn.assigns.project
offers = Production.list_offers([project_id: project.id], [:custom_fields])
conn
|> assign(:proj_offers, offers)
end
def list_offers(filters, preloads \\ []) when is_list(filters) and is_list(preloads) do
preloads =
preloads ++
[
:engagement,
:original_offer,
:replacement_offer,
:job_title,
:department,
:contract_type,
:document,
altered_documents: :document,
envelope_events: EnvelopeEventAPI.preload_query()
]
query =
from(o in Offer, preload: ^preloads)
|> Queries.apply_filters(filters)
Repo.all(query)
end
Marked As Solved
jmurphyweb
I now have all preloads showing up in appsignal:
MyApp.Repo
def default_options(_atom) do
[
telemetry_options: [
appsignal_parent_span: Appsignal.Tracer.current_span()
]
]
end
MyApp.Telemetry
def handle_event([:ev2, :repo, :query], measurements, metadata, config) do
:ok = send_preload_to_appsignal(measurements, metadata, config)
:ok
end
defp send_preload_to_appsignal(
%{total_time: total_time},
%{repo: repo, query: query, options: options},
_config
) do
parent_span = options[:appsignal_parent_span]
# if current_span is not nil then the event is already sent by appsignal library
if parent_span && is_nil(Appsignal.Tracer.current_span()) do
# appsignal library uses :os.system_time so using here for consistency
time = :os.system_time()
"http_request"
|> Appsignal.Tracer.create_span(parent_span, start_time: time - total_time)
|> Appsignal.Span.set_name("Query #{inspect(repo)}")
|> Appsignal.Span.set_attribute("appsignal:category", "query.ecto")
|> Appsignal.Span.set_sql(query)
|> Appsignal.Tracer.close_span(end_time: time)
end
:ok
end
3
Popular in Questions
Hi! May someone helps me, please!
I have two apps into an umbrella project: the first one is Database, which manages queries, and the se...
New
Credo is smart enough to check for (something like) this:
assert length(the_list) == 0
with this response:
Checking if an enum is empt...
New
Hi all,
Trying to get some more clarity over utc_datetime and naive_datetime for Ecto:
https://hexdocs.pm/ecto/Ecto.Schema.html#module-...
New
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
New
I would like to know what is the best IDE for elixir development?
New
I have a User schema with a :from_id field set to type :string:
defmodule TweetBot.Repo.Migrations.CreateUsers do
use Ecto.Migration
...
New
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
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
I’m trying to make a websocket server in Phoenix or raw Elixir. I heard about gun, I think I could use cowboy, but since I’m not that sma...
New
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
Other popular topics
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
Hello!
tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability.
After spen...
New
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1]
15:22:35.803 [error] gen_event {lager_file_backend...
New
Hi folks,
Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
New
I have an umbrella app.
Some of the apps inside depend on other apps in the umbrella, unsurprisingly.
I'm writing a test for one of t...
New
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
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
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
Elixir appears to be a superior language to Python. I don’t see any advantage of Python over Elixir. Are there any?
New
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







