feat(alephalpha): add beginner-friendly LLM tracing example (closes #4069)#4369
feat(alephalpha): add beginner-friendly LLM tracing example (closes #4069)#4369KochC wants to merge 2 commits into
Conversation
Closes traceloop#4069 - Add packages/sample-app/sample_app/alephalpha_example.py: a self-contained, well-commented runnable example that shows how to initialise Traceloop, instrument the Aleph Alpha client, make a completion request and observe the resulting trace. - Expand packages/opentelemetry-instrumentation-alephalpha/README.md with a step-by-step beginner walkthrough covering: * raw OpenTelemetry setup (console exporter) * AlephAlphaInstrumentor usage * a complete minimal code snippet * a table of expected span attributes * a Traceloop SDK variant - Add aleph_alpha_client and opentelemetry-instrumentation-alephalpha to packages/sample-app/pyproject.toml so the example can be run from the sample-app environment.
|
Chris seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThe PR adds beginner-oriented Aleph Alpha tracing documentation and a runnable sample app. It covers OpenTelemetry setup, Aleph Alpha instrumentation, Traceloop workflows and tasks, required dependencies, completion requests, and expected span attributes. ChangesAleph Alpha tracing examples
Estimated code review effort: 2 (Simple) | ~10 minutes Sequence Diagram(s)sequenceDiagram
participant Main
participant JokeGenerator
participant GenerateJoke
participant AlephAlphaClient
Main->>JokeGenerator: run workflow
JokeGenerator->>GenerateJoke: pass prompt
GenerateJoke->>AlephAlphaClient: submit CompletionRequest
AlephAlphaClient-->>GenerateJoke: return completion
GenerateJoke-->>JokeGenerator: return result
JokeGenerator-->>Main: finish workflow
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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/alephalpha_example.py (1)
50-62: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueExplicitly use
ConsoleSpanExporterfor debugging.As per coding guidelines, use
ConsoleSpanExporterfromopentelemetry.sdk.trace.exportfor debugging OpenTelemetry spans and hierarchy issues. AlthoughTraceloop.init()defaults to standard output when the API key is missing, the guidelines mandate explicit use ofConsoleSpanExporterfor debugging contexts like this beginner example.Note: Applying this change will strictly print traces to the console and override the default behavior of sending them to Traceloop's cloud if
TRACELOOP_API_KEYis set.💡 Proposed fix
+from opentelemetry.sdk.trace.export import ConsoleSpanExporter + # --------------------------------------------------------------------------- # Step 2 – Initialise Traceloop / OpenTelemetry # # Traceloop.init() sets up an OpenTelemetry TracerProvider and automatically # instruments every supported LLM library that is installed, including the # Aleph Alpha client. No additional call to AlephAlphaInstrumentor is needed # when using the SDK. # -# If TRACELOOP_API_KEY is set the traces are sent to Traceloop's cloud. -# Otherwise they are printed to stdout (great for local development). +# Traces are explicitly printed to stdout using ConsoleSpanExporter for local debugging. # --------------------------------------------------------------------------- -Traceloop.init(app_name="alephalpha_beginner_example") +Traceloop.init( + app_name="alephalpha_beginner_example", + 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/alephalpha_example.py` around lines 50 - 62, Update the Traceloop initialization in the Aleph Alpha example to explicitly configure and use OpenTelemetry’s ConsoleSpanExporter for span output. Import the exporter from opentelemetry.sdk.trace.export and pass it through Traceloop.init, ensuring traces are printed to the console regardless of TRACELOOP_API_KEY.Source: Coding guidelines
🤖 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/alephalpha_example.py`:
- Around line 64-67: Update the Aleph Alpha client initialization in the sample
setup to use strict dictionary lookup for the required AA_TOKEN environment
variable instead of providing an empty-string fallback. Preserve the existing
Client construction while ensuring a missing token fails immediately with the
environment lookup error.
---
Nitpick comments:
In `@packages/sample-app/sample_app/alephalpha_example.py`:
- Around line 50-62: Update the Traceloop initialization in the Aleph Alpha
example to explicitly configure and use OpenTelemetry’s ConsoleSpanExporter for
span output. Import the exporter from opentelemetry.sdk.trace.export and pass it
through Traceloop.init, ensuring traces are printed to the console regardless of
TRACELOOP_API_KEY.
🪄 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: f298f708-80d3-42f7-8952-a7f4c933a294
📒 Files selected for processing (3)
packages/opentelemetry-instrumentation-alephalpha/README.mdpackages/sample-app/pyproject.tomlpackages/sample-app/sample_app/alephalpha_example.py
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Summary
Closes #4069
This PR adds a beginner-friendly, self-contained example for tracing LLM calls with the Aleph Alpha instrumentation, addressing the request in issue #4069.
Changes
packages/sample-app/sample_app/alephalpha_example.py(new file)A runnable end-to-end example that walks through:
.envsupport viapython-dotenv)Traceloop.init)@task-decorated function that performs a completion request@workflowdecorator for a clean root spanThe file is heavily commented to guide new contributors and users who are unfamiliar with LLM observability.
packages/opentelemetry-instrumentation-alephalpha/README.md(updated)Expanded with a Beginner-friendly walkthrough section that covers:
packages/sample-app/pyproject.toml(updated)Added
aleph_alpha_client>=7.1.0,<8andopentelemetry-instrumentation-alephalpha(local editable source) so the new example can be installed and run from the sample-app environment.How to run
Expected trace
Summary by CodeRabbit
Documentation
Examples
Configuration