getsentry / sentry-python Goto Github PK
View Code? Open in Web Editor NEWThe official Python SDK for Sentry.io
Home Page: https://sentry.io/for/python/
License: MIT License
The official Python SDK for Sentry.io
Home Page: https://sentry.io/for/python/
License: MIT License
I misunderstood what the option meant. Do not release for now. gtg
When trying to deploy a "Chalice" serverless App, getting exception:
File "/Users/cookie/.virtualenvs/abc/lib/python3.6/site-packages/sentry_sdk/integrations/aws_lambda.py", line 21, in install
old_make_final_handler = lambda_bootstrap.make_final_handler
AttributeError: module '__main__' has no attribute 'make_final_handler'
sentry-python version: 0.3.9
Code in app.py
:
import sentry_sdk
from sentry_sdk.integrations.aws_lambda import AwsLambdaIntegration
sentry_sdk.init(
dsn="https://[email protected]/12345678",
integrations=[AwsLambdaIntegration()]
)
Where exactly am I supposed to put sentry_sdk.init()
?
If I put it in settings.py
, I see no error messages being reported.
The docs say nothing about dajngo + new sentry-sdk
, except the fact that raven
one is deprecated!
We have a simple test that verifies the Sentry SDK is capturing Flask errors because we had some configuration/PyPy issues in the past:
As of this writing we don't pin the sentry-sdk
version:
https://github.com/getsentry/snuba/blob/fd44ec8880240575ee2cb05bfc87e4cfd1d0e853/setup.py#L80
The test started failing because it seems that as of 0.3.7
(I tried 0.3.6
and wasn't able to reproduce the issue) the transport
is being called twice for the same exception, causing the number of reported issues to be 2
instead of 1
.
Maybe this is a false alarm but I think our integration is relatively simple so this may be signs of a larger issue?
Pull Request #30
Sometimes an error report line is reported incorrectly
tb.tb_fame.f_lineno may differ in some way.
Must use tb.tb_lineno
sentry-sdk/event.py
class Event(Mapping):
__slots__ = ("_data", "_exc_value")
def __init__(self, data={}):
self._data = {
"event_id": uuid.uuid4().hex,
"timestamp": datetime.datetime.utcnow(),
"level": "error",
}
self._data.update(data)
self._exc_value = None
def set_exception(self, exc_type, exc_value, tb, with_locals):
print("----------------- trace back --------------------")
print("f_lineno: " + str(tb.tb_next.tb_next.tb_frame.f_lineno))
print("tb_lineno: " + str(tb.tb_next.tb_next.tb_lineno))
print("f_lineno: " + str(tb.tb_next.tb_next.tb_next.tb_frame.f_lineno))
print("tb_lineno: " + str(tb.tb_next.tb_next.tb_next.tb_lineno))
print("f_lineno: " + str(tb.tb_next.tb_next.tb_next.tb_next.tb_frame.f_lineno))
print("tb_lineno: " + str(tb.tb_next.tb_next.tb_next.tb_next.tb_lineno))
print("f_lineno: " + str(tb.tb_next.tb_next.tb_next.tb_next.tb_next.tb_frame.f_lineno))
print("tb_lineno: " + str(tb.tb_next.tb_next.tb_next.tb_next.tb_next.tb_lineno))
print("f_lineno: " + str(tb.tb_next.tb_next.tb_next.tb_next.tb_next.tb_next.tb_frame.f_lineno))
print("tb_lineno: " + str(tb.tb_next.tb_next.tb_next.tb_next.tb_next.tb_next.tb_lineno))
print("f_lineno: " + str(tb.tb_next.tb_next.tb_next.tb_next.tb_next.tb_next.tb_next.tb_frame.f_lineno))
print("tb_lineno: " + str(tb.tb_next.tb_next.tb_next.tb_next.tb_next.tb_next.tb_next.tb_lineno))
print("f_lineno: " + str(tb.tb_next.tb_next.tb_next.tb_next.tb_next.tb_next.tb_next.tb_next.tb_frame.f_lineno))
print("tb_lineno: " + str(tb.tb_next.tb_next.tb_next.tb_next.tb_next.tb_next.tb_next.tb_next.tb_lineno))
print("----------------- trace back --------------------")
self["exception"] = {
"values": exceptions_from_error_tuple(exc_type, exc_value, tb, with_locals)
}
self._exc_value = exc_value
trace back
File "example.py", line 128, in _get_response
response = self.process_exception_by_middleware(e, request)
File "example.py", line 126, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "example.py", line 54, in wrapped_view
return view_func(*args, **kwargs)
File "example.py", line 69, in view
return self.dispatch(request, *args, **kwargs)
File "example.py", line 483, in dispatch
response = self.handle_exception(exc)
File "example.py", line 443, in handle_exception
self.raise_uncaught_exception(exc)
File "example.py", line 480, in dispatch
response = handler(request, *args, **kwargs)
File "example.py", line 210, in post
output
----------------- trace back --------------------
f_lineno: 128
tb_lineno: 126
f_lineno: 54
tb_lineno: 54
f_lineno: 69
tb_lineno: 69
f_lineno: 483
tb_lineno: 483
f_lineno: 443
tb_lineno: 443
f_lineno: 483
tb_lineno: 480
f_lineno: 213
tb_lineno: 210
----------------- trace back --------------------
With raven-python we could add extra
param to captureMessage
. Now with sentry-python capture_message
does not accept extra param.
Can we add extra data to event or message ?
Tracking interest at the moment. If you're interested in this please give this post a ๐ reaction. Don't post your ๐ as comment, this makes it harder to track.
(Note: The raven-python SDK supports Tornado too)
Raven used to put sys.argv
as extra key. This is useful for CLI apps
I have followed installation instructions mentioned in this page
https://docs.sentry.io/quickstart?platform=python
After a while, sentry fails and gives this error message.
File "/app/.heroku/python/lib/python3.6/site-packages/sentry_sdk/api.py", line 91, in add_breadcrumb
return hub.add_breadcrumb(*args, **kwargs)
File "/app/.heroku/python/lib/python3.6/site-packages/sentry_sdk/hub.py", line 206, in add_breadcrumb
scope._breadcrumbs.popleft()
AttributeError: 'list' object has no attribute 'popleft'
https://github.com/getsentry/sentry-python/blob/master/sentry_sdk/hub.py#L209
Chalice defines itself as "Python Serverless Microframework for AWS": https://github.com/aws/chalice
Some relevant information here: #110.
EDIT: Please vote on this issue with ๐ for Chalice support.
We only report the local function name in old transactions for django. David wants this to be the URL rule for Django. We should port the old resolver over to it (https://github.com/getsentry/raven-python/blob/03559bb05fd963e2be96372ae89fb0bce751d26d/raven/contrib/django/resolver.py).
When trying to import AwsLambdaIntegration
I get following Error:
ModuleNotFoundError: No module named 'runtime'
Traceback:
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-1-f0a35f42fdce> in <module>()
----> 1 from sentry_sdk.integrations.aws_lambda import AwsLambdaIntegration
~/Envs/gds/lib/python3.6/site-packages/sentry_sdk/integrations/aws_lambda.py in <module>()
13
14 import __main__ as lambda_bootstrap
---> 15 import runtime as lambda_runtime
16
17
ModuleNotFoundError: No module named 'runtime'
Version:
sentry-sdk==0.3.9
I tried install runtime
package, but it didn't help, because then I get:
~/Envs/gds/lib/python3.6/site-packages/runtime.py in <module>()
26 from thread import get_ident
27 except ImportError: # pragma: no cover
---> 28 from dummy_thread import get_ident
29
30 __all__ = (
ModuleNotFoundError: No module named 'dummy_thread'
And pip install thread
returns:
No matching distribution found for thread
While moving a project from raven-python to sentry-python I noticed, that there is no documentation (and maybe implementation?) for the template tag {% sentry_public_dsn %}
.
It was available in raven-python - I found it to be quiet handy.
I hope I am not missing something - or is there a reason that this wasn't implemented?
Python 3.7.0, sentry_sdk 0.3.2
2018-09-21 18:08:21,575 DEBUG Internal error in sentry_sdk
Traceback (most recent call last):
File "/home/dmugtasimov/.virtualenvs/packy-agent2-eBU3dgqa/lib/python3.7/site-packages/sentry_sdk/utils.py", line 28, in capture_internal_exceptions
yield
File "/home/dmugtasimov/.virtualenvs/packy-agent2-eBU3dgqa/lib/python3.7/site-packages/sentry_sdk/integrations/logging.py", line 102, in _emit
self._breadcrumb_from_record(record), hint={"log_record": record}
File "/home/dmugtasimov/.virtualenvs/packy-agent2-eBU3dgqa/lib/python3.7/site-packages/sentry_sdk/hub.py", line 209, in add_breadcrumb
scope._breadcrumbs.popleft()
AttributeError: 'list' object has no attribute 'popleft'
sentry-sdk==0.3.9
When Exception happens inside celery task, I can see traceback in sentry, but without local variables.
As a workaround, I am capturing exception directly, in BaseTask
and it works.
class BaseTask(Task):
def on_failure(self, exc, task_id, *args, **kwargs):
"""When passing raw exception to sentry we will get local variable values instead of just message"""
with push_scope() as scope:
scope.set_extra('task_id', task_id)
scope.set_extra('retries', self.request.retries)
capture_exception(exc)
super().on_failure(exc, task_id, *args, **kwargs)
usage: @shared_task(base=BaseTask)
In CeleryIntegration
def _process_failure_signal(self, sender, task_id, einfo, **kw):
gets einfo
, so I don't know why it's not working out of the box.
Traceback (most recent call last):
File "/app/.heroku/python/lib/python3.7/site-packages/botocore/vendored/requests/packages/urllib3/connectionpool.py", line 372, in _make_request
httplib_response = conn.getresponse(buffering=True)
File "/app/.heroku/python/lib/python3.7/site-packages/sentry_sdk/integrations/stdlib.py", line 38, in getresponse
rv = real_getresponse(self, *args, **kwargs)
TypeError: getresponse() got an unexpected keyword argument 'buffering'
A client should not ignore the django logger if the client does not have the django integration enabled.
In the previous version of the sdk, with django I've specialized logging handlers for sentry, this allows for example, that some specific logging always target sentry.
Now I see that only the level control if the message ends in sentry.
Is there any plan of adding the previous feature to the new client?
Is there any support to transport synchronously like HTTPTransport
of raven
(https://docs.sentry.io/clients/python/transports/#sync)? I could not find any support as far as I read code.
I want to transport synchronously for AWS Batch. AWS Batch can not send any exceptions in asynchronous way because it stop as soon as it raises exceptions.
We should be able to capture errors resulting from a crashing manage.py
task, see #19
sentry.io cannot handle "" as meta key, only "_meta"
since sys.excepthook
is not called for threads that crash, we should write a separate integration for this (turned on by default)
I have a sentry server set up on premises. I did this a couple weeks ago, just before you guys updated the docs with the new unified SDK.
Now I'm updating our project (Django) to use the python sdk. The problem is that in our project in sentry, the DSN I see has this format:
http://[email protected]:9000//2
Now the problem comes when initializing the integration. This DSN format (note: the double slash there) makes the initialization fail in sentry_sdk/utils.py
line 77, when int('/2')
is attempted.
This is easily fixed by simply removing the extra slash, but might be a headache for anyone who doesn't notice that.
Not sure if the SDK should handle this or if this is an issue with Sentry itself, but at least this didn't use to happen with Raven.
Python: 3.6.5
Django: 2.1.2
sentry-sdk: 0.4.2
I upgraded from raven to sentry-sdk yesterday and noticed my app was now keeping database connections open rather than closing them per request.
I wrote a tiny view to test this:
def sentry_test(request):
from django.contrib.auth.models import User
print(User.objects.all())
return HttpResponse("<h1>Hello</h1>")
and when GET the URL repeatedly I see the subsequent connections remain idle after the request has completed:
=> SELECT state, query FROM pg_stat_activity WHERE client_addr IS NOT NULL;
state | query
--------+-----------------------------------------------------
idle | SELECT "auth_user"."id", "auth_user"."password", ...
active | SELECT state, query FROM pg_stat_activity WHERE client_addr IS NOT NULL;
idle | SELECT "auth_user"."id", "auth_user"."password", ...
idle | SELECT "django_migrations"."app", "django_migrations"."name" FROM "django_migrations"
idle | SELECT "auth_user"."id", "auth_user"."password", ...
idle | SELECT "auth_user"."id", "auth_user"."password", ...
idle | SELECT "auth_user"."id", "auth_user"."password", ...
As you can see the connection from the migrate query on startup has remained open too.
If I use raven this behaviour is not exhibited.
I suspect this won't help much, but if I use sentry-sdk and comment out:
WSGIHandler.__call__ = sentry_patched_wsgi_handler
Then the problem doesn't manifest itself but I've basically turned off sentry at this stage.
A debug mode should be added that logs out when events are dropped and internal exceptions are ignored.
drain_timeout -> shutdown_timeout
@mitsuhiko could you look over
? I wonder if it would make sense to just write to the scope eagerly instead. Weakref on the environ dict is kind of shitty: Any middleware or web framework could dodict(environ)
and the weakref is brokenWe should django-rest-framework's request.data
instead of trying to extract a structured body ourselves
from #19
Basically if Django/Flask itself crashes (or some wsgi middleware) we won't notice.
This is slightly related to #20 because we need to wrap the WSGI app last if somebody decided to use WSGI middleware in Django.
In Flask we can wrap Flask.__call__
An unsolved question is whether we want to attach basic request info for such events, and if we're better off doing the entire request parsing in the wsgi middleware at that point.
@mitsuhiko discovered that passing around hubs does not work at all and we likely leak state between requests
The logging integration will capture the errors from the REPL and send them to sentry. We should try to detect those loggers and ignore them entirely.
The default HTTP Transport lives on its own thread and will not inherit the debug settings of the hub where the message was captured. It's basically impossible to enable debugging for threaded transports unless you make your hub the main one
I don't see a clear way to integrate with aiohttp (server) just yet. I can still use raven at present, but I imagine sentry-python/sentry-sdk is the proposed way forward longer term?
We should bring back support for rq.
Hello !
I just switched to using sentry-sdk instead of raven.
However I was getting the following error:
2018-10-17 13:14:54,907: Error running WSGI application
2018-10-17 13:14:54,913: ValueError: Unable to configure handler 'sentry': Cannot resolve 'raven.contrib.django.raven_compat.handlers.SentryHandler': No module named 'raven'
2018-10-17 13:14:54,915: File "/var/www/www_mysite_com_wsgi.py", line 18, in <module>
2018-10-17 13:14:54,917: application = get_wsgi_application()
Which was fixed by reinstalling raven via pip.
Is it intended for raven to be a requirement ? It's not mentioned in either the Python or Django related pages: https://docs.sentry.io/platforms/python/django/
Test Plan:
The user data that's logged by default (with sending of PII enabled) looks something like
{'username': teeberg', 'ip_address': '127.0.0.1', 'email': [email protected]'}
I'm trying to add some fields to this, but there doesn't seem to be an official documented way to do this.
Is there a cleaner way than monkey-patching sentry_sdk.integrations.django._set_user_info
?
Maybe the request could be sent along as another hint to before_send
handlers?
Pyramid was previously supported by raven. It would be great to see support for it in this client. Is this perhaps already on the roadmap?
Also if there is any documentation on how to write an integration I might be tempted to contribute.
We're having an issue with v0.3.2 where popleft
is called on a list type:
File "/srv/frontend/project/lib/python3.5/site-packages/sentry_sdk/hub.py" in add_breadcrumb
209. scope._breadcrumbs.popleft()
Exception Type: AttributeError at /
Exception Value: 'list' object has no attribute 'popleft'
AttributeError
'Identifier' object has no attribute 'postponed_alerts_counts'
ID: 8099fd1f8815496eaa1f815657918b9d
Sept. 26, 2018, 7:37:17 p.m. UTC
Exception
AttributeError: 'Identifier' object has no attribute 'postponed_alerts_counts'
File "interfaces.py", line 43, in start
self.startInternal()
File "identifier.py", line 63, in startInternal
send_time=send_time)
File "identifier.py", line 128, in match_batch
accepted = self.correct_by_past_history(match.person_guid, confident_score)
File "identifier.py", line 91, in correct_by_past_history
self.postponed_alerts_counts[guid] += 1
from #19
I have some tasks that require distributed lock mechanism and it is implemented as decorator for celery tasks:
@app.task
@celery_lock('receive_tasks', ttl=40)
def receive_tasks(ad_id):
raise Exception('sentry')
When exception is raised i get two error events logged, one is with tags: handled=no,level=error,mechanism=celery,server_name=,transaction=.receive_tasks
and warning text:
There was 1 error encountered while processing this event
Discarded invalid parameter '' Expand
Second event is almost equal to first one, but with tags: handled=yes, level=error, logger=celery.worker.job, mechanism=logging, server_name=
And contains message from celery worker stdout:
Task .receive_tasks[f209f4c9-61cb-47b8-94ea-b15e69933897] raised unexpected: Exception('sentry',)
If i remove @celery_lock decorator from task or pass lock_id as named argument @celery_lock(lock_id='receive_tasks', ttl=40), then all works fine - just one event received and no warnings.
Seems that this problem shows up because of non-keyword decorator args.
celery_lock implemented as simple decorator:
def celery_lock(lock_id, ttl):
def decorator(func):
@wraps(func)
def lock_decorator(*args, **kwargs):
with CeleryLock(lock_id, ttl) as aq:
if not aq:
return 'locked'
return func(*args, **kwargs)
return lock_decorator
return decorator
We've just started using sentry, and we are occasionally seeing this error:
AttributeError
'list' object has no attribute 'popleft'
hub.py in add_breadcrumb at line 206
if crumb is not None:
scope._breadcrumbs.append(crumb)
else:
logger.info("before breadcrumb dropped breadcrumb (%s)", original_crumb)
while len(scope._breadcrumbs) >= client.options["max_breadcrumbs"]:
scope._breadcrumbs.popleft()
def push_scope(self):
"""Pushes a new layer on the scope stack. Returns a context manager
that should be used to pop the scope again."""
client, scope = self._stack[-1]
And, furthermore in sentry it says:
client | <sentry_sdk.client.Client object at 0x7fd665dcbcc0>
-- | --
crumb | {category: 'httplib', data: {method: 'POST', reason: 'OK', status_code: 200, url: 'https://us-west-2.queue.amazonaws.com/'}, timestamp: datetime.datetime(2018, 9, 25, 16, 20, 20, 89233), type: 'http'}
hint | {httplib_response: <http.client.HTTPResponse object at 0x7fd645fd7e80>}
kwargs | {category: 'httplib', data: {method: 'POST', reason: 'OK', status_code: 200, url: 'https://us-west-2.queue.amazonaws.com/'}, type: 'http'}
original_crumb | {category: 'httplib', data: {method: 'POST', reason: 'OK', status_code: 200, url: 'https://us-west-2.queue.amazonaws.com/'}, timestamp: datetime.datetime(2018, 9, 25, 16, 20, 20, 89233), type: 'http'}
scope | <sentry_sdk.scope.Scope object at 0x7fd665b41d68>
self | <sentry_sdk.hub.Hub object at 0x7fd665aeb320>
Any thoughts on what is going on?
Thanks!
-- Samson
While migrating sentry.io to the new SDK this came up: There should be two separate handlers, one for creating events and one for creating breadcrumbs. Expose and document them as well.
Please, I'm missing this feature from raven
.
https://github.com/getsentry/raven-python/blob/4206873d63c461ffe6944029d36951514157928e/raven/base.py#L842
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.