add beginner-friendly openai example#4143
Conversation
📝 WalkthroughWalkthroughThis PR adds a single new quickstart example script that demonstrates how to initialize Traceloop and execute a basic OpenAI chat completion request. The script initializes tracing at import time and provides a simple entry point for users to test integration with gpt-4o-mini. ChangesOpenAI Quickstart Example
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
packages/sample-app/sample_app/quickstart_openai.py (1)
5-7: ⚡ Quick winAdd
ConsoleSpanExporterto align with repository debugging guidelines.This quickstart initializes tracing with
disable_batch=True, but omits the debugging exporter. WireConsoleSpanExporterthrough Traceloop's exporter parameter to match repository patterns used in other sample applications.Suggested patch
import os from openai import OpenAI from traceloop.sdk import Traceloop +from opentelemetry.sdk.trace.export import ConsoleSpanExporter # 1. Initialize Traceloop before calling any LLM services # We use disable_batch=True so traces are sent immediately (perfect for local testing!) -Traceloop.init(disable_batch=True) +Traceloop.init(disable_batch=True, exporter=ConsoleSpanExporter())🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/sample-app/sample_app/quickstart_openai.py` around lines 5 - 7, Traceloop.init currently disables batching but doesn't attach a ConsoleSpanExporter for local debugging; update the Traceloop.init call to pass an exporter configured with ConsoleSpanExporter so traces are emitted to the console (use ConsoleSpanExporter as the exporter parameter when calling Traceloop.init) — locate the Traceloop.init invocation and add the exporter argument wired to ConsoleSpanExporter.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/sample-app/sample_app/quickstart_openai.py`:
- Line 39: The file ends with a call to main() but is missing a trailing newline
which triggers linter W292; open the file containing the main() invocation and
add a single final newline character at the end of the file (after the main()
line) so the file terminates with a newline.
---
Nitpick comments:
In `@packages/sample-app/sample_app/quickstart_openai.py`:
- Around line 5-7: Traceloop.init currently disables batching but doesn't attach
a ConsoleSpanExporter for local debugging; update the Traceloop.init call to
pass an exporter configured with ConsoleSpanExporter so traces are emitted to
the console (use ConsoleSpanExporter as the exporter parameter when calling
Traceloop.init) — locate the Traceloop.init invocation and add the exporter
argument wired to ConsoleSpanExporter.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: c5a75825-05bc-417e-8ed9-f3305f41ad19
📒 Files selected for processing (1)
packages/sample-app/sample_app/quickstart_openai.py
| print(f"❌ An error occurred: {e}") | ||
|
|
||
| if __name__ == "__main__": | ||
| main() No newline at end of file |
There was a problem hiding this comment.
Add trailing newline at end of file.
Ruff reports W292 here; please add a final newline to satisfy linting.
🧰 Tools
🪛 Ruff (0.15.12)
[warning] 39-39: No newline at end of file
Add trailing newline
(W292)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@packages/sample-app/sample_app/quickstart_openai.py` at line 39, The file
ends with a call to main() but is missing a trailing newline which triggers
linter W292; open the file containing the main() invocation and add a single
final newline character at the end of the file (after the main() line) so the
file terminates with a newline.
feat(instrumentation): ...orfix(instrumentation): ....Summary by CodeRabbit