Run an experiment
Fetch experiment results
To fetch experiment results, use a SQL query to retrieve traces that match the criteria you are interested in. For example, the script below fetches traces based on whether or not a review score is present:Fetch specific child spans based on trace-level metadata
To retrieve child spans based on trace-level metadata, use a SQL query to filter spans by themetadata you are interested in.
For example, the script below calculates how long child spans took to run
that are in traces having a metadata key of “orgName” set to “qawolf”.
Paginate a large dataset
If you’re using the Python or TypeScript SDK, pagination is handled automatically. Only use this code if you’re developing with other tools.
Delete logs
To delete logs, issue log requests with the_object_delete flag set to true.
For example, the following script uses a SQL query to find all logs matching a
specific criteria and then deletes them:
Impersonate a user for a request
User impersonation allows a privileged user to perform an operation on behalf of another user, using the impersonated user’s identity and permissions. For example, a proxy service may wish to forward requests coming in from individual users to Braintrust without requiring each user to directly specify Braintrust credentials. The privileged service can initiate the request with its own credentials and impersonate the user so that Braintrust runs the operation with the user’s permissions. To this end, all API requests accept a headerx-bt-impersonate-user, which you
can set to the ID or email of the user to impersonate. Currently impersonating
another user requires that the requesting user has specifically been granted the
Owner role over all organizations that the impersonated user belongs to. This
check guarantees the requesting user has at least the set of permissions that
the impersonated user has.
Consider the following code example for configuring ACLs and running a request
with user impersonation.
Postman
Postman is a popular tool for interacting with HTTP APIs. You can load Braintrust’s API spec into Postman by importing the OpenAPI spec’s URL.
Trace with the REST API SDKs
In this section, we demonstrate the basics of logging with tracing using the language-specific REST API SDKs. The end result of running each example should be a single log entry in a project calledtracing_test, which looks like the
following:
