-
Notifications
You must be signed in to change notification settings - Fork 5
Implement OpenLLMetry Tracing in Python Application #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
nirga
wants to merge
1
commit into
main
Choose a base branch
from
claude/implement-openllmetry-tracing
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# OpenLLMetry Tracing Setup | ||
|
||
This application now includes OpenLLMetry tracing to monitor LLM calls and performance in Traceloop. | ||
|
||
## Setup | ||
|
||
1. **Install dependencies** (if not already installed): | ||
```bash | ||
uv sync | ||
``` | ||
|
||
2. **Set your Traceloop API key** (optional but recommended): | ||
```bash | ||
export TRACELOOP_API_KEY="your_api_key_here" | ||
``` | ||
|
||
You can get your API key from your [Traceloop dashboard](https://app.traceloop.com/). | ||
|
||
3. **Run the application**: | ||
```bash | ||
uv run kickoff | ||
``` | ||
|
||
## What Gets Traced | ||
|
||
The application automatically traces: | ||
|
||
- **Main prompt optimization flow**: Full workflow execution | ||
- **Prompt evaluation**: Each evaluation step with scores and feedback | ||
- **Prompt optimization**: Optimization attempts with before/after prompts | ||
- **Retry logic**: Retry counts and completion reasons | ||
|
||
## Trace Attributes | ||
|
||
Each trace includes relevant attributes such as: | ||
- Prompt content (original and optimized) | ||
- Evaluation scores | ||
- Retry counts | ||
- Failure reasons | ||
- Optimization results | ||
|
||
## Viewing Traces | ||
|
||
1. Go to your [Traceloop dashboard](https://app.traceloop.com/) | ||
2. Navigate to the "Traces" section | ||
3. View detailed traces of your prompt optimization runs | ||
|
||
## Local Development | ||
|
||
If you don't set the `TRACELOOP_API_KEY` environment variable, the application will still run and trace locally, but traces won't be sent to Traceloop. This allows for development without requiring API keys. | ||
|
||
## Environment Variables | ||
|
||
- `TRACELOOP_API_KEY`: Your Traceloop API key (optional for local development) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import os | ||
from openllmetry import init, tracer | ||
|
||
def initialize_tracing(): | ||
"""Initialize OpenLLMetry tracing for the application.""" | ||
# Get API key from environment variable or use placeholder | ||
api_key = os.getenv("TRACELOOP_API_KEY") | ||
|
||
if not api_key: | ||
print("Warning: TRACELOOP_API_KEY not set. Set it to enable tracing to Traceloop.") | ||
# Initialize without API key for local development | ||
init() | ||
else: | ||
# Initialize with API key for production | ||
init(api_key=api_key) | ||
|
||
print("OpenLLMetry tracing initialized") | ||
return tracer | ||
|
||
# Initialize tracing when module is imported | ||
tracer_instance = initialize_tracing() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The imported 'tracer_instance' is not used in this module. Consider removing it or adding instrumentation if needed.