1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of Ekino New Relic bundle. |
7
|
|
|
* |
8
|
|
|
* (c) Ekino - Thomas Rabaix <[email protected]> |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
11
|
|
|
* file that was distributed with this source code. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Ekino\NewRelicBundle\NewRelic; |
15
|
|
|
|
16
|
|
|
use Psr\Log\LoggerInterface; |
17
|
|
|
use Psr\Log\NullLogger; |
18
|
|
|
|
19
|
|
|
class LoggingInteractorDecorator implements NewRelicInteractorInterface |
20
|
|
|
{ |
21
|
|
|
private $interactor; |
22
|
|
|
private $logger; |
23
|
|
|
|
24
|
|
|
public function __construct(NewRelicInteractorInterface $interactor, LoggerInterface $logger = null) |
25
|
|
|
{ |
26
|
|
|
$this->interactor = $interactor; |
27
|
|
|
$this->logger = $logger ?? new NullLogger(); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function setApplicationName(string $name, string $key = null, bool $xmit = false): bool |
31
|
|
|
{ |
32
|
|
|
$this->logger->debug('Setting New Relic Application name to {name}', ['name' => $name]); |
33
|
|
|
|
34
|
|
|
return $this->interactor->setApplicationName($name, $key, $xmit); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function setTransactionName(string $name): bool |
38
|
|
|
{ |
39
|
|
|
$this->logger->debug('Setting New Relic Transaction name to {name}', ['name' => $name]); |
40
|
|
|
|
41
|
|
|
return $this->interactor->setTransactionName($name); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function ignoreTransaction(): void |
45
|
|
|
{ |
46
|
|
|
$this->logger->debug('Ignoring transaction'); |
47
|
|
|
$this->interactor->ignoreTransaction(); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function addCustomEvent(string $name, array $attributes): void |
51
|
|
|
{ |
52
|
|
|
$this->logger->debug('Adding custom New Relic event {name}', ['name' => $name, 'attributes' => $attributes]); |
53
|
|
|
$this->interactor->addCustomEvent($name, $attributes); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function addCustomMetric(string $name, float $value): bool |
57
|
|
|
{ |
58
|
|
|
$this->logger->debug('Adding custom New Relic metric {name}: {value}', ['name' => $name, 'value' => $value]); |
59
|
|
|
|
60
|
|
|
return $this->interactor->addCustomMetric($name, $value); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function addCustomParameter(string $name, $value): bool |
64
|
|
|
{ |
65
|
|
|
$this->logger->debug('Adding custom New Relic parameters {name}: {value}', ['name' => $name, 'value' => $value]); |
66
|
|
|
|
67
|
|
|
return $this->interactor->addCustomParameter($name, $value); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function getBrowserTimingHeader(bool $includeTags = true): string |
71
|
|
|
{ |
72
|
|
|
$this->logger->debug('Getting New Relic RUM timing header'); |
73
|
|
|
|
74
|
|
|
return $this->interactor->getBrowserTimingHeader($includeTags); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
public function getBrowserTimingFooter(bool $includeTags = true): string |
78
|
|
|
{ |
79
|
|
|
$this->logger->debug('Getting New Relic RUM timing footer'); |
80
|
|
|
|
81
|
|
|
return $this->interactor->getBrowserTimingFooter($includeTags); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
public function disableAutoRUM(): bool |
85
|
|
|
{ |
86
|
|
|
$this->logger->debug('Disabling New Relic Auto-RUM'); |
87
|
|
|
|
88
|
|
|
return $this->interactor->disableAutoRUM(); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
public function noticeError(int $errno, string $errstr, string $errfile = null, int $errline = null, string $errcontext = null): void |
92
|
|
|
{ |
93
|
|
|
$this->logger->debug('Sending notice error to New Relic'); |
94
|
|
|
$this->interactor->noticeError($errno, $errstr, $errfile, $errline, $errcontext); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
public function noticeThrowable(\Throwable $e, string $message = null): void |
98
|
|
|
{ |
99
|
|
|
$this->logger->debug('Sending exception to New Relic'); |
100
|
|
|
$this->interactor->noticeThrowable($e, $message); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
public function enableBackgroundJob(): void |
104
|
|
|
{ |
105
|
|
|
$this->logger->debug('Enabling New Relic background job'); |
106
|
|
|
$this->interactor->enableBackgroundJob(); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
public function disableBackgroundJob(): void |
110
|
|
|
{ |
111
|
|
|
$this->logger->debug('Disabling New Relic background job'); |
112
|
|
|
$this->interactor->disableBackgroundJob(); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
public function endTransaction(bool $ignore = false): bool |
116
|
|
|
{ |
117
|
|
|
$this->logger->debug('Ending a New Relic transaction'); |
118
|
|
|
|
119
|
|
|
return $this->interactor->endTransaction($ignore); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
public function startTransaction(string $name = null, string $license = null): bool |
123
|
|
|
{ |
124
|
|
|
$this->logger->debug('Starting a new New Relic transaction for app {name}', ['name' => $name]); |
125
|
|
|
|
126
|
|
|
return $this->interactor->startTransaction($name, $license); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
public function excludeFromApdex(): void |
130
|
|
|
{ |
131
|
|
|
$this->logger->debug('Excluding current transaction from New Relic Apdex score'); |
132
|
|
|
$this->interactor->excludeFromApdex(); |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
public function addCustomTracer(string $name): bool |
136
|
|
|
{ |
137
|
|
|
$this->logger->debug('Adding custom New Relic tracer'); |
138
|
|
|
|
139
|
|
|
return $this->interactor->addCustomTracer($name); |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
public function setCaptureParams(bool $enabled): void |
143
|
|
|
{ |
144
|
|
|
$this->logger->debug('Toggle New Relic capture params to {enabled}', ['enabled' => $enabled]); |
145
|
|
|
$this->interactor->setCaptureParams($enabled); |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
public function stopTransactionTiming(): void |
149
|
|
|
{ |
150
|
|
|
$this->logger->debug('Stopping New Relic timing'); |
151
|
|
|
$this->interactor->stopTransactionTiming(); |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
public function recordDatastoreSegment(callable $func, array $parameters) |
155
|
|
|
{ |
156
|
|
|
$this->logger->debug('Adding custom New Relic datastore segment'); |
157
|
|
|
|
158
|
|
|
return $this->interactor->recordDatastoreSegment($func, $parameters); |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
public function setUserAttributes(string $userValue, string $accountValue, string $productValue): bool |
162
|
|
|
{ |
163
|
|
|
$this->logger->debug('Setting New Relic user attributes', [ |
164
|
|
|
'user_value' => $userValue, |
165
|
|
|
'account_value' => $accountValue, |
166
|
|
|
'product_value' => $productValue, |
167
|
|
|
]); |
168
|
|
|
|
169
|
|
|
return $this->interactor->setUserAttributes($userValue, $accountValue, $productValue); |
170
|
|
|
} |
171
|
|
|
} |
172
|
|
|
|