Skip to main content
LLM-powered applications can contain multiple LLMs calls, additional data processing, and validation logic that is important to monitor. You can track these nested functions and their parent-child relationships in Weave using the @weave.op() decorator (Python), or wrap it with weave.op() (TypeScript). We recommend decorating functions and sub-functions as granularly as possible to capture the application’s complete execution flow. This can help you better understand and shape your application’s behavior. The following code builds on the quickstart example and adds logic to count the returned items from the LLM and wrap them in a higher-level function. Additionally, the example uses weave.op() to trace every function, its call order, and its parent-child relationship:
Nested functionsWhen you run the preceding code, the Traces page shows the inputs and outputs from the two nested functions (extract_dinos and count_dinos), as well as the automatically-logged OpenAI trace.Nested Weave Traces page showing center trace tree panel and the details panel for the selected Call

Tracking metadata

You can track metadata by using the weave.attributes context manager and passing it a dictionary of the metadata to track at call time. Continuing our example from above:
We recommend that you track metadata at run time, such as your user IDs and your code’s environment status (development, staging, or production).We recommennd that to track system settings, such as a system prompt, use Weave Models.
For more information on using attributes, see Define and log attributes.

What’s next?

  • Follow the App Versioning tutorial to capture, version, and organize ad-hoc prompt, model, and application changes.