-
-
Notifications
You must be signed in to change notification settings - Fork 466
Expand file tree
/
Copy pathHubAdapter.php
More file actions
221 lines (193 loc) · 5.14 KB
/
HubAdapter.php
File metadata and controls
221 lines (193 loc) · 5.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
<?php
declare(strict_types=1);
namespace Sentry\State;
use Sentry\Breadcrumb;
use Sentry\CheckInStatus;
use Sentry\ClientInterface;
use Sentry\Event;
use Sentry\EventHint;
use Sentry\EventId;
use Sentry\Integration\IntegrationInterface;
use Sentry\MonitorConfig;
use Sentry\SentrySdk;
use Sentry\Severity;
use Sentry\Tracing\Span;
use Sentry\Tracing\Transaction;
use Sentry\Tracing\TransactionContext;
/**
* An implementation of {@see HubInterface} that uses {@see SentrySdk} internally
* to manage the current hub.
*/
final class HubAdapter implements HubInterface
{
/**
* @var self|null The single instance which forwards all calls to {@see SentrySdk}
*/
private static $instance;
/**
* Constructor.
*/
private function __construct()
{
}
/**
* Gets the instance of this class. This is a singleton, so once initialized
* you will always get the same instance.
*/
public static function getInstance(): self
{
if (self::$instance === null) {
self::$instance = new self();
}
return self::$instance;
}
/**
* {@inheritdoc}
*/
public function getClient(): ?ClientInterface
{
return SentrySdk::getCurrentHub()->getClient();
}
/**
* {@inheritdoc}
*/
public function getLastEventId(): ?EventId
{
return SentrySdk::getCurrentHub()->getLastEventId();
}
/**
* {@inheritdoc}
*/
public function pushScope(): Scope
{
return SentrySdk::getCurrentHub()->pushScope();
}
/**
* {@inheritdoc}
*/
public function popScope(): bool
{
return SentrySdk::getCurrentHub()->popScope();
}
/**
* {@inheritdoc}
*/
public function withScope(callable $callback)
{
return SentrySdk::getCurrentHub()->withScope($callback);
}
/**
* {@inheritdoc}
*/
public function configureScope(callable $callback): void
{
SentrySdk::getCurrentHub()->configureScope($callback);
}
/**
* {@inheritdoc}
*/
public function bindClient(ClientInterface $client): void
{
SentrySdk::getCurrentHub()->bindClient($client);
}
/**
* {@inheritdoc}
*/
public function captureMessage(string $message, ?Severity $level = null, ?EventHint $hint = null): ?EventId
{
return SentrySdk::getCurrentHub()->captureMessage($message, $level, $hint);
}
/**
* {@inheritdoc}
*/
public function captureException(\Throwable $exception, ?EventHint $hint = null): ?EventId
{
return SentrySdk::getCurrentHub()->captureException($exception, $hint);
}
/**
* {@inheritdoc}
*/
public function captureEvent(Event $event, ?EventHint $hint = null): ?EventId
{
return SentrySdk::getCurrentHub()->captureEvent($event, $hint);
}
/**
* {@inheritdoc}
*/
public function captureLastError(?EventHint $hint = null): ?EventId
{
return SentrySdk::getCurrentHub()->captureLastError($hint);
}
/**
* {@inheritdoc}
*
* @param int|float|null $duration
*/
public function captureCheckIn(string $slug, CheckInStatus $status, $duration = null, ?MonitorConfig $monitorConfig = null, ?string $checkInId = null): ?string
{
return SentrySdk::getCurrentHub()->captureCheckIn($slug, $status, $duration, $monitorConfig, $checkInId);
}
/**
* {@inheritdoc}
*/
public function addBreadcrumb(Breadcrumb $breadcrumb): bool
{
return SentrySdk::getCurrentHub()->addBreadcrumb($breadcrumb);
}
/**
* {@inheritdoc}
*/
public function getIntegration(string $className): ?IntegrationInterface
{
return SentrySdk::getCurrentHub()->getIntegration($className);
}
/**
* {@inheritdoc}
*/
public function startTransaction(TransactionContext $context, array $customSamplingContext = []): Transaction
{
return SentrySdk::getCurrentHub()->startTransaction($context, $customSamplingContext);
}
/**
* {@inheritdoc}
*/
public function getTransaction(): ?Transaction
{
return SentrySdk::getCurrentHub()->getTransaction();
}
/**
* {@inheritdoc}
*/
public function getSpan(): ?Span
{
return SentrySdk::getCurrentHub()->getSpan();
}
/**
* {@inheritdoc}
*/
public function setSpan(?Span $span): HubInterface
{
return SentrySdk::getCurrentHub()->setSpan($span);
}
/**
* @see https://www.php.net/manual/en/language.oop5.cloning.php#object.clone
*/
public function __clone()
{
throw new \BadMethodCallException('Cloning is forbidden.');
}
/**
* @see https://www.php.net/manual/en/language.oop5.magic.php#object.wakeup
*/
public function __wakeup(): void
{
throw new \BadMethodCallException('Unserializing instances of this class is forbidden.');
}
/**
* @see https://www.php.net/manual/en/language.oop5.magic.php#object.sleep
*/
public function __sleep()
{
throw new \BadMethodCallException('Serializing instances of this class is forbidden.');
}
}