Home
About
Blog
Products
Forum
Support
Contact
Sunbelt Computer Software
PL/B Language Development and Support
Home
About
Blog
Products
Forum
Support
Contact
sentry-python/tests/test_api.py at master · gitcommit90/sentry-python · GitHub
Skip to content
Navigation Menu
Sign in
Appearance settings
Platform
AI CODE CREATION
GitHub Copilot
Write better code with AI
GitHub Copilot app
Direct agents from issue to merge
MCP Registry
Integrate external tools
DEVELOPER WORKFLOWS
Actions
Automate any workflow
Codespaces
Instant dev environments
Issues
Plan and track work
Code Review
Manage code changes
Code Quality
Enforce quality at merge
APPLICATION SECURITY
GitHub Advanced Security
Find and fix vulnerabilities
Code security
Secure your code as you build
Secret protection
Stop leaks before they start
EXPLORE
Why GitHub
Documentation
Blog
Changelog
Marketplace
View all features
Solutions
BY COMPANY SIZE
Enterprises
Small and medium teams
Startups
Nonprofits
BY USE CASE
App Modernization
DevSecOps
DevOps
CI/CD
View all use cases
BY INDUSTRY
Healthcare
Financial services
Manufacturing
Government
View all industries
View all solutions
Resources
EXPLORE BY TOPIC
AI
Software Development
DevOps
Security
View all topics
EXPLORE BY TYPE
Customer stories
Events & webinars
Ebooks & reports
Business insights
GitHub Skills
SUPPORT & SERVICES
Documentation
Customer support
Community forum
Trust center
Partners
View all resources
Open Source
COMMUNITY
GitHub Sponsors
Fund open source developers
PROGRAMS
Security Lab
Maintainer Community
GitHub Stars
Archive Program
REPOSITORIES
Topics
Trending
Collections
Enterprise
ENTERPRISE SOLUTIONS
Enterprise platform
AI-powered developer platform
AVAILABLE ADD-ONS
GitHub Advanced Security
Enterprise-grade security features
Copilot for Business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
gitcommit90
/
sentry-python
Public
forked from
getsentry/sentry-python
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Files
Expand file tree
master
Breadcrumbs
sentry-python
/
tests
/
test_api.py
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
223 lines (167 loc) · 6.24 KB
master
Breadcrumbs
sentry-python
/
tests
/
test_api.py
Copy path
Top
File metadata and controls
Code
Blame
223 lines (167 loc) · 6.24 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
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
222
223
import
re
from
unittest
import
mock
import
pytest
import
sentry_sdk
from
sentry_sdk
import
(
capture_exception
,
configure_scope
,
continue_trace
,
get_baggage
,
get_client
,
get_current_scope
,
get_current_span
,
get_global_scope
,
get_isolation_scope
,
get_traceparent
,
is_initialized
,
push_scope
,
set_tags
,
start_transaction
,
)
from
sentry_sdk
.
client
import
Client
,
NonRecordingClient
from
sentry_sdk
.
tracing
import
Span
from
tests
.
conftest
import
TestTransportWithOptions
def
test_get_current_span
():
fake_scope
=
mock
.
MagicMock
()
fake_scope
.
span
=
mock
.
MagicMock
()
assert
get_current_span
(
fake_scope
)
==
fake_scope
.
span
fake_scope
.
span
=
None
assert
get_current_span
(
fake_scope
)
is
None
def
test_get_current_span_default_hub
(
sentry_init
):
sentry_init
()
assert
get_current_span
()
is
None
scope
=
get_current_scope
()
fake_span
=
Span
()
scope
.
span
=
fake_span
assert
get_current_span
()
==
fake_span
def
test_get_current_span_default_hub_with_transaction
(
sentry_init
):
sentry_init
()
assert
get_current_span
()
is
None
with
start_transaction
()
as
new_transaction
:
assert
get_current_span
()
==
new_transaction
def
test_traceparent_with_tracing_enabled
(
sentry_init
):
sentry_init
(
traces_sample_rate
=
1.0
)
with
start_transaction
()
as
transaction
:
expected_traceparent
=
"%s-%s-1"
%
(
transaction
.
trace_id
,
transaction
.
span_id
,
)
assert
get_traceparent
()
==
expected_traceparent
def
test_traceparent_with_tracing_disabled
(
sentry_init
):
sentry_init
()
propagation_context
=
get_isolation_scope
().
_propagation_context
expected_traceparent
=
"%s-%s"
%
(
propagation_context
.
trace_id
,
propagation_context
.
span_id
,
)
assert
get_traceparent
()
==
expected_traceparent
def
test_baggage_with_tracing_disabled
(
sentry_init
):
sentry_init
(
release
=
"1.0.0"
,
environment
=
"dev"
)
propagation_context
=
get_isolation_scope
().
_propagation_context
expected_baggage
=
(
"sentry-trace_id={},sentry-environment=dev,sentry-release=1.0.0"
.
format
(
propagation_context
.
trace_id
)
)
assert
get_baggage
()
==
expected_baggage
def
test_baggage_with_tracing_enabled
(
sentry_init
):
sentry_init
(
traces_sample_rate
=
1.0
,
release
=
"1.0.0"
,
environment
=
"dev"
)
with
start_transaction
()
as
transaction
:
expected_baggage_re
=
r"^sentry-trace_id={},sentry-sample_rand=0\.\d{{6}},sentry-environment=dev,sentry-release=1\.0\.0,sentry-sample_rate=1\.0,sentry-sampled={}$"
.
format
(
transaction
.
trace_id
,
"true"
if
transaction
.
sampled
else
"false"
)
assert
re
.
match
(
expected_baggage_re
,
get_baggage
())
def
test_baggage_with_dsn
(
sentry_init
):
sentry_init
(
dsn
=
"http://97333d956c9e40989a0139756c121c34@sentry-x.sentry-y.s.c.local/976543210"
,
traces_sample_rate
=
1.0
,
release
=
"2.0.0"
,
environment
=
"dev"
,
transport
=
TestTransportWithOptions
,
)
with
start_transaction
()
as
transaction
:
expected_baggage_re
=
r"^sentry-trace_id={},sentry-sample_rand=0\.\d{{6}},sentry-environment=dev,sentry-release=2\.0\.0,sentry-public_key=97333d956c9e40989a0139756c121c34,sentry-sample_rate=1\.0,sentry-sampled={}$"
.
format
(
transaction
.
trace_id
,
"true"
if
transaction
.
sampled
else
"false"
)
assert
re
.
match
(
expected_baggage_re
,
get_baggage
())
def
test_continue_trace
(
sentry_init
):
sentry_init
()
trace_id
=
"471a43a4192642f0b136d5159a501701"
parent_span_id
=
"6e8f22c393e68f19"
parent_sampled
=
1
transaction
=
continue_trace
(
{
"sentry-trace"
:
"{}-{}-{}"
.
format
(
trace_id
,
parent_span_id
,
parent_sampled
),
"baggage"
:
"sentry-trace_id=566e3688a61d4bc888951642d6f14a19,sentry-sample_rand=0.123456"
,
},
name
=
"some name"
,
)
with
start_transaction
(
transaction
):
assert
transaction
.
name
==
"some name"
propagation_context
=
get_isolation_scope
().
_propagation_context
assert
propagation_context
.
trace_id
==
transaction
.
trace_id
==
trace_id
assert
propagation_context
.
parent_span_id
==
parent_span_id
assert
propagation_context
.
parent_sampled
==
parent_sampled
assert
propagation_context
.
dynamic_sampling_context
==
{
"trace_id"
:
"566e3688a61d4bc888951642d6f14a19"
,
"sample_rand"
:
"0.123456"
,
}
def
test_is_initialized
():
assert
not
is_initialized
()
scope
=
get_global_scope
()
scope
.
set_client
(
Client
())
assert
is_initialized
()
def
test_get_client
():
client
=
get_client
()
assert
client
is
not
None
assert
client
.
__class__
==
NonRecordingClient
assert
not
client
.
is_active
()
def
raise_and_capture
():
"""Raise an exception and capture it.
This is a utility function for test_set_tags.
"""
try
:
1
/
0
except
ZeroDivisionError
:
capture_exception
()
def
test_set_tags
(
sentry_init
,
capture_events
):
sentry_init
()
events
=
capture_events
()
set_tags
({
"tag1"
:
"value1"
,
"tag2"
:
"value2"
})
raise_and_capture
()
(
*
_
,
event
)
=
events
assert
event
[
"tags"
]
==
{
"tag1"
:
"value1"
,
"tag2"
:
"value2"
},
"Setting tags failed"
set_tags
({
"tag2"
:
"updated"
,
"tag3"
:
"new"
})
raise_and_capture
()
(
*
_
,
event
)
=
events
assert
event
[
"tags"
]
==
{
"tag1"
:
"value1"
,
"tag2"
:
"updated"
,
"tag3"
:
"new"
,
},
"Updating tags failed"
set_tags
({})
raise_and_capture
()
(
*
_
,
event
)
=
events
assert
event
[
"tags"
]
==
{
"tag1"
:
"value1"
,
"tag2"
:
"updated"
,
"tag3"
:
"new"
,
},
"Updating tags with empty dict changed tags"
def
test_configure_scope_deprecation
():
with
pytest
.
warns
(
DeprecationWarning
):
with
configure_scope
():
...
def
test_push_scope_deprecation
():
with
pytest
.
warns
(
DeprecationWarning
):
with
push_scope
():
...
def
test_init_context_manager_deprecation
():
with
pytest
.
warns
(
DeprecationWarning
):
with
sentry_sdk
.
init
():
...
def
test_init_enter_deprecation
():
with
pytest
.
warns
(
DeprecationWarning
):
sentry_sdk
.
init
().
__enter__
()
def
test_init_exit_deprecation
():
with
pytest
.
warns
(
DeprecationWarning
):
sentry_sdk
.
init
().
__exit__
(
None
,
None
,
None
)
You can’t perform that action at this time.