Excessibility.TelemetryCapture.Enrichers.EctoQueries (Excessibility v0.18.1)

Copy Markdown View Source

Enriches timeline events with Ecto query information.

Provides two mechanisms:

  1. Telemetry handler — attaches to [:ecto, :query] events during test execution. Call attach/0 before tests and detach/0 after.
  2. Enricher callback — reads captured queries from opts or the query store.

Example Output

%{
  ecto_queries: [
    %{source: "products", operation: :select, duration_ms: 1.2, query: "SELECT..."}
  ],
  ecto_query_count: 2,
  ecto_total_query_ms: 2.0
}

Summary

Functions

Attaches a telemetry handler to [:ecto, :query] events.

Builds a normalized query record from an Ecto [..., :query] telemetry event's measurements and metadata. Shared so the live capture layer (Excessibility.TelemetryCapture) attributes queries to events using the same shape this enricher reads back.

Clears all recorded queries.

Returns the cost of this enricher.

Detaches the telemetry handler.

Enriches assigns with Ecto query data.

Returns all recorded queries in order.

Returns the enricher name.

Records a query in the store.

Starts the Agent-based query store.

Stops the query store.

Functions

attach()

Attaches a telemetry handler to [:ecto, :query] events.

build_query_record(measurements, metadata)

Builds a normalized query record from an Ecto [..., :query] telemetry event's measurements and metadata. Shared so the live capture layer (Excessibility.TelemetryCapture) attributes queries to events using the same shape this enricher reads back.

clear()

Clears all recorded queries.

cost()

Returns the cost of this enricher.

detach()

Detaches the telemetry handler.

enrich(assigns, opts)

Enriches assigns with Ecto query data.

Reads queries from the :ecto_queries key in opts. Returns query list, count, and total duration.

get_queries()

Returns all recorded queries in order.

name()

Returns the enricher name.

record_query(query_record)

Records a query in the store.

start_store()

Starts the Agent-based query store.

stop_store()

Stops the query store.

Idempotent and race-safe: safe to call concurrently from multiple on_exit callbacks when tests share the globally-named Agent.