|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Development Setup |
| 6 | + |
| 7 | +This project uses the "3 Musketeers" pattern: Docker + Make + Compose. Most commands run inside Docker containers. |
| 8 | + |
| 9 | +```bash |
| 10 | +cp .env.dist .env # Required before first use |
| 11 | +make install # Install dependencies |
| 12 | +``` |
| 13 | + |
| 14 | +Set `PHP_VERSION` (8.1, 8.2, 8.3) to test against specific PHP versions: `PHP_VERSION=8.1 make all` |
| 15 | + |
| 16 | +## Common Commands |
| 17 | + |
| 18 | +```bash |
| 19 | +make test # Unit + integration tests |
| 20 | +make test-unit # Unit tests only |
| 21 | +make test-integration # Integration tests only |
| 22 | +make style # Run php-cs-fixer (auto-fix) |
| 23 | +make rector-write # Apply rector refactoring |
| 24 | +make deptrac # Check architectural layer dependencies |
| 25 | +make phan # Phan static analysis |
| 26 | +make psalm # Psalm static analysis |
| 27 | +make phpstan # PHPStan static analysis |
| 28 | +make all # Full CI suite (run before submitting PRs) |
| 29 | +make all-lowest # Same but with lowest dependency versions |
| 30 | +``` |
| 31 | + |
| 32 | +### Running a single test |
| 33 | + |
| 34 | +```bash |
| 35 | +# Run a specific test file |
| 36 | +vendor/bin/phpunit tests/Unit/SDK/Trace/SpanTest.php |
| 37 | + |
| 38 | +# Run with a filter |
| 39 | +vendor/bin/phpunit --filter testSomeMethod |
| 40 | +``` |
| 41 | + |
| 42 | +Or via Docker: `docker compose run --rm php vendor/bin/phpunit tests/Unit/...` |
| 43 | + |
| 44 | +## Architecture |
| 45 | + |
| 46 | +This is a **monorepo** — packages are distributed to Packagist individually via git subtree splits (`.gitsplit.yml`). |
| 47 | + |
| 48 | +### Package Structure (`/src`) |
| 49 | + |
| 50 | +| Package | Purpose | |
| 51 | +|---------|---------| |
| 52 | +| `API/` | Core interfaces, noop implementations, late-binding providers | |
| 53 | +| `SDK/` | Concrete implementations of the API (Trace, Metrics, Logs, Propagation, Resource) | |
| 54 | +| `Context/` | Context storage, scope management, Fiber support | |
| 55 | +| `Config/` | SDK configuration from environment/YAML using ComponentProvider pattern | |
| 56 | +| `Contrib/` | OTLP exporters (gRPC, HTTP), Zipkin, gRPC transport | |
| 57 | +| `Extension/` | B3 and CloudTrace propagators | |
| 58 | +| `SemConv/` | Semantic convention attributes (auto-generated from OTel spec) | |
| 59 | + |
| 60 | +### Key Architectural Patterns |
| 61 | + |
| 62 | +- **API/SDK separation**: `API/` defines interfaces and noops; `SDK/` provides real implementations. User code should depend on API only. |
| 63 | +- **SPI plugin discovery**: Plugins register via `composer.json` `extra.spi` for auto-discovery. |
| 64 | +- **Late binding**: Providers can be registered after app startup; noop implementations handle the uninitialized state. |
| 65 | +- **Architectural layers**: `deptrac.yaml` enforces that `API` cannot depend on `SDK`, `Contrib`, etc. Run `make deptrac` to validate. |
| 66 | + |
| 67 | +### Test Layout |
| 68 | + |
| 69 | +- `tests/Unit/` — Pure unit tests, mirrors `src/` structure |
| 70 | +- `tests/Integration/` — Tests requiring external services (collector, Jaeger, Zipkin) |
| 71 | +- `tests/TraceContext/` — W3C TraceContext compliance tests |
| 72 | +- `tests/Benchmark/` — Performance benchmarks |
| 73 | + |
| 74 | +### Signal Types |
| 75 | + |
| 76 | +OpenTelemetry has three signals, each with parallel implementations: |
| 77 | +- **Traces**: `API/Trace/`, `SDK/Trace/` |
| 78 | +- **Metrics**: `API/Metrics/`, `SDK/Metrics/` |
| 79 | +- **Logs**: `API/Logs/`, `SDK/Logs/` |
| 80 | + |
| 81 | +### Exporters |
| 82 | + |
| 83 | +Exporters live in `SDK/*/Export/` (built-in) or `Contrib/` (OTLP, Zipkin). OTLP supports both HTTP (JSON/Protobuf) and gRPC transports. Protobuf definitions are in `/proto/`. |
| 84 | + |
| 85 | +## CI Requirements |
| 86 | + |
| 87 | +PRs must pass `make all` cleanly: |
| 88 | +1. `rector` — no refactoring suggestions |
| 89 | +2. `style` — no code style violations |
| 90 | +3. `deptrac` — no architectural layer violations |
| 91 | +4. `phan`, `psalm`, `phpstan` — no static analysis errors |
| 92 | +5. `test` — all tests pass with coverage metadata |
| 93 | + |
| 94 | +## Mago |
| 95 | + |
| 96 | +The project includes Mago (a PHP linter/fixer) checks in CI. These are currently **non-blocking** but configured via `.github/workflows/`. |
0 commit comments