feat: examples#101
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a runnable microservices example showcasing Basalt observability across HTTP boundaries, and updates Basalt instrumentation behavior to better support framework-created parent spans.
Changes:
- Add FastAPI “Service A / Service B” microservices example with distributed tracing, LLM calls, and prompt usage.
- Improve Basalt root-span detection so
start_observecan act as a Basalt root even when invoked under non-Basalt parent spans (e.g., FastAPI/httpx). - Update lockfile dependencies (e.g.,
openai,google-genai,google-auth) and add a small instrumentation fallback.
Reviewed changes
Copilot reviewed 10 out of 11 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| uv.lock | Dependency resolution updates and new entries. |
| pyproject.toml | Removes an outdated comment in optional-deps section. |
| examples/microservices/service_a/main.py | Service A example (FastAPI + httpx + OpenAI + Basalt spans). |
| examples/microservices/service_a/init.py | Package marker for Service A. |
| examples/microservices/service_b/main.py | Service B example (FastAPI + retrieval span + Google GenAI + Basalt prompts). |
| examples/microservices/service_b/init.py | Package marker for Service B. |
| examples/microservices/run.sh | Convenience script to run both services via Hatch. |
| examples/microservices/pyproject.toml | Hatch env definition for the microservices example. |
| examples/microservices/.gitignore | Ignores local env/IDE artifacts for the microservices example. |
| basalt/observability/instrumentation.py | Adds fallback import logic for Google GenAI instrumentation. |
| basalt/observability/context_managers.py | Updates Basalt root-span detection logic to cooperate with external parent spans. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| # Determine if this should be treated as a Basalt root span | ||
| # A span is a Basalt root if: | ||
| # 1. There's no parent span at all (true root), OR | ||
| # 2. This is a start_observe (span_type="basalt_trace") AND the parent is NOT a Basalt span | ||
| # (e.g., parent is from FastAPI, httpx, or other instrumentation) |
There was a problem hiding this comment.
Root-span detection now treats start_observe spans as Basalt roots when there’s a non-Basalt parent span (e.g., FastAPI/httpx). There are existing context-manager tests, but none appear to cover the “external parent span present” case; add a unit test that sets a non-Basalt current span (with no ROOT_SPAN_CONTEXT_KEY) and asserts start_observe sets basalt.root and attaches ROOT_SPAN_CONTEXT_KEY.
There was a problem hiding this comment.
@copilot open a new pull request to apply changes based on this feedback
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
@CorentinGS I've opened a new pull request, #102, to work on those changes. Once the pull request is ready, I'll request review from you. |
No description provided.