Jev.Telemetry (Jev v0.2.3)

Copy Markdown View Source

The telemetry every backend emits.

span/4 wraps one request in [:jev, :request, :start | :stop | :exception] and fires [:jev, :answer] once per answered question. Jev.HTTP uses it, and a Jev.Backend of your own should too, so a calibration histogram or a cost sum sees local models and Jev alike.

EventMeasurementsMetadata
[:jev, :request, :start]system_timebackend, endpoint, model, questions, state_hash, tag
[:jev, :request, :stop]duration, input_tokens, output_tokens, costplus status, request_id, confidence
[:jev, :request, :exception]durationplus kind, reason, stacktrace
[:jev, :answer]confidence, probabilityname, type, answer, plus the start metadata

questions is a map of question name to type. The state is never in metadata, only its hash.

Summary

Types

What the function given to span/4 returns.

Functions

Runs fun as one request, emitting the events above.

Types

result()

@type result() ::
  {:ok, Jev.reply()}
  | {:ok, Jev.reply(), stop_metadata :: map()}
  | {:error, term()}

What the function given to span/4 returns.

Functions

span(state, questions, metadata, fun)

@spec span(Jev.entry(), Jev.questions(), map(), (-> result())) ::
  {:ok, Jev.reply()} | {:error, term()}

Runs fun as one request, emitting the events above.

metadata is what the backend knows before the call: backend, tag, and for Jev.HTTP endpoint and model. questions and state_hash are added. fun returns {:ok, reply}, {:ok, reply, stop_metadata} to add to the stop event, or {:error, reason}. A Jev.Error reason contributes its status and request_id; any other reason is put under error.

Returns {:ok, reply} or {:error, reason}.