Two ways to collect
- Log from callbacks. After
generateTextor in the finish callback ofstreamText, write a trace record with usage, finish reason, model, latency, feature and user. - Use OpenTelemetry. Turn on the SDK's telemetry so each call becomes spans, collect them with your OpenTelemetry pipeline, and map them as described in the OpenTelemetry guide.
The first is simpler for one app. The second scales better when you want every service traced the same way.