While tracing setup automatically logs LLM calls, you often need to trace additional application logic like data retrieval, preprocessing, business logic, or tool invocations. Custom tracing lets you capture these operations.Documentation Index
Fetch the complete documentation index at: https://braintrust.dev/docs/llms.txt
Use this file to discover all available pages before exploring further.
Trace function calls
Braintrust SDKs provide tools to trace function execution and capture inputs, outputs, and errors:- Python SDK uses the
@traceddecorator to automatically wrap functions - TypeScript SDK uses
wrapTraced()to create traced function wrappers - Go SDK uses OpenTelemetry’s manual span management with
tracer.Start()andspan.End()
- Function name as the span name
- Function arguments as input
- Return value as output
- Any errors that occur
Add metadata and tags
Enrich spans with custom metadata and tags to make them easier to filter and analyze.Tags from all spans in a trace are aggregated together at the trace level and automatically merged (union) rather than replaced.
Within a span
Attach metadata and tags from within the function body. This is useful for data that’s only available during execution, like computed values or results from intermediate steps.- In TypeScript and Python, use
span.log(). - In Go, C#, Ruby, and Java, use the OTel
setAttributeAPI. Custom attributes appear in the span’s metadata field. Usebraintrust.tagsfor tags. For LLM-specific OTel attributes, see OpenTelemetry.
At span creation
The TypeScript and Python SDKs support passing metadata and tags at span creation time, which avoids a separatespan.log() call. This is useful at request entry points where you have request-scoped data — like a user ID or org ID — already available and don’t want to thread it through helper functions.
Manual spans
For more control, create spans manually usinglogger.traced() or startSpan():
Span names must always be strings. Passing non-string values will cause validation failures. See Troubleshooting for details.
Nest spans
Spans automatically nest when called within other spans, creating a hierarchy that represents your application’s execution flow:Troubleshooting
Span names must be strings
Span names must be strings
If you pass a non-string value (like an object or array) to the
name field of a span, your logs will not appear in the UI - they will be hidden due to schema validation failure. Span names must always be strings.Before passing a value to the name parameter in tracing functions, ensure it is a string:Enable SDK debug logging (TypeScript)
Enable SDK debug logging (TypeScript)
If spans aren’t reaching Braintrust or instrumentation isn’t wrapping clients as expected, enable the SDK’s internal debug logging to see what’s happening under the hood. This surfaces flush failures, API retry attempts, and instrumentation lifecycle events.Set the Or configure it programmatically:Log levels from least to most verbose:
BRAINTRUST_DEBUG_LOG_LEVEL environment variable:"error", "warn", "info", "debug". This only affects local console output and does not change what data is logged to Braintrust.Next steps
- Advanced tracing patterns and techniques
- Capture user feedback like thumbs up/down
- View your logs in the Braintrust dashboard