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: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.