Snakepit.Telemetry.Control (Snakepit v0.11.0)

View Source

Helper functions for creating telemetry control messages.

Control messages flow from Elixir to Python workers over the gRPC telemetry stream to adjust telemetry behavior at runtime.

Summary

Functions

Creates a control message to filter events.

Creates a control message to adjust sampling rate.

Creates a control message to enable or disable telemetry.

Functions

filter(opts \\ [])

Creates a control message to filter events.

Allows explicit whitelisting or blacklisting of events.

Examples

iex> Snakepit.Telemetry.Control.filter(allow: ["python.call.start"])
%Snakepit.Bridge.TelemetryControl{
  control: {:filter, %Snakepit.Bridge.TelemetryEventFilter{
    allow: ["python.call.start"],
    deny: []
  }}
}

iex> Snakepit.Telemetry.Control.filter(deny: ["python.memory.sampled"])
%Snakepit.Bridge.TelemetryControl{
  control: {:filter, %Snakepit.Bridge.TelemetryEventFilter{
    allow: [],
    deny: ["python.memory.sampled"]
  }}
}

sampling(rate, patterns \\ [])

Creates a control message to adjust sampling rate.

The sampling rate must be between 0.0 and 1.0, where:

  • 0.0 = no events emitted
  • 1.0 = all events emitted
  • 0.1 = 10% of events emitted

Event patterns use glob-style matching (e.g., "python.*").

Examples

iex> Snakepit.Telemetry.Control.sampling(0.5)
%Snakepit.Bridge.TelemetryControl{
  control: {:sampling, %Snakepit.Bridge.TelemetrySamplingUpdate{
    sampling_rate: 0.5,
    event_patterns: []
  }}
}

iex> Snakepit.Telemetry.Control.sampling(0.1, ["python.call.*"])
%Snakepit.Bridge.TelemetryControl{
  control: {:sampling, %Snakepit.Bridge.TelemetrySamplingUpdate{
    sampling_rate: 0.1,
    event_patterns: ["python.call.*"]
  }}
}

toggle(enabled)

Creates a control message to enable or disable telemetry.

Examples

iex> Snakepit.Telemetry.Control.toggle(true)
%Snakepit.Bridge.TelemetryControl{
  control: {:toggle, %Snakepit.Bridge.TelemetryToggle{enabled: true}}
}