Pristine.Adapters.Telemetry.Foundation (Pristine v0.4.0)

Copy Markdown View Source

Telemetry adapter backed by Foundation.Telemetry.

This is the recommended runtime telemetry adapter. It keeps Pristine on the normal :telemetry handler model while letting callers attach exporters such as TelemetryReporter separately.

This adapter provides full telemetry support including:

  • Event emission
  • Function timing with automatic duration measurement
  • Counter and gauge metrics

Event naming follows a small normalization rule:

  • atom shorthand is prefixed as [:pristine, event]
  • caller-supplied event paths are emitted unchanged

Usage

# Emit a custom event
Foundation.emit(:request_completed, %{path: "/api"}, %{duration: 100})

# Measure a function
result = Foundation.measure(:database_query, %{table: "users"}, fn ->
  query_database()
end)

# Emit a counter
Foundation.emit_counter(:request_count, %{method: :get})

# Emit a gauge
Foundation.emit_gauge(:queue_size, 42, %{queue: "jobs"})

Event Naming

Examples:

  • emit(:request, ...) emits [:pristine, :request]
  • measure(:query, ...) emits [:pristine, :query]
  • emit([:my_sdk, :request, :stop], ...) emits that exact path

Summary

Functions

Emit a telemetry event.

Emit a counter event (increment by 1).

Emit a gauge event with a specific value.

Measure function execution time and emit a telemetry event.

Functions

emit(event, metadata, measurements)

Emit a telemetry event.

Atom shorthand is normalized under [:pristine, ...]. List paths are preserved as-is.

emit_counter(event, metadata)

Emit a counter event (increment by 1).

Emits an event with %{count: 1} measurement.

emit_gauge(event, value, metadata)

Emit a gauge event with a specific value.

Emits an event with %{value: value} measurement.

measure(event, metadata, fun)

Measure function execution time and emit a telemetry event.

Emits an event with %{duration: duration_in_native_time} measurement. If the function raises, the event is still emitted with :error metadata before re-raising.