-
Notifications
You must be signed in to change notification settings - Fork 4
feat: examples #101
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
Merged
Merged
feat: examples #101
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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 |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| # Python | ||
| __pycache__/ | ||
| *.py[cod] | ||
| *$py.class | ||
| *.so | ||
| .Python | ||
|
|
||
| # Virtual environments | ||
| venv/ | ||
| env/ | ||
| ENV/ | ||
|
|
||
| # Hatch | ||
| .hatch/ | ||
|
|
||
| # Environment files - NEVER commit actual secrets! | ||
| .envrc | ||
| .envrc.local | ||
| .env | ||
| .env.local | ||
|
|
||
| # IDEs | ||
| .vscode/ | ||
| .idea/ | ||
| *.swp | ||
| *.swo | ||
| *~ | ||
|
|
||
| # OS | ||
| .DS_Store | ||
| Thumbs.db | ||
|
|
||
| # Logs | ||
| *.log | ||
|
|
||
| # Testing | ||
| .pytest_cache/ | ||
| .coverage | ||
| htmlcov/ |
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 |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| [build-system] | ||
| requires = ["hatchling"] | ||
| build-backend = "hatchling.build" | ||
|
|
||
| [project] | ||
| name = "basalt-microservices-example" | ||
| version = "0.1.0" | ||
| description = "Microservices example demonstrating Basalt observability across HTTP communication" | ||
| readme = "README.md" | ||
|
CorentinGS marked this conversation as resolved.
|
||
| requires-python = ">=3.10" | ||
| dependencies = [] | ||
|
|
||
| [tool.hatch.envs.default] | ||
| detached = true | ||
| dependencies = [ | ||
| # Web framework dependencies | ||
| "fastapi>=0.104.0", | ||
| "uvicorn[standard]>=0.24.0", | ||
| "httpx>=0.25.0", | ||
|
|
||
|
CorentinGS marked this conversation as resolved.
|
||
| # LLM SDKs | ||
| "openai==2.15.0", | ||
| "google-genai==1.60.0", | ||
|
|
||
| # LLM Auto-instrumentation (FastAPI instrumentation removed due to conflicts with Basalt) | ||
| "opentelemetry-instrumentation-openai~=0.51.0", | ||
| # "opentelemetry-instrumentation-google-genai~=0.5b0", # NEW Google GenAI SDK (from google import genai) | ||
| "opentelemetry-instrumentation-google-generativeai~=0.51.0", | ||
| "opentelemetry-instrumentation-fastapi", | ||
| # OTLP Exporter for local telemetry collection | ||
| "opentelemetry-exporter-otlp-proto-grpc~=1.39.1", | ||
| ] | ||
|
|
||
| [tool.hatch.envs.default.scripts] | ||
| service-a = "uvicorn service_a.main:app --host 0.0.0.0 --port 8001" | ||
| service-b = "uvicorn service_b.main:app --host 0.0.0.0 --port 8002" | ||
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 |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| #!/usr/bin/env bash | ||
| set -e | ||
|
|
||
| # Colors for output | ||
| RED='\033[0;31m' | ||
| GREEN='\033[0;32m' | ||
| YELLOW='\033[1;33m' | ||
| NC='\033[0m' # No Color | ||
|
|
||
| # Check if direnv is loaded | ||
| if [ -z "$BASALT_API_KEY" ]; then | ||
| echo -e "${RED}Error: Environment not loaded.${NC}" | ||
| echo "Please run: ${YELLOW}direnv allow${NC}" | ||
| echo "Then edit .envrc with your Basalt API key" | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo -e "${GREEN}Environment loaded successfully${NC}" | ||
| echo "BASALT_ENVIRONMENT: $BASALT_ENVIRONMENT" | ||
| echo "BASALT_SERVICE_NAME: $BASALT_SERVICE_NAME" | ||
| echo "" | ||
|
|
||
| # Change to the microservices directory | ||
| cd "$(dirname "$0")" | ||
|
|
||
| # Check if hatch environment exists | ||
| if ! hatch env show default &>/dev/null; then | ||
| echo -e "${YELLOW}Creating hatch environment...${NC}" | ||
| hatch env create | ||
| fi | ||
|
|
||
| # Install basalt-py from parent directory | ||
| echo -e "${YELLOW}Installing basalt-py from parent directory...${NC}" | ||
| hatch run pip install -q -e ../.. | ||
|
|
||
| echo -e "${GREEN}Starting microservices...${NC}" | ||
| echo "" | ||
|
|
||
| # Start services in background | ||
| echo -e "${GREEN}Starting Service B on port 8002...${NC}" | ||
| hatch run service-b & | ||
| SERVICE_B_PID=$! | ||
|
|
||
| # Wait a moment for Service B to start | ||
| sleep 2 | ||
|
|
||
| echo -e "${GREEN}Starting Service A on port 8001...${NC}" | ||
| hatch run service-a & | ||
| SERVICE_A_PID=$! | ||
|
|
||
| # Wait for services to fully start | ||
| sleep 2 | ||
|
|
||
| # Trap to cleanup on exit | ||
| trap "echo -e '\n${YELLOW}Shutting down services...${NC}'; kill $SERVICE_A_PID $SERVICE_B_PID 2>/dev/null; exit 0" SIGINT SIGTERM EXIT | ||
|
|
||
| echo "" | ||
| echo -e "${GREEN}✓ Services started successfully!${NC}" | ||
| echo "" | ||
| echo "Service A: http://localhost:8001" | ||
| echo "Service B: http://localhost:8002" | ||
| echo "" | ||
| echo -e "${YELLOW}Test the microservices:${NC}" | ||
| echo " curl http://localhost:8001/process-request" | ||
| echo "" | ||
| echo -e "${YELLOW}Health checks:${NC}" | ||
| echo " curl http://localhost:8001/health" | ||
| echo " curl http://localhost:8002/health" | ||
| echo "" | ||
| echo -e "${RED}Press Ctrl+C to stop all services${NC}" | ||
| echo "" | ||
|
|
||
| # Wait for processes | ||
| wait |
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 |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| """Service A - Primary service that orchestrates requests to Service B.""" |
Oops, something went wrong.
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.
Root-span detection now treats
start_observespans 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 noROOT_SPAN_CONTEXT_KEY) and assertsstart_observesetsbasalt.rootand attachesROOT_SPAN_CONTEXT_KEY.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.
@copilot open a new pull request to apply changes based on this feedback