Redis.Telemetry (Redis v0.8.0)

Copy Markdown View Source

Telemetry events emitted by Redis.

Events

  • [:redis_ex, :connection, :connect] - successful connection

    • Measurements: %{duration: native_time}
    • Metadata: %{host: host, port: port}
  • [:redis_ex, :connection, :disconnect] - connection lost

    • Measurements: %{}
    • Metadata: %{host: host, port: port, reason: reason}
  • [:redis_ex, :pipeline, :start] - pipeline/command started

    • Measurements: %{system_time: native_time}
    • Metadata: %{commands: commands}
  • [:redis_ex, :pipeline, :stop] - pipeline/command completed

    • Measurements: %{duration: native_time}
    • Metadata: %{commands: commands}
  • [:redis_ex, :pipeline, :exception] - pipeline/command failed

    • Measurements: %{duration: native_time}
    • Metadata: %{commands: commands, kind: kind, reason: reason}
  • [:redis_ex, :auto_pipeline, :flush] - an automatic batch was sent

    • Measurements: %{batch_size: count}
    • Metadata: %{host: host, port: port, reason: reason}

Usage

Attach a handler:

:telemetry.attach("redis-logger", [:redis_ex, :pipeline, :stop], fn name, measurements, metadata, _config ->
  Logger.info("Redis #{inspect(name)} took #{measurements.duration}ns for #{length(metadata.commands)} commands")
end, nil)

Or use the built-in default handler for logging:

Redis.Telemetry.attach_default_handler()

Summary

Functions

Attaches a default log handler for all Redis telemetry events.

Emits a telemetry event. Wraps :telemetry.execute/3 with a no-op fallback if telemetry is not available.

Spans a telemetry event around a function call.

Functions

attach_default_handler()

Attaches a default log handler for all Redis telemetry events.

execute(event, measurements, metadata \\ %{})

Emits a telemetry event. Wraps :telemetry.execute/3 with a no-op fallback if telemetry is not available.

span(event_prefix, metadata, fun)

Spans a telemetry event around a function call.