Skip to main content

OpenTelemetry instrumentation for LiteLLM

Project description

Litellm OpenTelemetry Integration

Overview

This integration provides support for using OpenTelemetry with the Litellm framework. It enables tracing and monitoring of applications built with Litellm.

Installation

  1. Install traceAI Litellm
pip install pip install traceAI-litellm

Set Environment Variables

Set up your environment variables to authenticate with FutureAGI

import os

os.environ["FI_API_KEY"] = FI_API_KEY
os.environ["FI_SECRET_KEY"] = FI_SECRET_KEY

Quickstart

Register Tracer Provider

Set up the trace provider to establish the observability pipeline. The trace provider:

from fi_instrumentation import register
from fi_instrumentation.fi_types import ProjectType

trace_provider = register(
    project_type=ProjectType.OBSERVE,
    project_name="litellm_app"
)

Configure Litellm Instrumentation

Instrument the Litellm client to enable telemetry collection. This step ensures that all interactions with the Litellm SDK are tracked and monitored.

from traceai_litellm import LiteLLMInstrumentor

LiteLLMInstrumentor().instrument(tracer_provider=trace_provider)

Create Litellm Components

Set up your Litellm client with built-in observability.

import asyncio
import litellm

async def run_examples():
    # Simple single message completion call
    litellm.completion(
        model="gpt-3.5-turbo",
        messages=[{"content": "What's the capital of China?", "role": "user"}],
    )

    # Multiple message conversation completion call with added param
    litellm.completion(
        model="gpt-3.5-turbo",
        messages=[
            {"content": "Hello, I want to bake a cake", "role": "user"},
            {
                "content": "Hello, I can pull up some recipes for cakes.",
                "role": "assistant",
            },
            {"content": "No actually I want to make a pie", "role": "user"},
        ],
        temperature=0.7,
    )

    # Multiple message conversation acompletion call with added params
    await litellm.acompletion(
        model="gpt-3.5-turbo",
        messages=[
            {"content": "Hello, I want to bake a cake", "role": "user"},
            {
                "content": "Hello, I can pull up some recipes for cakes.",
                "role": "assistant",
            },
            {"content": "No actually I want to make a pie", "role": "user"},
        ],
        temperature=0.7,
        max_tokens=20,
    )

    # Completion with retries
    litellm.completion_with_retries(
        model="gpt-3.5-turbo",
        messages=[{"content": "What's the highest grossing film ever", "role": "user"}],
    )

    # Embedding call
    litellm.embedding(
        model="text-embedding-ada-002", input=["good morning from litellm"]
    )

    # Asynchronous embedding call
    await litellm.aembedding(
        model="text-embedding-ada-002", input=["good morning from litellm"]
    )

    # Image generation call
    litellm.image_generation(model="dall-e-2", prompt="cute baby otter")

    # Asynchronous image generation call
    await litellm.aimage_generation(model="dall-e-2", prompt="cute baby otter")

asyncio.run(run_examples())

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

traceai_litellm-0.1.6.tar.gz (6.8 kB view details)

Uploaded Source

Built Distribution

traceai_litellm-0.1.6-py3-none-any.whl (7.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: traceai_litellm-0.1.6.tar.gz
  • Upload date:
  • Size: 6.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.0.0 CPython/3.13.0 Darwin/24.1.0

File hashes

Hashes for traceai_litellm-0.1.6.tar.gz
Algorithm Hash digest
SHA256 f6635bb9324c109471d45c237383e6e9c568e8899e38f4d446bf760452d1a0ca
MD5 6ab26d7225b943b6f6022f2b5970b60d
BLAKE2b-256 65c37f1a8045e5b84234028bc6caff93511a93f5e6321cc10dc6a872bb20e5db

See more details on using hashes here.

File details

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

File metadata

  • Download URL: traceai_litellm-0.1.6-py3-none-any.whl
  • Upload date:
  • Size: 7.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.0.0 CPython/3.13.0 Darwin/24.1.0

File hashes

Hashes for traceai_litellm-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 197821804d5ccb45819c43cc915723f772623190e95811b5551ac00943659ecf
MD5 995f51dd15374e9b62b0a1260b359eea
BLAKE2b-256 8ccc69a523209dc07fbcfdac3f4758dc157c9c3910597b9f3716e4d339cb673b

See more details on using hashes here.

Supported by

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