Tesla.Middleware.Telemetry (tesla v1.4.0) View Source

Emits events using the :telemetry library to expose instrumentation.

Example usage

defmodule MyClient do
  use Tesla

  plug Tesla.Middleware.Telemetry
end

:telemetry.attach("my-tesla-telemetry", [:tesla, :request, :stop], fn event, measurements, meta, config ->
  # Do something with the event
end)

Options

  • :metadata - additional metadata passed to telemetry events

Telemetry Events

  • [:tesla, :request, :start] - emitted at the beginning of the request.

    • Measurement: %{system_time: System.system_time()}
    • Metadata: %{env: Tesla.Env.t()}
  • [:tesla, :request, :stop] - emitted at the end of the request.

    • Measurement: %{duration: native_time}
    • Metadata: %{env: Tesla.Env.t()} | %{env: Tesla.Env.t(), error: term()}
  • [:tesla, :request, :exception] - emitted when an exception has been raised.

    • Measurement: %{duration: native_time}
    • Metadata: %{kind: Exception.kind(), reason: term(), stacktrace: Exception.stacktrace()}

Legacy Telemetry Events

  • [:tesla, :request] - This event is emitted for backwards compatibility only and should be considered deprecated. This event can be disabled by setting config :tesla, Tesla.Middleware.Telemetry, disable_legacy_event: true in your config. Be sure to run mix deps.compile --force tesla after changing this setting to ensure the change is picked up.

Please check the telemetry for the further usage.