feat: Universal auto-instrumentation for all languages
## New Features ### Universal Instrumentation Container - Created deploy/instrumentation/ with Dockerfile that downloads OTel agents for: - .NET (glibc and musl/Alpine versions) - Node.js (with auto-instrumentation package) - Python (bootstrap script + requirements) - Java (javaagent JAR) - Go (example code for compile-time instrumentation) - PHP (composer package + init script) ### Universal instrument.sh Script - Auto-detects application language from running processes - Generates docker-compose snippets for each language - Supports: dotnet, nodejs, python, java, go, php - Usage: ./instrument.sh <container> [language] [otlp_endpoint] ### Improved docker-compose.yml - Added instrumentation init container with shared volume - Added AGENT_KEY environment variable for proper auth - Added ophion-agent service for host metrics collection - Named containers for easier management - Added ophion-network for service discovery ### Documentation - Created docs/QUICK_START.md with: - Single-command installation - Instrumentation guide for all languages - Troubleshooting section - Authentication guide ### Auth Fixes - Server now properly validates AGENT_KEY for agent authentication - OTel Collector configured with AGENT_KEY for forwarding to server - Fixed 401 errors when agents connect ## Files Changed - docker-compose.yml: Complete stack with all services - deploy/instrumentation/*: Universal OTel agent container - deploy/docker/otel-collector-config.yaml: Fixed auth headers - instrument.sh: Universal instrumentation script - docs/QUICK_START.md: Complete quick start guide - README.md: Updated with new features - .env.example: Added AGENT_KEY ## Testing - Go code compiles successfully - Docker images build correctly - All changes are backwards compatible
This commit is contained in:
29
deploy/instrumentation/files/php/otel_init.php
Normal file
29
deploy/instrumentation/files/php/otel_init.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
/**
|
||||
* OPHION PHP OpenTelemetry Initialization
|
||||
* Include this file in your application bootstrap
|
||||
*/
|
||||
|
||||
use OpenTelemetry\SDK\Sdk;
|
||||
use OpenTelemetry\SDK\Trace\TracerProvider;
|
||||
use OpenTelemetry\SDK\Trace\SpanProcessor\SimpleSpanProcessor;
|
||||
use OpenTelemetry\Contrib\Otlp\SpanExporter;
|
||||
use OpenTelemetry\SDK\Common\Export\Http\PsrTransportFactory;
|
||||
use OpenTelemetry\SDK\Resource\ResourceInfo;
|
||||
use OpenTelemetry\SDK\Common\Attribute\Attributes;
|
||||
|
||||
$endpoint = getenv('OTEL_EXPORTER_OTLP_ENDPOINT') ?: 'http://localhost:4318';
|
||||
$serviceName = getenv('OTEL_SERVICE_NAME') ?: 'php-app';
|
||||
|
||||
try {
|
||||
$transport = (new PsrTransportFactory())->create($endpoint . '/v1/traces', 'application/json');
|
||||
$exporter = new SpanExporter($transport);
|
||||
$tracerProvider = TracerProvider::builder()
|
||||
->addSpanProcessor(new SimpleSpanProcessor($exporter))
|
||||
->setResource(ResourceInfo::create(Attributes::create(['service.name' => $serviceName])))
|
||||
->build();
|
||||
Sdk::builder()->setTracerProvider($tracerProvider)->buildAndRegisterGlobal();
|
||||
error_log('[OPHION] OpenTelemetry initialized for PHP');
|
||||
} catch (Exception $e) {
|
||||
error_log('[OPHION] Failed to initialize OpenTelemetry: ' . $e->getMessage());
|
||||
}
|
||||
Reference in New Issue
Block a user