Skip to main content

A python package for observing traces of your LLM application.

Project description

TraceIT

Installation

Install the package from PyPI using:

   pip install trace_it

Note: It is recommended to use the latest version for optimal performance.

Middleware Setup

Add the following middleware functions to your FastAPI application in main.py or the appropriate entry point.

1. Traceit Middleware

This middleware creates a unified trace for each incoming request.

from trace_it import traceit_middleware

app = FastAPI()

@app.middleware("http")
async def traceit_middleware(request: Request, call_next):
    return await traceit_middleware(request, call_next, project_name="your_project_name")

Using Decorators for Tracing

ObserveLLM provides four decorators to enable tracing for different AI/ML components:

  • @embedding_tracing → Tracks embedding model calls.

  • @llm_tracing → Tracks LLM (Language Model) interactions.

  • @reranking_tracing → Tracks reranking models used in search/retrieval.

  • @vectordb_tracing → Tracks vector database operations.

Example: Using the @embedding_tracing Decorator

from trace_it import embedding_tracing

@embedding_tracing(provider='embedding_provider_name')
async def embedding_generation_function(model_name: str, dimension: int, inputs: list, input_type: str):
    ## your custom API calling logic

Example: Using the @llm_tracing Decorator

from trace_it import llm_tracing

@llm_tracing(provider='llm_provider_name')
async def llm_api_calling_function(model_name: str, system_prompt: str, user_prompt:str , user_query:str , **params):
    ## your custom API calling logic

Example: Using the @reranking_tracing Decorator

from trace_it import reranking_tracing

@reranking_tracing(provider='reranker_provider_name')
async def reranking_function(model_name: str, query: str, documents: list, top_n: int):
    ## your custom API calling logic

Example: Using the @vectordb_tracing Decorator

from trace_it import vectordb_tracing

## for write operation
@vectordb_tracing(provider='pinecone', operation_type='write')
async def vectordb_function(self, index_host, input, namespace):
    ## your custom API calling logic

## for read operation
@vectordb_tracing(provider='pinecone', operation_type='read')
async def vectordb_function(self, index_host, namespace, top_k, alpha: int, query: str, query_vector_embeds: list, query_sparse_embeds: dict, include_metadata: bool, filter_dict: dict = None):
    ## your custom API calling logic

Note: It is essential to define your methods using the above parameters for consistency and compatibility.

Prerequisite: Self-Hosted Phoenix

To ensure proper logging and tracing, you must have a self-hosted Phoenix instance up and running. Without it, tracing will not function correctly. find out more about self hosted phoenix here

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

trace_it-0.1.6.tar.gz (15.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

trace_it-0.1.6-py3-none-any.whl (19.3 kB view details)

Uploaded Python 3

File details

Details for the file trace_it-0.1.6.tar.gz.

File metadata

  • Download URL: trace_it-0.1.6.tar.gz
  • Upload date:
  • Size: 15.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for trace_it-0.1.6.tar.gz
Algorithm Hash digest
SHA256 4f771b02ab3f87470c9085e7d079eec3686d20247e2fb30e3f829d7adb34bfa6
MD5 949bc31d936df1fc84d4ddc38bdc516f
BLAKE2b-256 defc3ae1fa7bf408c54ac255ce59f3af02c89adc96eb9b88e24f64f4679e2dc2

See more details on using hashes here.

Provenance

The following attestation bundles were made for trace_it-0.1.6.tar.gz:

Publisher: python-publish.yml on Krish-Goyani/Trace_IT

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file trace_it-0.1.6-py3-none-any.whl.

File metadata

  • Download URL: trace_it-0.1.6-py3-none-any.whl
  • Upload date:
  • Size: 19.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for trace_it-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 298a511bc192a2069dbd15a8c15dd7437f0f3a0c362b302add38a9c92fbdd09c
MD5 3af343ff7462eb7e5fbb7c2015e74f91
BLAKE2b-256 b0c99802b078750ef2c04cc74f30107cba79fe69c6be6a8485fc6c27c009cc1a

See more details on using hashes here.

Provenance

The following attestation bundles were made for trace_it-0.1.6-py3-none-any.whl:

Publisher: python-publish.yml on Krish-Goyani/Trace_IT

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page