Manual Tracing
In addition to the Auto Tracing integrations, you can instrument your Python code using MLflow's manual tracing APIs. This is especially useful when you need to instrument your custom Python code.
tip
Looking for the Typescript guide? Checkout the Typescript SDK documentation.
Decorator
The mlflow.trace()
decorator allows you to create a span for any function. This approach provides a simple yet effective way to add tracing to your code with minimal effort:
- 🔗 MLflow detects the parent-child relationships between functions, making it compatible with auto-tracing integrations.
- 🛡️ Captures exceptions during function execution and records them as span events.
- 📊 Automatically logs the function's name, inputs, outputs, and execution time.
- 🤝 Can be used alongside auto-tracing features, such as
mlflow.openai.autolog
.
The @mlflow.trace decorator currently supports the following types of functions:
Function Type | Supported |
---|---|
Sync | Yes |
Async | Yes (>= 2.16.0) |
Generator | Yes (>= 2.20.2) |
Async Generator | Yes (>= 2.20.2) |