# PHP Instrument PHP applications with OpenTelemetry # Integration Instrument your PHP applications to send traces, logs, and metrics to Kopai. ## Installation ```bash composer require open-telemetry/sdk open-telemetry/exporter-otlp \ php-http/guzzle7-adapter guzzlehttp/guzzle nyholm/psr7 ``` ## Basic Setup ```php merge( ResourceInfo::create(Attributes::create([ ResourceAttributes::SERVICE_NAME => $serviceName, ])) ); // Create OTLP HTTP exporter $transport = PsrTransportFactory::discover()->create( "$endpoint/v1/traces", ContentTypes::JSON ); $exporter = new SpanExporter($transport); // Build and register tracer provider $tracerProvider = TracerProvider::builder() ->addSpanProcessor(new SimpleSpanProcessor($exporter)) ->setResource($resource) ->build(); // Get tracer and create spans $tracer = $tracerProvider->getTracer('my-app'); $span = $tracer->spanBuilder('my-operation')->startSpan(); // ... your code $span->end(); ``` ## Running Your Application Set the required environment variables and run: ```bash export OTEL_EXPORTER_OTLP_ENDPOINT="https://otlp-http.kopai.app" export OTEL_SERVICE_NAME="my-service" php -S 0.0.0.0:8080 ``` | Variable | Description | |----------|-------------| | `OTEL_EXPORTER_OTLP_ENDPOINT` | Kopai OTLP endpoint | | `OTEL_SERVICE_NAME` | Name shown in Kopai UI | ## Working Example For a complete working example: **[PHP Example](https://github.com/kopai-app/kopai-integration-examples/tree/main/php)**