Tracing tools
Project description
Tracely
Tracely is a tool designed for tracing and monitoring AI model interactions, enabling you to gain real-time insights into your models' performance. This repository offers a straightforward interface for integrating tracing into your Python applications.
Getting Started
Prerequisites
- Python 3.x
- An account on Evidently Cloud
- API Key from your Evidently account
Installation
Tracely is available as a PyPI package. To install it using pip package manager, run:
pip install tracely
Usage
Init
To send your traces to Evidently you need to initialize tracely:
from tracely import init_tracing
init_tracing(
address="https://app.evidently.cloud", # Trace Collector Address
api_key="", # API Key from Evidently Cloud
team_id="a1d08c46-0624-49e3-a9f5-11a13b4a2aa5", # Team ID from Evidently Cloud
export_name="tracing-dataset",
)
All parameters can be set using environment varialbes:
EVIDENTLY_TRACE_COLLECTOR
- trace collector address (default to https://app.evidently.cloud)EVIDENTLY_TRACE_COLLECTOR_API_KEY
- API Key to access Evidently Cloud for creating dataset and uploading tracesEVIDENTLY_TRACE_COLLECTOR_EXPORT_NAME
- Export name in Evidently CloudEVIDENTLY_TRACE_COLLECTOR_TEAM_ID
- Team ID from Evidently Cloud to create Export dataset in
Decorator
Once Tracely is initialized, you can decorate your functions with trace_event
to start collecting traces for a specific function:
from tracely import init_tracing
from tracely import trace_event
init_tracing()
@trace_event()
def process_request(question: str, session_id: str):
# do work
return "work done"
The trace_event
decorator accepts several arguments:
span_name
- the name of the span to send in the event (defaults to the function name)track_args
- a list of function arguments to include in the event (defaults toNone
, indicating that all arguments should be included)ingore_args
- a list of function arguments to exclude (defaults toNone
, meaning no arguments are ignored)track_output
- indicates whether the event should track the function's return value (defaults toTrue
)parse_output
- indicates whether the result should be parsed (e.g., dict, list, and tuple types would be split into separate fields; defaults toTrue
)
Context Manager
If you need to create a trace event without using a decorator (e.g., for a specific piece of code), you can do so with the context manager:
import uuid
from tracely import init_tracing
from tracely import create_trace_event
init_tracing()
session_id = str(uuid.uuid4())
with create_trace_event("external_span", session_id=session_id) as event:
event.set_attribute("my-attribute", "value")
# do work
event.set_result({"data": "data"})
The create_trace_event
function accepts the following arguments:
name
- the name of the event to label itparse_output
- indicates whether the result (if set) should be parsed (dict, list and tuple types would be split in separate fields), default toTrue
**params
- key-value style parameters to set as attributes
The event
object has the following methods:
set_attribute
- set a custom attribute for the eventset_result
- set a result for the event (only one result can be set per event)
Extending events with additional attributes
If you want to add a new attribute to active event span, you can use get_current_span()
to get access to current span:
import uuid
from tracely import init_tracing
from tracely import create_trace_event
from tracely import get_current_span
init_tracing()
session_id = str(uuid.uuid4())
with create_trace_event("external_span", session_id=session_id):
span = get_current_span()
span.set_attribute("my-attribute", "value")
# do work
span.set_result({"data": "data"})
Object from tracely.get_current_span()
have 2 methods:
set_attribute
- add new attribute to active spanset_result
- set a result field to an active span (have no effect in decorated functions with return values)
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file tracely-0.1.3.tar.gz
.
File metadata
- Download URL: tracely-0.1.3.tar.gz
- Upload date:
- Size: 11.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 00042844b77e6b2c8c0b512e9f9c0af6bae399a759134714fb63f789d6fca7f2 |
|
MD5 | 1d70fc6781260e75e4cb26948eb2e3af |
|
BLAKE2b-256 | aaeaf7fbdf79c35446067a5354860fddf3f1267966e1c0522682d915fe74b305 |
File details
Details for the file tracely-0.1.3-py3-none-any.whl
.
File metadata
- Download URL: tracely-0.1.3-py3-none-any.whl
- Upload date:
- Size: 12.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7ed47926b8c647210405c87dba09e39c20a43e60fc6147ff2dd3362c8ecf6449 |
|
MD5 | 733761f05dbcf311cc41b7645d586790 |
|
BLAKE2b-256 | 33dcae0ce648fd711e79761d3effaebe73abc83a27782919a2c435a83dd283ac |