Python SDK for LangTrace
Project description
Langtrace
Open Source & Open Telemetry(OTEL) Observability for LLM applications
Langtrace 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.
Open Telemetry Support
The traces generated by Langtrace adhere to Open Telemetry Standards(OTEL). We are developing semantic conventions for the traces generated by this project. You can checkout the current definitions in this repository. Note: This is an ongoing development and we encourage you to get involved and welcome your feedback.
Langtrace Cloud ☁️
To use the managed SaaS version of Langtrace, follow the steps below:
- Sign up by going to this link.
- 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.
- Generate an API key by going inside the project.
- In your application, install the Langtrace SDK and initialize it with the API key you generated in the step 3.
- The code for installing and setting up the SDK is shown below
Getting Started
Get started by adding simply three lines to your code!
pip install langtrace-python-sdk
from langtrace_python_sdk import langtrace # Must precede any llm module imports
langtrace.init(api_key=<your_api_key>)
OR
from langtrace_python_sdk import langtrace # Must precede any llm module imports
langtrace.init() # LANGTRACE_API_KEY as an ENVIRONMENT variable
Langtrace Self Hosted
Get started by adding simply two lines to your code and see traces being logged to the console!
pip install langtrace-python-sdk
from langtrace_python_sdk import langtrace # Must precede any llm module imports
langtrace.init(write_to_langtrace_cloud=False, batch=False)
Langtrace self hosted custom exporter
Get started by adding simply three lines to your code and see traces being exported to your remote location!
pip install langtrace-python-sdk
from langtrace_python_sdk import langtrace # Must precede any llm module imports
langtrace.init(custom_remote_exporter=<your_exporter>, batch=<True or False>)
Additional Customization
@with_langtrace_root_span
- this decorator is designed to organize and relate different spans, in a hierarchical manner. When you're performing multiple operations that you want to monitor together as a unit, this function helps by establishing a "parent" (LangtraceRootSpan
or whatever is passed toname
) span. Then, any calls to the LLM APIs made within the given function (fn) will be considered "children" of this parent span. This setup is especially useful for tracking the performance or behavior of a group of operations collectively, rather than individually.
from langtrace_python_sdk.utils.with_root_span import with_langtrace_root_span
@with_langtrace_root_span()
def example():
response = client.chat.completions.create(
model="gpt-4",
messages=[{"role": "user", "content": "Say this is a test three times"}],
stream=False,
)
return response
with_additional_attributes
- this function is designed to enhance the traces by adding custom attributes to the current context. These custom attributes provide extra details about the operations being performed, making it easier to analyze and understand their behavior.
from langtrace_python_sdk.utils.with_root_span import (
with_langtrace_root_span,
with_additional_attributes,
)
@with_additional_attributes({"user.id": "1234", "user.feedback.rating": 1})
def api_call1():
response = client.chat.completions.create(
model="gpt-4",
messages=[{"role": "user", "content": "Say this is a test three times"}],
stream=False,
)
return response
@with_additional_attributes({"user.id": "5678", "user.feedback.rating": -1})
def api_call2():
response = client.chat.completions.create(
model="gpt-4",
messages=[{"role": "user", "content": "Say this is a test three times"}],
stream=False,
)
return response
@with_langtrace_root_span()
def chat_completion():
api_call1()
api_call2()
Supported integrations
Langtrace automatically captures traces from the following vendors:
Vendor | Type | Typescript SDK | Python SDK |
---|---|---|---|
OpenAI | LLM | :white_check_mark: | :white_check_mark: |
Anthropic | LLM | :white_check_mark: | :white_check_mark: |
Azure OpenAI | LLM | :white_check_mark: | :white_check_mark: |
Langchain | Framework | :x: | :white_check_mark: |
LlamaIndex | Framework | :white_check_mark: | :white_check_mark: |
Pinecone | Vector Database | :white_check_mark: | :white_check_mark: |
ChromaDB | Vector Database | :white_check_mark: | :white_check_mark: |
Feature Requests and Issues
- To request for features, head over here to start a discussion.
- To raise an issue, head over here and create an issue.
Contributions
We welcome contributions to this project. To get started, fork this repository and start developing. To get involved, join our Discord workspace.
Security
To report security vulnerabilites, email us at security@scale3labs.com. You can read more on security here.
License
Project details
Release history Release notifications | RSS feed
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 langtrace_python_sdk-1.2.18.tar.gz
.
File metadata
- Download URL: langtrace_python_sdk-1.2.18.tar.gz
- Upload date:
- Size: 42.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.9.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e661c987990562023f4ef345db13bcfdf7fbbd840d15ac07232e4e6692c68478 |
|
MD5 | 1f9cae0f5b621231da88d3d34c0f35d7 |
|
BLAKE2b-256 | 7afaa658bb4d1c4ee92931201153db6148a65efc0affcff20a9790f7722336f2 |
File details
Details for the file langtrace_python_sdk-1.2.18-py3-none-any.whl
.
File metadata
- Download URL: langtrace_python_sdk-1.2.18-py3-none-any.whl
- Upload date:
- Size: 61.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.9.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 18e7a8970f42a9d3bfee7fc21bc737e6bfc0e58d3de4b610c9c112d37ae2ac95 |
|
MD5 | 46ada9f98910fc2fe68347c9f26126f6 |
|
BLAKE2b-256 | a76b9b4fe3a9e3fe89b118e61fba1d58fff7e97673f64d298a1a5c865c4b21e8 |