FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
sentry-php/src/SentrySdk.php at source-frame-cache · getsentry/sentry-php · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
getsentry
/
sentry-php
Public
Uh oh!
There was an error while loading.
Please reload this page
.
Notifications
You must be signed in to change notification settings
Fork
475
Star
1.9k
Code
Issues
20
Pull requests
11
Discussions
Actions
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Discussions
Actions
Security and quality
Insights
Expand file tree
Breadcrumbs
sentry-php
/
src
/
SentrySdk.php
Copy path
More file actions
More file actions
Latest commit
History
History
History
167 lines (143 loc) · 4.31 KB
Breadcrumbs
sentry-php
/
src
/
SentrySdk.php
Copy path
File metadata and controls
167 lines (143 loc) · 4.31 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
<?php
declare
(strict_types=
1
);
namespace
Sentry
;
use
Sentry
\
Logs
\
Logs
;
use
Sentry
\
Metrics
\
TraceMetrics
;
use
Sentry
\
State
\
Hub
;
use
Sentry
\
State
\
HubInterface
;
use
Sentry
\
State
\
RuntimeContext
;
use
Sentry
\
State
\
RuntimeContextManager
;
/**
* This class is the main entry point for all the most common SDK features.
*
* @author Stefano Arlandini <sarlandini@alice.it>
*/
final
class
SentrySdk
{
/**
* @var HubInterface|null The baseline hub
*/
private
static
$
currentHub
;
/**
* @var RuntimeContextManager|null
*/
private
static
$
runtimeContextManager
;
/**
* Constructor.
*/
private
function
__construct
()
{
}
/**
* Initializes the SDK by creating a new hub instance each time this method
* gets called.
*/
public
static
function
init
():
HubInterface
{
self
::
$
currentHub
=
new
Hub
();
self
::
$
runtimeContextManager
=
new
RuntimeContextManager
(
self
::
$
currentHub
);
return
self
::
getCurrentHub
();
}
/**
* Gets the current hub. If it's not initialized then creates a new instance
* and sets it as current hub.
*/
public
static
function
getCurrentHub
():
HubInterface
{
return
self
::
getRuntimeContextManager
()->
getCurrentHub
();
}
/**
* Sets the current hub.
*
* If called while an explicit runtime context is active, the hub update is
* scoped to that active context only. Otherwise, it updates the baseline
* hub used by the global fallback context and future contexts.
*
* @param HubInterface $hub The hub to set
*/
public
static
function
setCurrentHub
(
HubInterface
$
hub
):
HubInterface
{
$
wasSetOnActiveRuntimeContext
=
self
::
getRuntimeContextManager
()->
setCurrentHub
(
$
hub
);
if
(!
$
wasSetOnActiveRuntimeContext
) {
self
::
$
currentHub
=
$
hub
;
}
return
$
hub
;
}
public
static
function
startContext
():
void
{
self
::
getRuntimeContextManager
()->
startContext
();
}
public
static
function
endContext
(?
int
$
timeout
=
null
):
void
{
self
::
getRuntimeContextManager
()->
endContext
(
$
timeout
);
}
/**
* Executes the given callback within an isolated context.
*
* If a context is already active for the current execution key, this method
* reuses it and only executes the callback.
*
* @param callable $callback The callback to execute
*
* @phpstan-template T
*
* @phpstan-param callable(): T $callback
*
* @return mixed
*
* @phpstan-return T
*/
public
static
function
withContext
(
callable
$
callback
, ?
int
$
timeout
=
null
)
{
$
runtimeContextManager
=
self
::
getRuntimeContextManager
();
$
startedNewContext
= !
$
runtimeContextManager
->
hasActiveContext
();
if
(
$
startedNewContext
) {
$
runtimeContextManager
->
startContext
();
}
try
{
return
$
callback
();
}
finally
{
if
(
$
startedNewContext
) {
$
runtimeContextManager
->
endContext
(
$
timeout
);
}
}
}
/**
* Gets the current runtime-local context.
*
* @internal
*/
public
static
function
getCurrentRuntimeContext
():
RuntimeContext
{
return
self
::
getRuntimeContextManager
()->
getCurrentContext
();
}
/**
* Flushes all buffered telemetry data.
*
* This is a convenience facade that forwards the flush operation to all
* internally managed components.
*
* Calling this method is equivalent to invoking `flush()` on each component
* individually. It does not change flushing behavior, improve performance,
* or reduce the number of network requests.
*/
public
static
function
flush
():
void
{
Logs::
getInstance
()->
flush
();
TraceMetrics::
getInstance
()->
flush
();
$
client
=
self
::
getCurrentHub
()->
getClient
();
if
(
$
client
!==
null
) {
$
client
->
flush
();
}
}
private
static
function
getRuntimeContextManager
():
RuntimeContextManager
{
if
(
self
::
$
currentHub
===
null
) {
self
::
$
currentHub
=
new
Hub
();
}
if
(
self
::
$
runtimeContextManager
===
null
) {
self
::
$
runtimeContextManager
=
new
RuntimeContextManager
(
self
::
$
currentHub
);
}
return
self
::
$
runtimeContextManager
;
}
}
Back
|
FazBrowse Home
|
New Git URL