Huginn.Clickhouse.Telemetry (Huginn v0.6.0)

Copy Markdown View Source

Telemetry events emitted by Huginn, and an optional default logger.

Every request issued through Huginn.Clickhouse.Client is wrapped in a :telemetry span:

EventMeasurementsMetadata
[:huginn, :query, :start]:system_time, :monotonic_time:method, :sql, :query_id, :pool, :telemetry_span_context
[:huginn, :query, :stop]:duration, :monotonic_timestart metadata + :stats and :rows, or :error, or :halted
[:huginn, :query, :exception]:duration, :monotonic_timestart metadata + :kind, :reason, :stacktrace
[:huginn, :query, :retry]:attempt, :delay:method, :sql, :query_id, :pool, :error

:method is one of :query, :insert, :insert_stream, :stream_query, :stream_io. :query_id is the ID the query runs under on the server. It is generated up front unless you pass :query_id. Durations are in :native time units (use System.convert_time_unit/3).

:stop metadata depends on how the request ended:

  • success - :stats is the server's final statistics (or nil) and :rows is stats.rows, the number of result rows (only when the server sent statistics)
  • failure - :error is the Huginn.Error
  • a stream the consumer stopped early - halted: true

stream_query/2 and stream_io/3 are lazy: their :start is emitted when enumeration begins, and :stop (or :exception) when it ends, so :duration covers the whole enumeration.

[:huginn, :query, :retry] fires before each retry of a :connection failure. :attempt is the attempt that just failed (1-based), :delay is the backoff in milliseconds.

Default logger

Attach a ready-made handler that logs each completed request:

Huginn.attach_default_logger()
# or with a level
Huginn.attach_default_logger(:debug)

Detach it with detach_default_logger/0.

Summary

Functions

Attaches a default Logger handler for Huginn query events.

Detaches the default logger attached by attach_default_logger/1.

Functions

attach_default_logger(level \\ :info)

@spec attach_default_logger(Logger.level()) :: :ok | {:error, :already_exists}

Attaches a default Logger handler for Huginn query events.

level is the log level used for successful queries (default: :info); failures and exceptions are always logged at :error. Returns :ok, or {:error, :already_exists} if already attached.

detach_default_logger()

@spec detach_default_logger() :: :ok | {:error, :not_found}

Detaches the default logger attached by attach_default_logger/1.