1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* MIT License |
5
|
|
|
* For full license information, please view the LICENSE file that was distributed with this source code. |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace SprykerEco\Service\NewRelic\Plugin; |
9
|
|
|
|
10
|
|
|
use Spryker\Service\MonitoringExtension\Dependency\Plugin\MonitoringExtensionPluginInterface; |
11
|
|
|
|
12
|
|
|
class NewRelicMonitoringExtensionPlugin implements MonitoringExtensionPluginInterface |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @var string |
16
|
|
|
*/ |
17
|
|
|
protected $application; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @var bool |
21
|
|
|
*/ |
22
|
|
|
protected $isActive; |
23
|
|
|
|
24
|
|
|
public function __construct() |
25
|
|
|
{ |
26
|
|
|
$this->isActive = extension_loaded('newrelic'); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @param string $message |
31
|
|
|
* @param \Exception|\Throwable $exception |
32
|
|
|
* |
33
|
|
|
* @return void |
34
|
|
|
*/ |
35
|
|
|
public function setError(string $message, $exception): void |
36
|
|
|
{ |
37
|
|
|
if (!$this->isActive) { |
38
|
|
|
return; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
\newrelic_notice_error($message, $exception); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @param null|string $application |
46
|
|
|
* @param null|string $store |
47
|
|
|
* @param null|string $environment |
48
|
|
|
* |
49
|
|
|
* @return void |
50
|
|
|
*/ |
51
|
|
|
public function setApplicationName(?string $application = null, ?string $store = null, ?string $environment = null): void |
52
|
|
|
{ |
53
|
|
|
if (!$this->isActive) { |
54
|
|
|
return; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
$this->application = $application . '-' . $store . ' (' . $environment . ')'; |
58
|
|
|
|
59
|
|
|
\newrelic_set_appname($this->application); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @param string $name |
64
|
|
|
* |
65
|
|
|
* @return void |
66
|
|
|
*/ |
67
|
|
|
public function setTransactionName(string $name): void |
68
|
|
|
{ |
69
|
|
|
if (!$this->isActive) { |
70
|
|
|
return; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
\newrelic_name_transaction($name); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @return void |
78
|
|
|
*/ |
79
|
|
|
public function markStartTransaction(): void |
80
|
|
|
{ |
81
|
|
|
if (!$this->isActive) { |
82
|
|
|
return; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
\newrelic_start_transaction($this->application); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @return void |
90
|
|
|
*/ |
91
|
|
|
public function markEndOfTransaction(): void |
92
|
|
|
{ |
93
|
|
|
if (!$this->isActive) { |
94
|
|
|
return; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
\newrelic_end_transaction(); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @return void |
102
|
|
|
*/ |
103
|
|
|
public function markIgnoreTransaction(): void |
104
|
|
|
{ |
105
|
|
|
if (!$this->isActive) { |
106
|
|
|
return; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
\newrelic_ignore_transaction(); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* @return void |
114
|
|
|
*/ |
115
|
|
|
public function markAsConsoleCommand(): void |
116
|
|
|
{ |
117
|
|
|
if (!$this->isActive) { |
118
|
|
|
return; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
\newrelic_background_job(true); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* @param string $key |
126
|
|
|
* @param mixed $value |
127
|
|
|
* |
128
|
|
|
* @return void |
129
|
|
|
*/ |
130
|
|
|
public function addCustomParameter(string $key, $value): void |
131
|
|
|
{ |
132
|
|
|
if (!$this->isActive) { |
133
|
|
|
return; |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
\newrelic_add_custom_parameter($key, $value); |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* @param string $tracer |
141
|
|
|
* |
142
|
|
|
* @return void |
143
|
|
|
*/ |
144
|
|
|
public function addCustomTracer(string $tracer): void |
145
|
|
|
{ |
146
|
|
|
if (!$this->isActive) { |
147
|
|
|
return; |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
\newrelic_add_custom_tracer($tracer); |
151
|
|
|
} |
152
|
|
|
} |
153
|
|
|
|