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.7.tar.gz (15.5 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.7-py3-none-any.whl (19.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: trace_it-0.1.7.tar.gz
  • Upload date:
  • Size: 15.5 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.7.tar.gz
Algorithm Hash digest
SHA256 48ff8c6fce1bccf6d81b24859321e71133192839836cfdb1ca11e21228a1caff
MD5 f3a49b7c82ea86cd97bb895ccca4f728
BLAKE2b-256 dd22ca3afbee62018920e5ff2feacdc5b0c0b432938c67d531912c08f086f380

See more details on using hashes here.

Provenance

The following attestation bundles were made for trace_it-0.1.7.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.7-py3-none-any.whl.

File metadata

  • Download URL: trace_it-0.1.7-py3-none-any.whl
  • Upload date:
  • Size: 19.1 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.7-py3-none-any.whl
Algorithm Hash digest
SHA256 318b44d2eba54ce4c9800fd0ae63860b97dbb4868ecdd974ec5e6b0d097714e5
MD5 d63b660bbed26269c2fe98e10bf81f79
BLAKE2b-256 36a1ed94d7eddcdca45520889221791b3400356e818432ac26a555b566aed320

See more details on using hashes here.

Provenance

The following attestation bundles were made for trace_it-0.1.7-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