forked from open-telemetry/opentelemetry-php
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AlwaysOnZipkinExample.php
52 lines (42 loc) · 1.36 KB
/
AlwaysOnZipkinExample.php
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
declare(strict_types=1);
require __DIR__ . '/../vendor/autoload.php';
use GuzzleHttp\Client;
use GuzzleHttp\Psr7\HttpFactory;
use OpenTelemetry\Contrib\Zipkin\Exporter as ZipkinExporter;
use OpenTelemetry\SDK\Common\Attribute\Attributes;
use OpenTelemetry\SDK\Trace\SpanProcessor\SimpleSpanProcessor;
use OpenTelemetry\SDK\Trace\TracerProvider;
$zipkinExporter = new ZipkinExporter(
'alwaysOnZipkinExample',
'http://zipkin:9411/api/v2/spans',
new Client(),
new HttpFactory(),
new HttpFactory()
);
$tracerProvider = new TracerProvider(
new SimpleSpanProcessor(
$zipkinExporter
)
);
$tracer = $tracerProvider->getTracer();
echo 'Starting AlwaysOnZipkinExample';
$root = $span = $tracer->spanBuilder('root')->startSpan();
$span->activate();
for ($i = 0; $i < 3; $i++) {
// start a span, register some events
$span = $tracer->spanBuilder('loop-' . $i)->startSpan();
$span->setAttribute('remote_ip', '1.2.3.4')
->setAttribute('country', 'USA');
$span->addEvent('found_login' . $i, new Attributes([
'id' => $i,
'username' => 'otuser' . $i,
]));
$span->addEvent('generated_session', new Attributes([
'id' => md5((string) microtime(true)),
]));
$span->end();
}
$root->end();
echo PHP_EOL . 'AlwaysOnZipkinExample complete! See the results at http://localhost:9411/';
echo PHP_EOL;