Setup
Install the Braintrust andgoogle-cloud-discoveryengine packages, set your API key, and authenticate with Google Cloud. Requires Braintrust v0.41.0+ and google-cloud-discoveryengine v0.20.3 or later.1
Install packages
2
Set environment variables
.env
3
Authenticate with Google Cloud
The Discovery Engine clients load Application Default Credentials. For local development, authenticate with the In production, configure Application Default Credentials for your runtime, such as an attached service account. Your credentials need permission to call Discovery Engine in the target Google Cloud project.
gcloud CLI:Auto-instrumentation
To trace Discovery Engine calls without modifying your application code, callbraintrust.auto_instrument() before creating your Discovery Engine clients.Manual instrumentation
To trace a specific Discovery Engine client instance manually, usewrap_google_discoveryengine(). Use this when you want to instrument a particular client rather than patching all Discovery Engine clients globally.What Braintrust traces
Braintrust instruments synchronous and asynchronousgoogle-cloud-discoveryengine v1 clients and creates spans per call:- Answer query spans (
google_discoveryengine.answer_query), with the query and optional preamble as input, answer text, citations, references, and grounding details as output, and time-to-first-token for streaming. - Streaming answer query spans (
google_discoveryengine.stream_answer_query), with the same structure as non-streaming answer queries, with incremental output aggregated across chunks. - Conversational search spans (
google_discoveryengine.converse_conversation), with the query as input and the summary text with citations and references as output. - Grounding check spans (
google_discoveryengine.check_grounding), with the answer candidate and grounding facts as input and support score, cited chunks, and claims as output. - Ranking spans (
google_discoveryengine.rank), with query and document records as input, up to 100 ranked results with scores as output, and ranking configuration and model as metadata when specified. - Provider metadata and the model and serving configuration supplied with generation requests.
- Errors captured on every call.
Asynchronous mode
answer_query calls (where asynchronous_mode=True in the request) are not traced and pass through unmodified. This is separate from using an asynchronous Python client, which is supported.