-
Notifications
You must be signed in to change notification settings - Fork 222
Expand file tree
/
Copy pathautoload_sdk.php
More file actions
26 lines (18 loc) · 918 Bytes
/
autoload_sdk.php
File metadata and controls
26 lines (18 loc) · 918 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<?php
declare(strict_types=1);
namespace OpenTelemetry\Example;
putenv('OTEL_PHP_AUTOLOAD_ENABLED=true');
putenv('OTEL_TRACES_EXPORTER=otlp');
putenv('OTEL_METRICS_EXPORTER=otlp');
putenv('OTEL_LOGS_EXPORTER=otlp');
putenv('OTEL_EXPORTER_OTLP_PROTOCOL=grpc');
putenv('OTEL_EXPORTER_OTLP_ENDPOINT=http://collector:4317');
putenv('OTEL_PROPAGATORS=b3,baggage,tracecontext');
echo 'autoloading SDK example starting...' . PHP_EOL;
// Composer autoloader will execute SDK/_autoload.php which will register global instrumentation from environment configuration
require dirname(__DIR__) . '/vendor/autoload.php';
$instrumentation = new \OpenTelemetry\API\Instrumentation\CachedInstrumentation('demo');
$instrumentation->tracer()->spanBuilder('root')->startSpan()->end();
$instrumentation->meter()->createCounter('cnt')->add(1);
$instrumentation->eventLogger()->emit('foo', 'hello, otel');
echo 'Finished!' . PHP_EOL;