@@ -4,114 +4,114 @@ description: "While we don't expect most users of our SDK to run into these issu
44sidebar_order : 9000
55---
66
7- We expect most users of the Python SDK not to run into any of the problems
8- documented here.
7+ ## General
98
109Use the information in this page to help answer these questions:
1110
1211- "What do I do if scope data is leaking between requests?"
1312- "What do I do if my transaction has nested spans when they should be parallel?"
1413- "What do I do if the SDK has trouble sending events to Sentry?"
1514
16- ## Addressing Concurrency Issues
15+ <Expandable title = " Addressing Concurrency Issues" >
16+ The short answer to the first two questions: make sure your ` contextvars ` work and
17+ that your isolation scope was cloned for each concurrency unit.
1718
18- The short answer to the first two questions: make sure your ` contextvars ` work and
19- that your isolation scope was cloned for each concurrency unit .
19+ Python supports several distinct solutions to concurrency, including threads and
20+ coroutines .
2021
21- Python supports several distinct solutions to concurrency, including threads and
22- coroutines.
22+ The Python SDK does its best to figure out how contextual data such as tags set
23+ with ` sentry_sdk.set_tags ` is supposed to flow along your control flow. In most
24+ cases it works perfectly, but in a few situations some special care must be
25+ taken. This is specially true when working with a code base doing concurrency
26+ outside of the provided framework integrations.
2327
24- The Python SDK does its best to figure out how contextual data such as tags set
25- with ` sentry_sdk.set_tags ` is supposed to flow along your control flow. In most
26- cases it works perfectly, but in a few situations some special care must be
27- taken. This is specially true when working with a code base doing concurrency
28- outside of the provided framework integrations.
28+ The general recommendation is to have one isolation scope per "concurrency unit"
29+ (thread/coroutine/etc). The SDK ensures every thread has an independent scope via the ` ThreadingIntegration ` .
30+ If you do concurrency with ` asyncio ` coroutines, make sure to use the ` AsyncioIntegration `
31+ which will clone the correct scope in your ` Task ` s.
2932
30- The general recommendation is to have one isolation scope per "concurrency unit"
31- (thread/coroutine/etc). The SDK ensures every thread has an independent scope via the ` ThreadingIntegration ` .
32- If you do concurrency with ` asyncio ` coroutines, make sure to use the ` AsyncioIntegration `
33- which will clone the correct scope in your ` Task ` s.
33+ The general pattern of usage for creating a new isolation scope is:
3434
35- The general pattern of usage for creating a new isolation scope is:
35+ ``` python
36+ with sentry_sdk.isolation_scope() as scope:
37+ # In this block scope refers to a new fork of the original isolation scope,
38+ # with the same client and the same initial scope data.
39+ ```
3640
37- ``` python
38- with sentry_sdk.isolation_scope() as scope:
39- # In this block scope refers to a new fork of the original isolation scope,
40- # with the same client and the same initial scope data.
41- ```
42-
43- See the <PlatformLink to = " /integrations/default-integrations/#threading" >Threading</PlatformLink > section
44- for a more complete example that involves forking the isolation scope.
41+ See the <PlatformLink to = " /integrations/default-integrations/#threading" >Threading</PlatformLink > section
42+ for a more complete example that involves forking the isolation scope.
43+ </Expandable >
4544
46- ## Context Variables vs Thread Locals
45+ < Expandable title = " Context Variables vs Thread Locals" >
4746
48- The Python SDK uses [ thread
49- locals] ( https://docs.python.org/3/library/threading.html#thread-local-data ) to
50- keep contextual data where it belongs. There are a few situations where this
51- approach fails.
47+ The Python SDK uses [ thread locals] ( https://docs.python.org/3/library/threading.html#thread-local-data ) to
48+ keep contextual data where it belongs. There are a few situations where this
49+ approach fails.
5250
53- Read along if you cannot figure out why contextual data is leaking across HTTP
54- requests, or data is missing or popping up at the wrong place and time.
51+ Read along if you cannot figure out why contextual data is leaking across HTTP
52+ requests, or data is missing or popping up at the wrong place and time.
5553
56- ### Python 2: Thread Locals and gevent
54+ #### Python 2: Thread Locals and gevent
5755
58- If the SDK is installed on Python 2, there is not much else to use than the
59- aforementioned thread locals, so the SDK will use just that.
56+ If the SDK is installed on Python 2, there is not much else to use than the
57+ aforementioned thread locals, so the SDK will use just that.
6058
61- Code that uses async libraries such as ** ` twisted ` is not supported** in the
62- sense that you will experience context data leaking across tasks/any logical
63- boundaries, at least out of the box.
59+ Code that uses async libraries such as ** ` twisted ` is not supported** in the
60+ sense that you will experience context data leaking across tasks/any logical
61+ boundaries, at least out of the box.
6462
65- Code that uses more "magical" async libraries such as ** ` gevent ` or ` eventlet `
66- will work just fine** provided those libraries are configured to monkeypatch
67- the stdlib. If you are only using those libraries in the context of running
68- ` gunicorn ` that is the case, for example.
63+ Code that uses more "magical" async libraries such as ** ` gevent ` or ` eventlet `
64+ will work just fine** provided those libraries are configured to monkeypatch
65+ the stdlib. If you are only using those libraries in the context of running
66+ ` gunicorn ` that is the case, for example.
6967
70- ### Python 3: Context Variables or Thread Locals
68+ #### Python 3: Context Variables or Thread Locals
7169
72- Python 3 introduced ` asyncio ` , which, just like Twisted, had the problem of not
73- having any concept of attaching contextual data to your control flow. That
74- means in Python 3.6 and lower, the SDK is not able to prevent leaks of
75- contextual data.
70+ Python 3 introduced ` asyncio ` , which, just like Twisted, had the problem of not
71+ having any concept of attaching contextual data to your control flow. That
72+ means in Python 3.6 and lower, the SDK is not able to prevent leaks of
73+ contextual data.
7674
77- Python 3.7 rectified this problem with the ` contextvars ` stdlib module which is
78- basically thread locals that also work in asyncio-based code. The SDK will
79- attempt to use that module instead of thread locals if available.
75+ Python 3.7 rectified this problem with the ` contextvars ` stdlib module which is
76+ basically thread locals that also work in asyncio-based code. The SDK will
77+ attempt to use that module instead of thread locals if available.
8078
81- ** For Python 3.6 and older, install ` aiocontextvars ` from PyPI** which is a
82- fully-functional backport of ` contextvars ` . The SDK will check for this package
83- and use it instead of thread locals.
79+ ** For Python 3.6 and older, install ` aiocontextvars ` from PyPI** which is a
80+ fully-functional backport of ` contextvars ` . The SDK will check for this package
81+ and use it instead of thread locals.
8482
85- ## Context Variables vs gevent/eventlet
83+ </ Expandable >
8684
87- If you are using ` gevent ` (older than 20.5) or ` eventlet ` in your application and
88- have configured it to monkeypatch the stdlib, the SDK will abstain from using
89- ` contextvars ` even if it is available.
85+ <Expandable title = " Context Variables vs gevent/eventlet" >
86+ If you are using ` gevent ` (older than 20.5) or ` eventlet ` in your application and
87+ have configured it to monkeypatch the stdlib, the SDK will abstain from using
88+ ` contextvars ` even if it is available.
9089
91- The reason for that is that both of those libraries will monkeypatch the
92- ` threading ` module only, and not the ` contextvars ` module.
90+ The reason for that is that both of those libraries will monkeypatch the
91+ ` threading ` module only, and not the ` contextvars ` module.
9392
94- The real-world usecase where this actually comes up is if you're using Django
95- 3.0 within a ` gunicorn+gevent ` worker on Python 3.7. In such a scenario the
96- monkeypatched ` threading ` module will honor the control flow of a gunicorn
97- worker while the unpatched ` contextvars ` will not.
93+ The real-world usecase where this actually comes up is if you're using Django
94+ 3.0 within a ` gunicorn+gevent ` worker on Python 3.7. In such a scenario the
95+ monkeypatched ` threading ` module will honor the control flow of a gunicorn
96+ worker while the unpatched ` contextvars ` will not.
9897
99- It gets more complicated if you're using Django Channels in the same app, but a
100- separate server process, as this is a legitimate usage of ` asyncio ` for which
101- ` contextvars ` behaves more correctly. Make sure that your channels websocket
102- server does not import or use gevent at all (and much less call
103- ` gevent.monkey.patch_all ` ), and you should be good.
98+ It gets more complicated if you're using Django Channels in the same app, but a
99+ separate server process, as this is a legitimate usage of ` asyncio ` for which
100+ ` contextvars ` behaves more correctly. Make sure that your channels websocket
101+ server does not import or use gevent at all (and much less call
102+ ` gevent.monkey.patch_all ` ), and you should be good.
104103
105- Even then there are still edge cases where this behavior is flat-out broken,
106- such as mixing asyncio code with gevent/eventlet-based code. In that case there
107- is no right, _ static_ answer as to which context library to use. Even then
108- gevent's aggressive monkeypatching is likely to interfere in a way that cannot
109- be fixed from within the SDK.
104+ Even then there are still edge cases where this behavior is flat-out broken,
105+ such as mixing asyncio code with gevent/eventlet-based code. In that case there
106+ is no right, _ static_ answer as to which context library to use. Even then
107+ gevent's aggressive monkeypatching is likely to interfere in a way that cannot
108+ be fixed from within the SDK.
110109
111- This [ issue has been fixed with gevent 20.5] ( https://github.com/gevent/gevent/issues/1407 ) but continues to be one for
112- eventlet.
110+ This [ issue has been fixed with gevent 20.5] ( https://github.com/gevent/gevent/issues/1407 ) but continues to be one for
111+ eventlet.
112+ </Expandable >
113113
114- ## Network Issues
114+ < Expandable title = " Network Issues" >
115115
116116Your SDK might have issues sending events to Sentry. You might see
117117` "Remote end closed connection without response" ` , ` "Connection aborted" ` ,
@@ -136,8 +136,9 @@ sentry_sdk.init(
136136
137137If you need more fine-grained control over the behavior of the socket, check out
138138<PlatformLink to = " /configuration/options/#socket-options" >socket-options</PlatformLink >.
139+ </Expandable >
139140
140- ## Multiprocessing deprecation after Python 3.12
141+ < Expandable title = " Multiprocessing deprecation after Python 3.12" >
141142
142143If you're on Python version 3.12 or greater, you might see the following deprecation warning on Linux environments since the SDK spawns several threads.
143144
@@ -160,3 +161,88 @@ if __name__ == "__main__":
160161 pool = concurrent.futures.ProcessPoolExecutor()
161162 pool.submit(sentry_sdk.capture_message, " world" )
162163```
164+ </Expandable >
165+
166+ <Expandable title = " Why was my tag value truncated?" >
167+
168+ Currently, every tag has a maximum character limit of 200 characters. Tags over the 200 character limit will become truncated, losing potentially important information. To retain this data, you can split data over several tags instead.
169+
170+ For example, a 200+ character tagged request:
171+
172+ ` https://empowerplant.io/api/0/projects/ep/setup_form/?user_id=314159265358979323846264338327&tracking_id=EasyAsABC123OrSimpleAsDoReMi&product_name=PlantToHumanTranslator&product_id=161803398874989484820458683436563811772030917980576 `
173+
174+ The 200+ character request above will become truncated to:
175+
176+ ` https://empowerplant.io/api/0/projects/ep/setup_form/?user_id=314159265358979323846264338327&tracking_id=EasyAsABC123OrSimpleAsDoReMi&product_name=PlantToHumanTranslator&product_id=1618033988749894848 `
177+
178+ <PlatformContent includePath = " performance/control-data-truncation" />
179+
180+ </Expandable >
181+
182+
183+ ## Profiling
184+
185+ <Expandable title = " Why am I not seeing any profiling data?" >
186+
187+ If you don't see any profiling data in [ sentry.io] ( https://sentry.io ) , you can try the following:
188+
189+ - Ensure that <PlatformLink to = " /tracing/" >Tracing is enabled</PlatformLink >.
190+ - Ensure that the automatic instrumentation is sending performance data to Sentry by going to the ** Performance** page in [ sentry.io] ( https://sentry.io ) .
191+ - If the automatic instrumentation is not sending performance data, try using <PlatformLink to = " /tracing/instrumentation/custom-instrumentation" >custom instrumentation</PlatformLink >.
192+ - Enable <PlatformLink to = " /configuration/options/#debug" >debug mode</PlatformLink > in the SDK and check the logs.
193+
194+ ### Upgrading From Older SDK Versions
195+
196+ The feature was experimental prior to version ` 1.17.0 ` . To update your SDK to the latest version, remove ` profiles_sample_rate ` from ` _experiments ` and set it in the top-level options.
197+
198+ ``` python
199+ sentry_sdk.init(
200+ dsn = " ___PUBLIC_DSN___" ,
201+ traces_sample_rate = 1.0 ,
202+ _experiments = {
203+ " profiles_sample_rate" : 1.0 , # for versions before 1.17.0
204+ },
205+ )
206+ ```
207+ </Expandable >
208+
209+
210+ ## Crons
211+
212+ <PlatformContent includePath = " crons/troubleshooting" />
213+
214+ <Expandable title = " Why aren't recurring job errors showing up on my monitor details page?" >
215+
216+ You may not have <PlatformLink to = " /crons/#connecting-errors-to-cron-monitors" >linked errors to your monitor</PlatformLink >.
217+
218+ </Expandable >
219+
220+ <Expandable title = " Why are my monitors showing up as failed?" >
221+
222+ The SDK might be experiencing network issues. Learn more about <PlatformLink to = " /troubleshooting/#network-issues" >troubleshooting network issues</PlatformLink >.
223+
224+ </Expandable >
225+
226+ <Expandable title = " Why am I not receiving alerts when my monitor fails?" >
227+
228+ You may not have <PlatformLink to = " /crons/#alerts" >set up alerts for your monitor</PlatformLink >.
229+
230+ </Expandable >
231+
232+ <Expandable title = " What is the crons data retention policy for check-ins?" >
233+
234+ Our current data retention policy is 90 days.
235+
236+ </Expandable >
237+
238+ <Expandable title = " Do you support a monitor schedule with a six-field crontab expression?" >
239+
240+ Currently, we only support crontab expressions with five fields.
241+
242+ </Expandable >
243+
244+ <Expandable title = " Can I monitor async tasks as well?" >
245+
246+ Yes, just make sure you're using SDK version ` 1.44.1 ` or higher since that's when support for monitoring async functions was added.
247+
248+ </Expandable >
0 commit comments