docs(sample-app): add beginner-friendly LLM tracing example (#4069)
Adds a short, heavily-commented walkthrough at `packages/sample-app/sample_app/beginner_tracing_example.py` that introduces `Traceloop.init`, `@workflow`, and `@task` against a single OpenAI call.
Closes #4069.
The existing examples in `sample-app/` are great references once you already know the SDK shape, but they assume you do. This one starts from `Traceloop.init` and works up to a two-task workflow so a first-time user can copy it, run it, and see the trace structure that everything else in the repo produces.
Also replaces the sample-app README placeholder (`Project description here.`) with a short paragraph that points new users at this example first.
```bash export OPENAI_API_KEY=sk-... poetry run python sample_app/beginner_tracing_example.py ```
``` $ uvx ruff check packages/sample-app/sample_app/beginner_tracing_example.py All checks passed!
$ uvx ruff format --check packages/sample-app/sample_app/beginner_tracing_example.py 1 file already formatted ```
Summary by CodeRabbit
-
Documentation
- Enhanced sample app README with a βStart here if youβre newβ quick-start, runnable walkthrough, instructions to switch to real tracing backends, and an overview of additional provider/scenario examples.
-
New Features
- Added a beginner tracing example that demonstrates instrumented AI chat workflows with real-time spans emitted to stdout and prints example outputs.
No actionable comments were generated in the recent review. π
βΉοΈ Recent review info
βοΈ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: bfeccd7e-9fa2-4930-9566-c017e397ce60
π₯ Commits
Reviewing files that changed from the base of the PR and between f6be672aed8df030e3ceb055fd477fdeb6ed6319 and 06c20556aa263d63b1a5e896b69cd6ea0b76ec25.
π Files selected for processing (2)
packages/sample-app/README.mdpackages/sample-app/sample_app/beginner_tracing_example.py
β Files skipped from review due to trivial changes (1)
- packages/sample-app/README.md
π§ Files skipped from review as they are similar to previous changes (1)
- packages/sample-app/sample_app/beginner_tracing_example.py
π Walkthrough
Walkthrough
This PR adds README instructions and a self-contained beginner tracing example that initializes Traceloop with a ConsoleSpanExporter, creates an OpenAI client, defines two traced tasks and a traced workflow that call OpenAI chat completions, and provides a main entrypoint to run the workflow.
Changes
Beginner-Friendly LLM Tracing Example
| Layer / File(s) | Summary |
|---|---|
Documentation and overview packages/sample-app/README.md, packages/sample-app/sample_app/beginner_tracing_example.py (header) |
README updated with runnable instructions and link to the beginner example; example file header/docstring explains the minimal walkthrough, three-part structure, and exporter behavior. |
Setup and configuration packages/sample-app/sample_app/beginner_tracing_example.py (imports, init, client) |
Traceloop initialized with app_name="beginner-tracing-example", disable_batch=True, and exporter=ConsoleSpanExporter() for stdout spans; a module-level client = OpenAI() is created. |
Traced tasks and workflow execution packages/sample-app/sample_app/beginner_tracing_example.py (tasks, workflow, entrypoint) |
Defines @task functions tell_joke() and explain_joke(joke) that call OpenAI chat completions and return text, a @workflow(name="joke_and_explanation") that calls both and prints results, and a __main__ entrypoint to execute the workflow. |
Estimated code review effort
π― 3 (Moderate) | β±οΈ ~20 minutes
Poem
π° A hop, a prompt, a trace in flight, I tell a joke and shed some light, Spans hop to stdout, clear and bright, Workflow hums, tasks pair just right, New folks grin and trace the sight!
π₯ Pre-merge checks | β 4 | β 1
β Failed checks (1 warning)
| Check name | Status | Explanation | Resolution |
|---|---|---|---|
| Docstring Coverage | β οΈ Warning | Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. | Write docstrings for the functions missing them to satisfy the coverage threshold. |
β Passed checks (4 passed)
| Check name | Status | Explanation |
|---|---|---|
| Description Check | β Passed | Check skipped - CodeRabbitβs high-level summary is enabled. |
| Title check | β Passed | The title accurately summarizes the main change: adding a beginner-friendly LLM tracing example to the sample app. |
| Linked Issues check | β Passed | All requirements from issue #4069 are met: minimal setup guide, basic LLM call example, tracing demonstration, trace output visibility, and copyable format for beginners. |
| Out of Scope Changes check | β Passed | All changes are directly scoped to the linked issue: beginner example file, README updates, and exporter configuration. No unrelated modifications present. |
βοΈ Tip: You can configure your own custom pre-merge checks in the settings.
β¨ Finishing Touches
π§ͺ Generate unit tests (beta)
- [ ] Create PR with unit tests
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 @coderabbitai help to get the list of available commands and usage tips.
Thanks @coderabbitai β addressed all three in 06c2055:
poetry runβuv runin both the docstring and the README, matching the repo guideline.- Silent example β wired `exporter=ConsoleSpanExporter()` into `Traceloop.init` so spans land on stdout without needing `TRACELOOP_API_KEY` or an OTLP endpoint. Docstring + README updated to say so, with a note that real backends should drop the explicit exporter and use `TRACELOOP_API_KEY` / `OTEL_EXPORTER_OTLP_*` instead.
[!TIP] For best results, initiate chat on the files or code changes.
@NishchayMahor Thanks for the update! All three changes look great:
- β
uv runalignment keeps the example consistent with the repo's toolchain. - β
Wiring in
ConsoleSpanExporter()makes the example truly zero-config β new users can run it immediately without any credentials or backend setup. - β
The note pointing toward
TRACELOOP_API_KEY/OTEL_EXPORTER_OTLP_*for real deployments is a nice touch that bridges the beginner example to production use.
The changes address the original concerns well. π
If you found this review helpful, would you consider giving us a shout-out on X?
Thank you for using CodeRabbit!