-
Notifications
You must be signed in to change notification settings - Fork 0
feat: grpc client instrumentation #47
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
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,5 @@ | ||
| """gRPC client instrumentation.""" | ||
|
|
||
| from .instrumentation import GrpcInstrumentation | ||
|
|
||
| __all__ = ["GrpcInstrumentation"] |
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,27 @@ | ||
| version: 1 | ||
|
|
||
| service: | ||
| id: "grpc-e2e-test-id" | ||
| name: "grpc-e2e-test" | ||
| port: 8000 | ||
| start: | ||
| command: "python src/app.py" | ||
| readiness_check: | ||
| command: "curl -f http://localhost:8000/health" | ||
| timeout: 45s | ||
| interval: 5s | ||
|
|
||
| tusk_api: | ||
| url: "http://localhost:8000" | ||
|
|
||
| test_execution: | ||
| concurrent_limit: 10 | ||
| batch_size: 10 | ||
| timeout: 30s | ||
|
|
||
| recording: | ||
| sampling_rate: 1.0 | ||
| export_spans: false | ||
|
|
||
| replay: | ||
| enable_telemetry: false |
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,21 @@ | ||
| FROM python-e2e-base:latest | ||
|
|
||
| # Copy SDK source for editable install | ||
| COPY . /sdk | ||
|
|
||
| # Copy test files | ||
| COPY drift/instrumentation/grpc/e2e-tests /app | ||
|
|
||
| WORKDIR /app | ||
|
|
||
| # Install dependencies (requirements.txt uses -e /sdk for SDK) | ||
| RUN pip install -q -r requirements.txt | ||
|
|
||
| # Make entrypoint executable | ||
| RUN chmod +x entrypoint.py | ||
|
|
||
| # Create .tusk directories | ||
| RUN mkdir -p /app/.tusk/traces /app/.tusk/logs | ||
|
|
||
| # Run entrypoint | ||
| ENTRYPOINT ["python", "entrypoint.py"] | ||
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,19 @@ | ||
| services: | ||
| app: | ||
| build: | ||
| context: ../../../.. | ||
| dockerfile: drift/instrumentation/grpc/e2e-tests/Dockerfile | ||
| args: | ||
| - TUSK_CLI_VERSION=${TUSK_CLI_VERSION:-latest} | ||
| environment: | ||
| - PORT=8000 | ||
| - TUSK_ANALYTICS_DISABLED=1 | ||
| - PYTHONUNBUFFERED=1 | ||
| working_dir: /app | ||
| volumes: | ||
| # Mount SDK source for hot reload (no rebuild needed for SDK changes) | ||
| - ../../../..:/sdk | ||
| # Mount app source for development | ||
| - ./src:/app/src | ||
| # Mount .tusk folder to persist traces | ||
| - ./.tusk:/app/.tusk |
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,67 @@ | ||
| #!/usr/bin/env python3 | ||
| """ | ||
| E2E Test Entrypoint for gRPC Instrumentation | ||
|
|
||
| This script orchestrates the full e2e test lifecycle: | ||
| 1. Setup: Install dependencies, generate proto files | ||
| 2. Record: Start app in RECORD mode, execute requests | ||
| 3. Test: Run Tusk CLI tests | ||
| 4. Teardown: Cleanup and return exit code | ||
| """ | ||
|
|
||
| import sys | ||
| from pathlib import Path | ||
|
|
||
| # Add SDK to path for imports | ||
| sys.path.insert(0, "/sdk") | ||
|
|
||
| from drift.instrumentation.e2e_common.base_runner import E2ETestRunnerBase | ||
|
|
||
|
|
||
| class GrpcE2ETestRunner(E2ETestRunnerBase): | ||
| """E2E test runner for gRPC instrumentation.""" | ||
|
|
||
| def __init__(self): | ||
| import os | ||
|
|
||
| port = int(os.getenv("PORT", "8000")) | ||
| super().__init__(app_port=port) | ||
|
|
||
| def setup(self): | ||
| """Phase 1: Setup dependencies and generate proto files.""" | ||
| self.log("=" * 50, self.Colors.BLUE) | ||
| self.log("Phase 1: Setup", self.Colors.BLUE) | ||
| self.log("=" * 50, self.Colors.BLUE) | ||
|
|
||
| self.log("Installing Python dependencies...", self.Colors.BLUE) | ||
| self.run_command(["pip", "install", "-q", "-r", "requirements.txt"]) | ||
|
|
||
| # Generate proto files | ||
| self.log("Generating proto files...", self.Colors.BLUE) | ||
| self.run_command( | ||
| [ | ||
| "python", | ||
| "-m", | ||
| "grpc_tools.protoc", | ||
| "-I", | ||
| "src/proto", | ||
| "--python_out=src", | ||
| "--grpc_python_out=src", | ||
| "src/proto/greeter.proto", | ||
| ] | ||
| ) | ||
|
|
||
| self.log("Setup complete", self.Colors.GREEN) | ||
|
|
||
| # Use Colors from base class | ||
| @property | ||
| def Colors(self): | ||
| from drift.instrumentation.e2e_common.base_runner import Colors | ||
|
|
||
| return Colors | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| runner = GrpcE2ETestRunner() | ||
| exit_code = runner.run() | ||
| sys.exit(exit_code) |
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,5 @@ | ||
| -e /sdk | ||
| Flask>=3.1.2 | ||
| grpcio>=1.60.0 | ||
| grpcio-tools>=1.60.0 | ||
| protobuf>=6.0 |
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,64 @@ | ||
| #!/bin/bash | ||
|
|
||
| # Exit on error | ||
| set -e | ||
|
|
||
| # Accept optional port parameter (default: 8000) | ||
| APP_PORT=${1:-8000} | ||
| export APP_PORT | ||
|
|
||
| # Generate unique docker compose project name | ||
| # Get the instrumentation name (parent directory of e2e-tests) | ||
| TEST_NAME="$(basename "$(dirname "$(pwd)")")" | ||
| PROJECT_NAME="python-${TEST_NAME}-${APP_PORT}" | ||
|
|
||
| # Colors for output | ||
| GREEN='\033[0;32m' | ||
| RED='\033[0;31m' | ||
| YELLOW='\033[1;33m' | ||
| BLUE='\033[0;34m' | ||
| NC='\033[0m' | ||
|
|
||
| echo -e "${BLUE}========================================${NC}" | ||
| echo -e "${BLUE}Running Python E2E Test: ${TEST_NAME}${NC}" | ||
| echo -e "${BLUE}Port: ${APP_PORT}${NC}" | ||
| echo -e "${BLUE}========================================${NC}" | ||
| echo "" | ||
|
|
||
| # Cleanup function | ||
| cleanup() { | ||
| echo "" | ||
| echo -e "${YELLOW}Cleaning up containers...${NC}" | ||
| docker compose -p "$PROJECT_NAME" down -v 2>/dev/null || true | ||
| } | ||
|
|
||
| # Register cleanup on exit | ||
| trap cleanup EXIT | ||
|
|
||
| # Build containers | ||
| echo -e "${BLUE}Building containers...${NC}" | ||
| docker compose -p "$PROJECT_NAME" build --no-cache | ||
|
|
||
| # Run the test container | ||
| echo -e "${BLUE}Starting test...${NC}" | ||
| echo "" | ||
|
|
||
| # Run container and capture exit code (always use port 8000 inside container) | ||
| # Disable set -e temporarily to capture exit code | ||
| set +e | ||
| docker compose -p "$PROJECT_NAME" run --rm app | ||
| EXIT_CODE=$? | ||
| set -e | ||
|
|
||
| echo "" | ||
| if [ $EXIT_CODE -eq 0 ]; then | ||
| echo -e "${GREEN}========================================${NC}" | ||
| echo -e "${GREEN}Test passed!${NC}" | ||
| echo -e "${GREEN}========================================${NC}" | ||
| else | ||
| echo -e "${RED}========================================${NC}" | ||
| echo -e "${RED}Test failed with exit code ${EXIT_CODE}${NC}" | ||
| echo -e "${RED}========================================${NC}" | ||
| fi | ||
|
|
||
| exit $EXIT_CODE |
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.
Uh oh!
There was an error while loading. Please reload this page.