1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Apache OSL-2 |
5
|
|
|
* For full license information, please view the LICENSE file that was distributed with this source code. |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace SprykerEco\Service\Tideways\Plugin; |
9
|
|
|
|
10
|
|
|
use Spryker\Service\MonitoringExtension\Dependency\Plugin\MonitoringExtensionPluginInterface; |
11
|
|
|
use Tideways\Profiler; |
|
|
|
|
12
|
|
|
|
13
|
|
|
class TidewaysMonitoringExtensionPlugin implements MonitoringExtensionPluginInterface |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* @var string |
17
|
|
|
*/ |
18
|
|
|
protected $applicationName; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @var bool |
22
|
|
|
*/ |
23
|
|
|
protected $isActive; |
24
|
|
|
|
25
|
|
|
public function __construct() |
26
|
|
|
{ |
27
|
|
|
$this->isActive = class_exists('Tideways\Profiler'); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Report an error at this line of code, with a complete stack trace. |
32
|
|
|
* |
33
|
|
|
* @param string $message |
34
|
|
|
* @param \Exception|\Throwable $exception |
35
|
|
|
* |
36
|
|
|
* @return void |
37
|
|
|
*/ |
38
|
|
|
public function setError(string $message, $exception): void |
39
|
|
|
{ |
40
|
|
|
if (!$this->isActive) { |
41
|
|
|
return; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
if ($exception) { |
45
|
|
|
Profiler::logException($exception); |
46
|
|
|
} |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @param null|string $application |
51
|
|
|
* @param null|string $store |
52
|
|
|
* @param null|string $environment |
53
|
|
|
* |
54
|
|
|
* @return void |
55
|
|
|
*/ |
56
|
|
|
public function setApplicationName(?string $application = null, ?string $store = null, ?string $environment = null): void |
57
|
|
|
{ |
58
|
|
|
if (!$this->isActive) { |
59
|
|
|
return; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
$name = $application . '-' . $store; |
63
|
|
|
|
64
|
|
|
Profiler::setServiceName($name); |
65
|
|
|
$this->addCustomParameter('env', $environment); |
66
|
|
|
$this->applicationName = $name; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @param string $name |
71
|
|
|
* |
72
|
|
|
* @return void |
73
|
|
|
*/ |
74
|
|
|
public function setTransactionName(string $name): void |
75
|
|
|
{ |
76
|
|
|
if (!$this->isActive) { |
77
|
|
|
return; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
Profiler::setTransactionName($name); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @return void |
85
|
|
|
*/ |
86
|
|
|
public function markStartTransaction(): void |
87
|
|
|
{ |
88
|
|
|
if (!$this->isActive) { |
89
|
|
|
return; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
Profiler::start(); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @return void |
97
|
|
|
*/ |
98
|
|
|
public function markEndOfTransaction(): void |
99
|
|
|
{ |
100
|
|
|
if (!$this->isActive) { |
101
|
|
|
return; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
Profiler::stop(); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* @return void |
109
|
|
|
*/ |
110
|
|
|
public function markIgnoreTransaction(): void |
111
|
|
|
{ |
112
|
|
|
if (!$this->isActive) { |
113
|
|
|
return; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
Profiler::ignoreTransaction(); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* @return void |
121
|
|
|
*/ |
122
|
|
|
public function markAsConsoleCommand(): void |
123
|
|
|
{ |
124
|
|
|
if (!$this->isActive) { |
125
|
|
|
return; |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
$name = isset($this->applicationName) ? $this->applicationName . '-CLI' : 'CLI'; |
129
|
|
|
Profiler::setServiceName($name); |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* @param string $key |
134
|
|
|
* @param mixed $value |
135
|
|
|
* |
136
|
|
|
* @return void |
137
|
|
|
*/ |
138
|
|
|
public function addCustomParameter(string $key, $value): void |
139
|
|
|
{ |
140
|
|
|
if (!$this->isActive) { |
141
|
|
|
return; |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
Profiler::setCustomVariable($key, (string)$value); |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* @param string $tracer |
149
|
|
|
* |
150
|
|
|
* @return void |
151
|
|
|
*/ |
152
|
|
|
public function addCustomTracer(string $tracer = 'classname::function_name'): void |
153
|
|
|
{ |
154
|
|
|
if (!$this->isActive) { |
155
|
|
|
return; |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
Profiler::watch($tracer); |
159
|
|
|
} |
160
|
|
|
} |
161
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths