DeribitEx.Telemetry (deribit_ex v0.1.0)

View Source

Telemetry events for the DeribitEx library.

This module provides a consistent interface for emitting telemetry events throughout the library. Use these functions instead of calling :telemetry.execute directly to ensure consistent event naming and metadata structure.

Event Categories

DeribitEx emits telemetry events in the following categories:

  • Connection: Events related to WebSocket connection lifecycle
  • RPC: Events for request/response operations
  • Auth: Authentication-related events
  • Subscription: Channel subscription events
  • Order Context: Order tracking events

Example Usage

:telemetry.attach(
  "deribit-auth-handler",
  [:deribit_ex, :auth, :success],
  fn name, measurements, metadata, _config ->
    # Process authentication success event
  end,
  nil
)

Summary

Types

Connection identifier, typically the WebSocket client PID.

Generic metadata map for telemetry events.

RPC request types.

Session identifier for tracking session state.

Types of session transitions.

Functions

Emits a telemetry event when authentication fails.

Emits a telemetry event when authentication is successful.

Emits a telemetry event when a connection is closed.

Emits a telemetry event when a connection is established.

Emits a telemetry event when an order is registered.

Emits a telemetry event when an order is updated.

Emits a telemetry event when an RPC request is sent.

Emits a telemetry event when an RPC response is received.

Emits a telemetry event when a session transition occurs.

Emits a telemetry event when a subscription is created.

Emits a telemetry event when a subscription is removed.

Types

connection()

@type connection() :: pid() | atom()

Connection identifier, typically the WebSocket client PID.

metadata()

@type metadata() :: map()

Generic metadata map for telemetry events.

rpc_type()

@type rpc_type() :: :auth | :public | :private | :subscription | :heartbeat

RPC request types.

session_id()

@type session_id() :: String.t()

Session identifier for tracking session state.

transition_type()

@type transition_type() :: :refresh | :exchange | :fork | :logout

Types of session transitions.

Functions

emit_auth_failure(connection, reason, metadata \\ %{})

@spec emit_auth_failure(connection(), term(), metadata()) :: :ok

Emits a telemetry event when authentication fails.

Parameters

  • connection: The WebSocket connection identifier
  • reason: The reason for the authentication failure
  • metadata: Additional metadata to include with the event

emit_auth_success(connection, metadata \\ %{})

@spec emit_auth_success(connection(), metadata()) :: :ok

Emits a telemetry event when authentication is successful.

Parameters

  • connection: The WebSocket connection identifier
  • metadata: Additional metadata to include with the event

emit_connection_closed(connection, reason, metadata \\ %{})

@spec emit_connection_closed(connection(), term(), metadata()) :: :ok

Emits a telemetry event when a connection is closed.

Parameters

  • connection: The WebSocket connection identifier
  • reason: The reason for the connection closure
  • metadata: Additional metadata to include with the event

emit_connection_opened(connection, metadata \\ %{})

@spec emit_connection_opened(connection(), metadata()) :: :ok

Emits a telemetry event when a connection is established.

Parameters

  • connection: The WebSocket connection identifier
  • metadata: Additional metadata to include with the event

emit_order_registered(order_id, session_id, metadata \\ %{})

@spec emit_order_registered(String.t(), session_id(), metadata()) :: :ok

Emits a telemetry event when an order is registered.

Parameters

  • order_id: The ID of the order
  • session_id: The session ID that the order belongs to
  • metadata: Additional metadata to include with the event

emit_order_updated(order_id, session_id, status, metadata \\ %{})

@spec emit_order_updated(String.t(), session_id(), String.t(), metadata()) :: :ok

Emits a telemetry event when an order is updated.

Parameters

  • order_id: The ID of the order
  • session_id: The session ID that the order belongs to
  • status: The new status of the order
  • metadata: Additional metadata to include with the event

emit_rpc_request(type, method, metadata \\ %{})

@spec emit_rpc_request(rpc_type(), String.t(), metadata()) :: :ok

Emits a telemetry event when an RPC request is sent.

Parameters

  • type: The type of RPC request (:auth, :public, :private, etc.)
  • method: The RPC method name
  • metadata: Additional metadata to include with the event

emit_rpc_response(type, method, duration, metadata \\ %{})

@spec emit_rpc_response(rpc_type(), String.t(), integer(), metadata()) :: :ok

Emits a telemetry event when an RPC response is received.

Parameters

  • type: The type of RPC request that this is a response to
  • method: The RPC method name
  • duration: The duration of the request in native time units
  • metadata: Additional metadata to include with the event

emit_session_transition(prev_session_id, new_session_id, transition_type, metadata \\ %{})

@spec emit_session_transition(
  session_id(),
  session_id(),
  transition_type(),
  metadata()
) :: :ok

Emits a telemetry event when a session transition occurs.

Parameters

  • prev_session_id: The previous session ID
  • new_session_id: The new session ID
  • transition_type: The type of transition (:refresh, :exchange, :fork, :logout)
  • metadata: Additional metadata to include with the event

emit_subscription_created(channel, metadata \\ %{})

@spec emit_subscription_created(String.t(), metadata()) :: :ok

Emits a telemetry event when a subscription is created.

Parameters

  • channel: The channel name that was subscribed to
  • metadata: Additional metadata to include with the event

emit_subscription_removed(channel, metadata \\ %{})

@spec emit_subscription_removed(String.t(), metadata()) :: :ok

Emits a telemetry event when a subscription is removed.

Parameters

  • channel: The channel name that was unsubscribed from
  • metadata: Additional metadata to include with the event