-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathparent-transactions.php
47 lines (34 loc) · 1.31 KB
/
parent-transactions.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
<?php
//
// This example demonstrates the use of parent transactions to link transactions together.
//
require __DIR__ . '/vendor/autoload.php';
use Nipwaayoni\Agent;
$config = [
'serviceName' => 'examples',
'serviceVersion' => '1.0.0-beta',
];
$agent = (new \Nipwaayoni\AgentBuilder())
->withConfig(new Nipwaayoni\Config($config))
->build();
// Start a new parent Transaction
$parent = $agent->startTransaction('GET /users');
// Start a child Transaction and set the Parent
$childOne = $agent->startTransaction('http.session.get.auth.data');
$childOne->setParent($parent);
// Do stuff ..
usleep(rand(1000, 99999));
$agent->stopTransaction($childOne->getTransactionName());
// Start another child Transaction and set the Parent
$childTwo = $agent->startTransaction('elasticsearch.search.active.users');
$childTwo->setParent($parent);
// Do stuff ..
usleep(rand(1000, 99999));
$agent->stopTransaction($childTwo->getTransactionName());
// Create a 3rd child Transaction that is throwing an exception
$childThree = $agent->startTransaction('division.by.zero');
$childThree->setParent($parent);
$agent->captureThrowable( new Exception("division by 0 exception"), [], $childThree );
$agent->stopTransaction($childThree->getTransactionName());
$agent->stopTransaction($parent->getTransactionName());
// $agent->send();