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