Wiretapping the Runtime
The simplest debugging path is to attach a wiretap listener to theInferenceRuntime. The wiretap receives every event dispatched during the request lifecycle, including request construction, driver selection, streaming deltas, and the final response.
Listening for Specific Events
When you only care about certain events, useonEvent() to register targeted listeners instead of a wiretap. This avoids noise from events you do not need.
Available Events
Polyglot dispatches events at each stage of the inference lifecycle:| Event | When it fires |
|---|---|
InferenceStarted | Before the first attempt begins |
InferenceRequested | When a request is about to be sent |
InferenceAttemptStarted | At the start of each retry attempt |
InferenceAttemptSucceeded | When an attempt receives a successful response |
InferenceAttemptFailed | When an attempt fails (before retry) |
StreamEventReceived | When a raw SSE event arrives during streaming |
StreamEventParsed | After a stream event is parsed into a delta |
StreamFirstChunkReceived | When the first visible delta arrives (useful for TTFC) |
PartialInferenceDeltaCreated | For each visible streaming delta |
InferenceResponseCreated | When the final response is assembled |
InferenceCompleted | After the entire inference flow finishes |
InferenceFailed | When all retry attempts are exhausted |
InferenceUsageReported | When token usage data is available |
InferenceDriverBuilt | When the driver is constructed (includes redacted config) |
Logging to Files
For persistent debugging, write event data to a log file:HTTP-Level Inspection
If you need to see the raw HTTP request and response bodies, inject a custom HTTP client with middleware. This is useful when you suspect Polyglot is sending an unexpected payload, or when the provider returns an error body that higher-level events do not surface.withMiddleware() to log, transform, or inspect requests and responses at the transport layer. This is especially helpful when working behind proxies, or when provider error messages are only visible in the raw HTTP body.
Tips for Effective Debugging
- Start with wiretap. It gives a complete picture with no configuration.
- Narrow to specific events once you know which stage of the flow is failing.
- Check the
InferenceDriverBuiltevent to confirm the correct driver and configuration were resolved. The config is automatically redacted to hide API keys. - Use file logging in production rather than
echo, so you can review logs after the fact. - For streaming issues, listen for
StreamFirstChunkReceivedto measure time-to-first-chunk, andPartialInferenceDeltaCreatedto verify deltas are arriving.