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 $license = 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, $license, $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( |
92
|
|
|
int $errno, |
93
|
|
|
string $errstr, |
94
|
|
|
string $errfile = null, |
95
|
|
|
int $errline = null, |
96
|
|
|
string $errcontext = null |
97
|
|
|
): void { |
98
|
|
|
$this->logger->debug('Sending notice error to New Relic', [ |
99
|
|
|
'error_code' => $errno, |
100
|
|
|
'message' => $errstr, |
101
|
|
|
'file' => $errfile, |
102
|
|
|
'line' => $errline, |
103
|
|
|
'context_error' => $errcontext, |
104
|
|
|
]); |
105
|
|
|
$this->interactor->noticeError($errno, $errstr, $errfile, $errline, $errcontext); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
public function noticeThrowable(\Throwable $e, string $message = null): void |
109
|
|
|
{ |
110
|
|
|
$this->logger->debug('Sending exception to New Relic', [ |
111
|
|
|
'message' => $message, |
112
|
|
|
'exception' => $e, |
113
|
|
|
]); |
114
|
|
|
$this->interactor->noticeThrowable($e, $message); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
public function enableBackgroundJob(): void |
118
|
|
|
{ |
119
|
|
|
$this->logger->debug('Enabling New Relic background job'); |
120
|
|
|
$this->interactor->enableBackgroundJob(); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
public function disableBackgroundJob(): void |
124
|
|
|
{ |
125
|
|
|
$this->logger->debug('Disabling New Relic background job'); |
126
|
|
|
$this->interactor->disableBackgroundJob(); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
public function endTransaction(bool $ignore = false): bool |
130
|
|
|
{ |
131
|
|
|
$this->logger->debug('Ending a New Relic transaction'); |
132
|
|
|
|
133
|
|
|
return $this->interactor->endTransaction($ignore); |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
public function startTransaction(string $name = null, string $license = null): bool |
137
|
|
|
{ |
138
|
|
|
$this->logger->debug('Starting a new New Relic transaction for app {name}', ['name' => $name]); |
139
|
|
|
|
140
|
|
|
return $this->interactor->startTransaction($name, $license); |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
public function excludeFromApdex(): void |
144
|
|
|
{ |
145
|
|
|
$this->logger->debug('Excluding current transaction from New Relic Apdex score'); |
146
|
|
|
$this->interactor->excludeFromApdex(); |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
public function addCustomTracer(string $name): bool |
150
|
|
|
{ |
151
|
|
|
$this->logger->debug('Adding custom New Relic tracer', ['name' => $name]); |
152
|
|
|
|
153
|
|
|
return $this->interactor->addCustomTracer($name); |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
public function setCaptureParams(bool $enabled): void |
157
|
|
|
{ |
158
|
|
|
$this->logger->debug('Toggle New Relic capture params to {enabled}', ['enabled' => $enabled]); |
159
|
|
|
$this->interactor->setCaptureParams($enabled); |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
public function stopTransactionTiming(): void |
163
|
|
|
{ |
164
|
|
|
$this->logger->debug('Stopping New Relic timing'); |
165
|
|
|
$this->interactor->stopTransactionTiming(); |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
public function recordDatastoreSegment(callable $func, array $parameters) |
169
|
|
|
{ |
170
|
|
|
$this->logger->debug('Adding custom New Relic datastore segment', [ |
171
|
|
|
'parameters' => $parameters, |
172
|
|
|
]); |
173
|
|
|
|
174
|
|
|
return $this->interactor->recordDatastoreSegment($func, $parameters); |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
public function setUserAttributes(string $userValue, string $accountValue, string $productValue): bool |
178
|
|
|
{ |
179
|
|
|
$this->logger->debug('Setting New Relic user attributes', [ |
180
|
|
|
'user_value' => $userValue, |
181
|
|
|
'account_value' => $accountValue, |
182
|
|
|
'product_value' => $productValue, |
183
|
|
|
]); |
184
|
|
|
|
185
|
|
|
return $this->interactor->setUserAttributes($userValue, $accountValue, $productValue); |
186
|
|
|
} |
187
|
|
|
} |
188
|
|
|
|