-
Notifications
You must be signed in to change notification settings - Fork 1.1k
docs(sample-app): add Groq getting started guide for beginners #4469
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
priyanshiranawat15
wants to merge
4
commits into
traceloop:main
Choose a base branch
from
priyanshiranawat15:docs/sample-app-groq-readme
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
Show all changes
4 commits
Select commit
Hold shift + click to select a range
87c230e
docs(sample-app): add Groq getting started guide for beginners
priyanshiranawat15 74a7e29
fix(sample-app): address CodeRabbit review feedback
priyanshiranawat15 3a33571
docs(sample-app): add step-by-step Groq guide with terminal screenshots
priyanshiranawat15 8e07048
docs(sample-app): add dedicated joke output screenshot to README
priyanshiranawat15 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
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 |
|---|---|---|
| @@ -1,3 +1,247 @@ | ||
| # sample-app | ||
| # Sample App — Groq Getting Started Guide | ||
|
|
||
| Project description here. | ||
| Runnable examples for tracing LLM applications with [OpenLLMetry](https://github.com/traceloop/openllmetry). | ||
|
|
||
| This guide walks you through **`groq_example.py`** step by step. Groq is a great first example because it has a **free API tier** and returns responses quickly. | ||
|
|
||
| --- | ||
|
|
||
| ## What you'll learn | ||
|
|
||
| By the end of this guide you will: | ||
|
|
||
| 1. Set up the sample app locally | ||
| 2. Run a Groq LLM call with OpenLLMetry tracing enabled | ||
| 3. Read the trace output in your terminal | ||
| 4. Understand how **workflow**, **task**, and **LLM** spans relate to each other | ||
| 5. Confirm the LLM response (joke) printed in your terminal | ||
|
|
||
| --- | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| Before you start, make sure you have: | ||
|
|
||
| | Requirement | Why | | ||
| |-------------|-----| | ||
| | Python 3.10–3.12 | See `.python-version` in this folder | | ||
| | [Node.js](https://nodejs.org/) | Runs monorepo commands (`nx`) | | ||
| | [uv](https://docs.astral.sh/uv/) | Python package manager used by this repo | | ||
| | [Groq API key](https://console.groq.com/keys) | Free tier available — used to call the LLM | | ||
|
|
||
| > **No Traceloop cloud account required.** This example prints traces directly to your terminal. | ||
|
|
||
| --- | ||
|
|
||
| ## Step 1 — Clone and install dependencies | ||
|
|
||
| From the **repository root**: | ||
|
|
||
| ```bash | ||
| git clone https://github.com/traceloop/openllmetry.git | ||
| cd openllmetry | ||
| npm ci | ||
| npx nx run sample-app:install | ||
| ``` | ||
|
|
||
| **What this does:** | ||
| - `npm ci` installs JavaScript tooling for the monorepo | ||
| - `npx nx run sample-app:install` creates a Python virtual environment and installs all sample-app dependencies (including `traceloop-sdk` and Groq instrumentation) | ||
|
|
||
| --- | ||
|
|
||
| ## Step 2 — Get a Groq API key | ||
|
|
||
| 1. Go to [console.groq.com](https://console.groq.com/) | ||
| 2. Sign up (free tier is fine) | ||
| 3. Open **API Keys** → **Create API Key** | ||
| 4. Copy the key — it starts with `gsk_` | ||
|
|
||
| --- | ||
|
|
||
| ## Step 3 — Configure your environment | ||
|
|
||
| ```bash | ||
| cd packages/sample-app | ||
| cp .env.example .env | ||
| ``` | ||
|
|
||
| Edit `.env` and set your Groq key (**no space** after `=`): | ||
|
|
||
| ```bash | ||
| GROQ_API_KEY=gsk-your-key-here | ||
| ``` | ||
|
|
||
| Load the variables into your terminal: | ||
|
|
||
| ```bash | ||
| set -a | ||
| source .env | ||
| set +a | ||
| ``` | ||
|
|
||
| Verify the key is set (does not print the key itself): | ||
|
|
||
| ```bash | ||
| echo "GROQ_API_KEY set: ${GROQ_API_KEY:+yes}" | ||
| ``` | ||
|
|
||
| For local terminal tracing, **do not set** `TRACELOOP_API_KEY` (or comment it out in `.env`): | ||
|
|
||
| ```bash | ||
| unset TRACELOOP_API_KEY | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## Step 4 — Run the example | ||
|
|
||
| ```bash | ||
| cd packages/sample-app | ||
| uv run --with 'groq>=0.18' python sample_app/groq_example.py | ||
| ``` | ||
|
|
||
| > The `--with 'groq>=0.18'` flag avoids a known `groq`/`httpx` version mismatch in some environments. | ||
|
|
||
| You should see tracing initialize, then JSON spans, then a joke: | ||
|
|
||
|  | ||
|
|
||
| --- | ||
|
|
||
| ## Step 5 — Read the Groq LLM span | ||
|
|
||
| OpenLLMetry automatically instruments the Groq API call. Look for a span named `chat openai/gpt-oss-120b` with `"status_code": "OK"`: | ||
|
|
||
|  | ||
|
|
||
| **Key fields to notice:** | ||
|
|
||
| | Field | Meaning | | ||
| |-------|---------| | ||
| | `"gen_ai.provider.name": "groq"` | Which LLM provider was called | | ||
| | `"gen_ai.request.model"` | Model used for the request | | ||
| | `"gen_ai.usage.total_tokens"` | Tokens consumed (input + output) | | ||
| | `"status_code": "OK"` | The Groq call succeeded | | ||
|
|
||
| --- | ||
|
|
||
| ## Step 6 — Read the task span | ||
|
|
||
| The `@task` decorator wraps `generate_joke()`. Its span captures the function input/output: | ||
|
|
||
|  | ||
|
|
||
| --- | ||
|
|
||
| ## Step 7 — See the joke printed in your terminal | ||
|
|
||
| Between the JSON trace blocks, the script prints the Groq response as plain text — this is the actual LLM output: | ||
|
|
||
|  | ||
|
|
||
| If you see a joke like this, your Groq API key and tracing setup are working correctly. | ||
|
|
||
| --- | ||
|
|
||
| ## Step 8 — Read the workflow span | ||
|
|
||
| The `@workflow` decorator wraps `joke_generator()` — the top-level entry point: | ||
|
|
||
|  | ||
|
|
||
| All spans share the same `trace_id`, which ties them together as one traced request. | ||
|
|
||
| --- | ||
|
|
||
| ## Trace hierarchy (big picture) | ||
|
|
||
| ```text | ||
| joke_generator.workflow ← @workflow (top level) | ||
| └── generate_joke.task ← @task (your function) | ||
| └── chat openai/gpt-oss-120b ← auto-instrumented Groq API call | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## How the code works | ||
|
|
||
| ```python | ||
| from traceloop.sdk import Traceloop | ||
| from traceloop.sdk.decorators import task, workflow | ||
|
|
||
| Traceloop.init(app_name="groq_example", disable_batch=True) | ||
|
|
||
| @task(name="generate_joke") | ||
| def generate_joke(): | ||
| # Groq call is traced automatically | ||
| ... | ||
|
|
||
| @workflow(name="joke_generator") | ||
| def joke_generator(): | ||
| generate_joke() | ||
| ``` | ||
|
|
||
| See the full script: [`sample_app/groq_example.py`](./sample_app/groq_example.py) | ||
|
|
||
| **Design choices in this example:** | ||
|
|
||
| - **`ConsoleSpanExporter`** — prints traces to your terminal when `TRACELOOP_API_KEY` is not set (no cloud account needed) | ||
| - **`disable_batch=True`** — shows spans immediately instead of batching them | ||
| - **`@workflow` / `@task`** — groups your code into readable trace hierarchy | ||
|
|
||
| --- | ||
|
|
||
| ## Exporting traces to the cloud (optional) | ||
|
|
||
| To send traces to [Traceloop Cloud](https://app.traceloop.com) instead of the terminal, add to `.env`: | ||
|
|
||
| ```bash | ||
| TRACELOOP_API_KEY=your-valid-traceloop-api-key | ||
| ``` | ||
|
|
||
| See the [getting started guide](https://traceloop.com/docs/openllmetry/getting-started-python) for Datadog, Grafana, and other backends. | ||
|
|
||
| --- | ||
|
|
||
| ## Troubleshooting | ||
|
|
||
| | Problem | Fix | | ||
| |---------|-----| | ||
| | `Missing Traceloop API key` | Safe to ignore if traces print to terminal; or unset `TRACELOOP_API_KEY` | | ||
| | `401 Unauthorized` from Traceloop | Invalid `TRACELOOP_API_KEY` — comment it out for local tracing | | ||
| | `GROQ_API_KEY` not set / `Bearer ` error | Check `.env` has no space after `=`; run `source .env` | | ||
| | Model not found (404) | Check [Groq models](https://console.groq.com/docs/models) and update `MODEL` in `groq_example.py` | | ||
| | `proxies` TypeError | Run with `uv run --with 'groq>=0.18' python sample_app/groq_example.py` | | ||
| | Watsonx warning | Harmless — optional dependency not installed | | ||
|
|
||
| --- | ||
|
|
||
| ## More examples | ||
|
|
||
| Browse [`sample_app/`](./sample_app/) for other providers and frameworks: | ||
|
|
||
| | Category | Examples | | ||
| |----------|----------| | ||
| | LLM providers | `openai_streaming.py`, `anthropic_joke_example.py`, `cohere_example.py` | | ||
| | Local models | `ollama_streaming.py` | | ||
| | Frameworks | `langchain_app.py`, `langgraph_example.py`, `crewai_example.py` | | ||
| | Vector DBs | `chroma_app.py`, `pinecone_app.py`, `qdrant_app.py` | | ||
|
|
||
| --- | ||
|
|
||
| ## Development commands | ||
|
|
||
| From the repository root: | ||
|
|
||
| ```bash | ||
| npx nx run sample-app:lint | ||
| npx nx run sample-app:test | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## Contributing | ||
|
|
||
| - [Contributing guide](https://traceloop.com/docs/openllmetry/contributing/overview) | ||
| - [Slack community](https://traceloop.com/slack) | ||
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Remove the redundant
cdfrom Step 4.When Steps 3 and 4 run in the same shell, Step 3 leaves the working directory at
packages/sample-app. Step 4 then attempts to enterpackages/sample-app/packages/sample-app, which reports an error. The subsequentuv runcan still use the existing directory, but the documented sequence contains an avoidable failure. Remove the Step 4cd packages/sample-appcommand.🤖 Prompt for AI Agents