Telemetry integration for TestcontainerEx.
Emits structured events at key lifecycle points so users can hook into
monitoring, metrics, or logging via :telemetry.
Events
| Event | Measurements | Metadata |
|---|---|---|
[:testcontainer_ex, :container, :start] | duration, monotonic_time | container_id, image |
[:testcontainer_ex, :container, :stop] | duration, monotonic_time | container_id |
[:testcontainer_ex, :image, :pull] | duration, monotonic_time | image |
[:testcontainer_ex, :network, :create] | duration, monotonic_time | network_name |
[:testcontainer_ex, :network, :remove] | duration, monotonic_time | network_name |
[:testcontainer_ex, :ryuk, :start] | duration, monotonic_time | session_id |
[:testcontainer_ex, :wait, :strategy] | duration, monotonic_time | strategy, container_id |
Usage
Attach a handler to measure container start times:
:telemetry.attach(
"my-handler",
[:testcontainer_ex, :container, :start],
fn _name, measurements, _meta, _config ->
:io.format("Container started in ~p us~n", [measurements[:duration]])
end,
nil
)With telemetry_metrics
Metrics.summary("testcontainer_ex.container.start.duration",
unit: {:microsecond, :millisecond}
)
Summary
Functions
Emits a telemetry event without timing a function.
Returns the list of all event names this module can emit. Useful for documentation or for attaching handlers programmatically.
Executes the given function and emits a telemetry event with timing.
Functions
Emits a telemetry event without timing a function.
Useful for instantaneous events like "container stopped".
@spec events() :: [[atom()]]
Returns the list of all event names this module can emit. Useful for documentation or for attaching handlers programmatically.
Executes the given function and emits a telemetry event with timing.
Returns the result of fun. on success, or re-raises on error (still
emitting the event with error: true in metadata).
Parameters
event_name— list of atoms, e.g.[:testcontainer_ex, :container, :start]metadata— map of extra metadata to includefun— zero-arity function to time
Examples
with_telemetry(
[:testcontainer_ex, :container, :start],
%{image: "redis:7"},
fn -> Lifecycle.start_container(builder, conn, state) end
)