Skip to main content

Python SDK for Obiguard Trace

Project description

Obiguard Trace Python SDK

Open Source & Open Telemetry(OTEL) Observability for LLM Applications

Static Badge Static Badge


๐Ÿ“š Table of Contents

Obiguard Trace is an open source observability software which lets you capture, debug and analyze traces and metrics from all your applications that leverages LLM APIs, Vector Databases and LLM based Frameworks.

โœจ Features

  • ๐Ÿ“Š Open Telemetry Support: Built on OTEL standards for comprehensive tracing
  • ๐Ÿ”„ Real-time Monitoring: Track LLM API calls, vector operations, and framework usage
  • ๐ŸŽฏ Performance Insights: Analyze latency, costs, and usage patterns
  • ๐Ÿ” Debug Tools: Trace and debug your LLM application workflows
  • ๐Ÿ“ˆ Analytics: Get detailed metrics and visualizations
  • ๐Ÿ› ๏ธ Framework Support: Extensive integration with popular LLM frameworks
  • ๐Ÿ”Œ Vector DB Integration: Support for major vector databases
  • ๐ŸŽจ Flexible Configuration: Customizable tracing and monitoring options

๐Ÿš€ Quick Start

pip install obiguard-trace-python-sdk
from obiguard_trace_python_sdk import langtrace
langtrace.init(api_key='<your Obiguard API or virtual key>') # Get your API key at obiguard.ai

๐Ÿ”— Supported Integrations

Obiguard Trace automatically captures traces from the following vendors:

LLM Providers

Provider TypeScript SDK Python SDK
OpenAI โœ… โœ…
Anthropic โœ… โœ…
Azure OpenAI โœ… โœ…
Cohere โœ… โœ…
Groq โœ… โœ…
Perplexity โœ… โœ…
Gemini โŒ โœ…
Mistral โŒ โœ…
AWS Bedrock โœ… โœ…
Ollama โŒ โœ…
Cerebras โŒ โœ…

Frameworks

Framework TypeScript SDK Python SDK
Langchain โŒ โœ…
LlamaIndex โœ… โœ…
Langgraph โŒ โœ…
LiteLLM โŒ โœ…
DSPy โŒ โœ…
CrewAI โŒ โœ…
VertexAI โœ… โœ…
EmbedChain โŒ โœ…
Autogen โŒ โœ…
HiveAgent โŒ โœ…
Inspect AI โŒ โœ…
Graphlit โŒ โœ…
Phidata โŒ โœ…
Arch โŒ โœ…

Vector Databases

Database TypeScript SDK Python SDK
Pinecone โœ… โœ…
ChromaDB โœ… โœ…
QDrant โœ… โœ…
Weaviate โœ… โœ…
PGVector โœ… โœ… (SQLAlchemy)
MongoDB โŒ โœ…
Milvus โŒ โœ…

๐ŸŒ Getting Started

Obiguard Security Control Panel for your AI โ˜๏ธ

  1. Sign up by going to this link.
  2. Create a new Project after signing up. Projects are containers for storing traces and metrics generated by your application. If you have only one application, creating 1 project will do.
  3. Generate an API key by going inside the project.
  4. In your application, install the Obiguard SDK and initialize it with the API key you generated in the step 3.
  5. The code for installing and setting up the SDK is shown below

โš™๏ธ Configuration

Initialize Options

The SDK can be initialized with various configuration options to customize its behavior:

langtrace.init(
    api_key: Optional[str] = None,          # API key for authentication
    batch: bool = True,                     # Enable/disable batch processing
    write_spans_to_console: bool = False,   # Console logging
    custom_remote_exporter: Optional[Any] = None,  # Custom exporter
    api_host: Optional[str] = None,         # Custom API host
    disable_instrumentations: Optional[Dict] = None,  # Disable specific integrations
    service_name: Optional[str] = None,     # Custom service name
    disable_logging: bool = False,          # Disable all logging
    headers: Dict[str, str] = {},           # Custom headers
)

Configuration Details

Parameter Type Default Value Description
api_key str LANGTRACE_API_KEY or None The API key for authentication. Can be set via environment variable
batch bool True Whether to batch spans before sending them to reduce API calls
write_spans_to_console bool False Enable console logging for debugging purposes
custom_remote_exporter Optional[Exporter] None Custom exporter for sending traces to your own backend
api_host Optional[str] https://langtrace.ai/ Custom API endpoint for self-hosted deployments
disable_instrumentations Optional[Dict] None Disable specific vendor instrumentations (e.g., {'only': ['openai']})
service_name Optional[str] None Custom service name for trace identification
disable_logging bool False Disable SDK logging completely
headers Dict[str, str] {} Custom headers for API requests

Environment Variables

Configure Obiguard Trace behavior using these environment variables:

Variable Description Default Impact
LANGTRACE_API_KEY Primary authentication method Required* Required if not passed to init()
TRACE_PROMPT_COMPLETION_DATA Control prompt/completion tracing true Set to 'false' to opt out of prompt/completion data collection
TRACE_DSPY_CHECKPOINT Control DSPy checkpoint tracing true Set to 'false' to disable checkpoint tracing
LANGTRACE_ERROR_REPORTING Control error reporting true Set to 'false' to disable Sentry error reporting
LANGTRACE_API_HOST Custom API endpoint https://langtrace.ai/ Override default API endpoint for self-hosted deployments

Performance Note: Setting TRACE_DSPY_CHECKPOINT=false is recommended in production environments as checkpoint tracing involves state serialization which can impact latency.

Security Note: When TRACE_PROMPT_COMPLETION_DATA=false, no prompt or completion data will be collected, ensuring sensitive information remains private.

๐Ÿ”ง Advanced Features

Root Span Decorator

Use the root span decorator to create custom trace hierarchies:

from obiguard_trace_python_sdk import langtrace

@langtrace.with_langtrace_root_span(name="custom_operation")
def my_function():
    # Your code here
    pass

Additional Attributes

Inject custom attributes into your traces:

# Using decorator
@langtrace.with_additional_attributes({"custom_key": "custom_value"})
def my_function():
    pass

# Using context manager
with langtrace.inject_additional_attributes({"custom_key": "custom_value"}):
    # Your code here
    pass

Prompt Registry

Register and manage prompts for better traceability:

from obiguard_trace_python_sdk import langtrace

# Register a prompt template
langtrace.register_prompt("greeting", "Hello, {name}!")

# Use registered prompt
response = client.chat.completions.create(
    model="gpt-4",
    messages=[{"role": "user", "content": langtrace.get_prompt("greeting", name="Alice")}]
)

User Feedback System

Collect and analyze user feedback:

from obiguard_trace_python_sdk import langtrace

# Record user feedback for a trace
langtrace.record_feedback(
    trace_id="your_trace_id",
    rating=5,
    feedback_text="Great response!",
    metadata={"user_id": "123"}
)

DSPy Checkpointing

Manage DSPy checkpoints for workflow tracking:

from obiguard_trace_python_sdk import langtrace

# Enable checkpoint tracing (disabled by default in production)
langtrace.init(
    api_key="your_api_key",
    dspy_checkpoint_tracing=True
)

Vector Database Operations

Track vector database operations:

from obiguard_trace_python_sdk import langtrace

# Vector operations are automatically traced
with langtrace.inject_additional_attributes({"operation_type": "similarity_search"}):
    results = vector_db.similarity_search("query", k=5)

For more detailed examples and use cases, visit our documentation.

๐Ÿ”’ Security

To report security vulnerabilities, email us at support@obiguard.com.

๐Ÿ“œ License

Obiguard Trace Python SDK is licensed under the Apache 2.0 License. You can read about this license 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

obiguard_trace_python_sdk-3.8.20.tar.gz (6.1 MB view details)

Uploaded Source

Built Distribution

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

obiguard_trace_python_sdk-3.8.20-py3-none-any.whl (6.2 MB view details)

Uploaded Python 3

File details

Details for the file obiguard_trace_python_sdk-3.8.20.tar.gz.

File metadata

File hashes

Hashes for obiguard_trace_python_sdk-3.8.20.tar.gz
Algorithm Hash digest
SHA256 8e733fcb4b70881bb1eab183202695926deb58918b43568f78f7b96a33679944
MD5 a09d804426eb2785f576e7495f099a47
BLAKE2b-256 801afb5e2f096f4f43174750dfcbcbc601f5729dce4128f1823ca5adb18fa6ee

See more details on using hashes here.

Provenance

The following attestation bundles were made for obiguard_trace_python_sdk-3.8.20.tar.gz:

Publisher: deploy-pypi.yml on obiguard/obiguard-trace-python-sdk

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

File details

Details for the file obiguard_trace_python_sdk-3.8.20-py3-none-any.whl.

File metadata

File hashes

Hashes for obiguard_trace_python_sdk-3.8.20-py3-none-any.whl
Algorithm Hash digest
SHA256 bd3db067674b58a851014793b5c0b65b85cf84940dbe8a649793c7db6d596c55
MD5 1681e8f0cdddaf375fa8f8d1111acf72
BLAKE2b-256 cad3324ffed593f00092ebab6e747042033d823c4085620c165adfc2af358b3e

See more details on using hashes here.

Provenance

The following attestation bundles were made for obiguard_trace_python_sdk-3.8.20-py3-none-any.whl:

Publisher: deploy-pypi.yml on obiguard/obiguard-trace-python-sdk

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