@weave.op() decorator (Python), or wrap it with weave.op() (TypeScript).
Decorate functions and sub-functions as granularly as possible to capture the application’s complete execution flow. This helps you better understand and shape your application’s behavior.
Trace nested functions
This section steps through an example that traces a function and its nested sub-functions. 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 usesweave.op() to trace every function, its call order, and its parent-child relationship:
- Python
- TypeScript
extract_dinos and count_dinos), as well as the automatically-logged OpenAI trace.
Track metadata
Now that Weave traces your nested functions, you can enrich those traces with additional context about the run, such as the user or environment. You can track metadata by using theweave.attributes context manager and passing it a dictionary of the metadata to track at call time.
Continuing the previous example:
- Python
- TypeScript
Track metadata at run time, such as your user IDs and your code’s environment status (development, staging, or production).To track system settings, such as a system prompt, use Weave Models.
What’s next
- Follow the App Versioning tutorial to capture, version, and organize ad-hoc prompt, model, and application changes.