Skip to content

Commit

Permalink
Release v4.6.1
Browse files Browse the repository at this point in the history
  • Loading branch information
imjoehaines authored Dec 11, 2023
2 parents 563063f + 4de721b commit b22ab1f
Show file tree
Hide file tree
Showing 25 changed files with 695 additions and 499 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
Changelog
=========

## v4.6.1 (2023-12-11)

### Bug fixes

* Avoid using deprecated `flask.__version__` attribute
[#365](/~https://github.com/bugsnag/bugsnag-python/pull/365)
* Ensure the session delivery queue is started regardless of `auto_capture_sessions` configuration
[#367](/~https://github.com/bugsnag/bugsnag-python/pull/367)

## v4.6.0 (2023-09-05)

### Enhancements
Expand Down
13 changes: 10 additions & 3 deletions bugsnag/flask/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from bugsnag.wsgi import request_path
from bugsnag.legacy import _auto_leave_breadcrumb
from bugsnag.breadcrumbs import BreadcrumbType
from bugsnag.utils import remove_query_from_url
from bugsnag.utils import remove_query_from_url, get_package_version


__all__ = ('handle_exceptions',)
Expand Down Expand Up @@ -36,9 +36,16 @@ def add_flask_request_to_notification(event: bugsnag.Event):


def handle_exceptions(app):
middleware = bugsnag.configure().internal_middleware
bugsnag.configure().runtime_versions['flask'] = flask.__version__
configuration = bugsnag.configure()

version = get_package_version("flask")

if version is not None:
configuration.runtime_versions["flask"] = version

middleware = configuration.internal_middleware
middleware.before_notify(add_flask_request_to_notification)

flask.got_request_exception.connect(__log_exception, app)
flask.request_started.connect(_on_request_started, app)

Expand Down
2 changes: 1 addition & 1 deletion bugsnag/notifier.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
_NOTIFIER_INFORMATION = {
'name': 'Python Bugsnag Notifier',
'url': '/~https://github.com/bugsnag/bugsnag-python',
'version': '4.6.0'
'version': '4.6.1'
}
3 changes: 2 additions & 1 deletion bugsnag/sessiontracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ def __init__(self, configuration):
self.delivery_thread = None

def start_session(self):
if not self.auto_sessions and self.config.auto_capture_sessions:
if not self.auto_sessions:
self.auto_sessions = True
self.__start_delivery()

start_time = strftime('%Y-%m-%dT%H:%M:00', gmtime())
new_session = {
'id': uuid4().hex,
Expand Down
17 changes: 17 additions & 0 deletions bugsnag/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,3 +461,20 @@ def to_rfc3339(dt: datetime) -> str:
int(dt.microsecond / 1000),
_get_timezone_offset(dt)
)


def get_package_version(package_name: str) -> Optional[str]:
try:
from importlib import metadata

return metadata.version(package_name) # type: ignore
except ImportError:
try:
import pkg_resources
except ImportError:
return None

try:
return pkg_resources.get_distribution(package_name).version
except pkg_resources.DistributionNotFound:
return None
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

setup(
name='bugsnag',
version='4.6.0',
version='4.6.1',
description='Automatic error monitoring for django, flask, etc.',
long_description=__doc__,
author='Simon Maynard',
Expand Down
6 changes: 5 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ def reset_breadcrumbs():
@pytest.fixture
def bugsnag_server():
server = FakeBugsnagServer(wait_for_duplicate_requests=False)
bugsnag.configure(endpoint=server.url, api_key='3874876376238728937')
bugsnag.configure(
endpoint=server.events_url,
session_endpoint=server.sessions_url,
api_key='3874876376238728937'
)

yield server

Expand Down
6 changes: 5 additions & 1 deletion tests/integrations/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
@pytest.fixture
def bugsnag_server():
server = FakeBugsnagServer(wait_for_duplicate_requests=True)
bugsnag.configure(endpoint=server.url, api_key='3874876376238728937')
bugsnag.configure(
endpoint=server.events_url,
session_endpoint=server.sessions_url,
api_key='3874876376238728937'
)

yield server

Expand Down
35 changes: 19 additions & 16 deletions tests/integrations/test_asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@
class TestASGIMiddleware(IntegrationTest):
def setUp(self):
super(TestASGIMiddleware, self).setUp()
bugsnag.configure(endpoint=self.server.url,
asynchronous=False,
api_key='3874876376238728937',
max_breadcrumbs=25)
bugsnag.configure(
endpoint=self.server.events_url,
session_endpoint=self.server.sessions_url,
asynchronous=False,
api_key='3874876376238728937',
max_breadcrumbs=25,
)

def test_normal_http_operation(self):
async def app(scope, recv, send):
Expand Down Expand Up @@ -46,7 +49,7 @@ async def index(req):
self.assertRaises(ScaryException, lambda: app.get('/'))
self.assertSentReportCount(1)

payload = self.server.received[0]['json_body']
payload = self.server.events_received[0]['json_body']
request = payload['events'][0]['metaData']['request']
self.assertEqual('/', request['path'])
self.assertEqual('GET', request['httpMethod'])
Expand Down Expand Up @@ -84,7 +87,7 @@ async def index(req):
self.assertRaises(ScaryException, lambda: app.get('/'))
self.assertSentReportCount(1)

payload = self.server.received[0]['json_body']
payload = self.server.events_received[0]['json_body']
environment = payload['events'][0]['metaData']['environment']

self.assertEqual('/', environment['path'])
Expand Down Expand Up @@ -116,7 +119,7 @@ async def index(req):
)
self.assertSentReportCount(1)

payload = self.server.received[0]['json_body']
payload = self.server.events_received[0]['json_body']
headers = payload['events'][0]['metaData']['request']['headers']

self.assertEqual('[FILTERED]', headers['authorization'])
Expand All @@ -130,7 +133,7 @@ async def app(scope, recv, send):
self.assertRaises(ScaryException, lambda: app.get('/'))
self.assertSentReportCount(1)

payload = self.server.received[0]['json_body']
payload = self.server.events_received[0]['json_body']
request = payload['events'][0]['metaData']['request']
self.assertEqual('/', request['path'])
self.assertEqual('GET', request['httpMethod'])
Expand Down Expand Up @@ -167,7 +170,7 @@ async def index(req):
self.assertRaises(ScaryException, lambda: app.get('/'))
self.assertSentReportCount(1)

payload = self.server.received[0]['json_body']
payload = self.server.events_received[0]['json_body']
metadata = payload['events'][0]['metaData']
request = metadata['request']
self.assertEqual('/', request['path'])
Expand Down Expand Up @@ -202,7 +205,7 @@ async def app(scope, receive, send):

self.assertSentReportCount(1)

payload = self.server.received[0]['json_body']
payload = self.server.events_received[0]['json_body']
metadata = payload['events'][0]['metaData']
request = metadata['request']
self.assertEqual('/', request['path'])
Expand Down Expand Up @@ -238,7 +241,7 @@ async def index(req):
)
self.assertSentReportCount(1)

payload = self.server.received[0]['json_body']
payload = self.server.events_received[0]['json_body']
request = payload['events'][0]['metaData']['request']
self.assertEqual(
'http://testserver/path?password=[FILTERED]',
Expand Down Expand Up @@ -272,7 +275,7 @@ async def index(req):
)
self.assertSentReportCount(1)

payload = self.server.received[0]['json_body']
payload = self.server.events_received[0]['json_body']
request = payload['events'][0]['metaData']['request']
self.assertEqual('/', request['path'])
self.assertEqual('GET', request['httpMethod'])
Expand Down Expand Up @@ -316,7 +319,7 @@ async def index(req):

assert self.sent_report_count == 1

payload = self.server.received[0]['json_body']
payload = self.server.events_received[0]['json_body']

print(payload)
assert len(payload['events'][0]['exceptions']) == 2
Expand Down Expand Up @@ -364,7 +367,7 @@ async def index(req):

assert self.sent_report_count == 1

payload = self.server.received[0]['json_body']
payload = self.server.events_received[0]['json_body']
exception = payload['events'][0]['exceptions'][0]
feature_flags = payload['events'][0]['featureFlags']

Expand All @@ -383,7 +386,7 @@ async def index(req):

assert self.sent_report_count == 2

payload = self.server.received[1]['json_body']
payload = self.server.events_received[1]['json_body']
feature_flags = payload['events'][0]['featureFlags']

assert feature_flags == [
Expand All @@ -396,7 +399,7 @@ async def index(req):

assert self.sent_report_count == 3

payload = self.server.received[2]['json_body']
payload = self.server.events_received[2]['json_body']
feature_flags = payload['events'][0]['featureFlags']

assert feature_flags == []
29 changes: 15 additions & 14 deletions tests/integrations/test_bottle.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
class TestBottle(IntegrationTest):
def setUp(self):
super(TestBottle, self).setUp()
bugsnag.configure(endpoint=self.server.url,
session_endpoint=self.server.url,
auto_capture_sessions=False,
api_key='3874876376238728937',
asynchronous=False)
bugsnag.configure(
endpoint=self.server.events_url,
session_endpoint=self.server.sessions_url,
api_key='3874876376238728937',
asynchronous=False,
)

def test_routing_error(self):
@route('/beans')
Expand All @@ -26,8 +27,8 @@ def index():
app = TestApp(BugsnagMiddleware(app))

self.assertRaises(Exception, lambda: app.get('/beans?password=123'))
self.assertEqual(1, len(self.server.received))
payload = self.server.received[0]['json_body']
self.assertEqual(1, len(self.server.events_received))
payload = self.server.events_received[0]['json_body']
event = payload['events'][0]
self.assertTrue(event['unhandled'])
self.assertEqual(event['context'], 'GET /beans')
Expand All @@ -54,8 +55,8 @@ def index():
app = TestApp(BugsnagMiddleware(app))

self.assertRaises(Exception, lambda: app.get('/beans'))
self.assertEqual(1, len(self.server.received))
payload = self.server.received[0]['json_body']
self.assertEqual(1, len(self.server.events_received))
payload = self.server.events_received[0]['json_body']
metadata = payload['events'][0]['metaData']
self.assertEqual(metadata['environment']['PATH_INFO'], '/beans')

Expand All @@ -69,9 +70,9 @@ def index(variety):
app = TestApp(BugsnagMiddleware(app))

self.assertRaises(Exception, lambda: app.get('/berries/red'))
self.assertEqual(1, len(self.server.received))
self.assertEqual(1, len(self.server.events_received))

payload = self.server.received[0]['json_body']
payload = self.server.events_received[0]['json_body']
event = payload['events'][0]
self.assertTrue(event['unhandled'])
self.assertEqual(event['context'], 'GET /berries/red')
Expand Down Expand Up @@ -112,7 +113,7 @@ def index():

assert self.sent_report_count == 1

payload = self.server.received[0]['json_body']
payload = self.server.events_received[0]['json_body']
exception = payload['events'][0]['exceptions'][0]
feature_flags = payload['events'][0]['featureFlags']

Expand All @@ -131,7 +132,7 @@ def index():

assert self.sent_report_count == 2

payload = self.server.received[1]['json_body']
payload = self.server.events_received[1]['json_body']
feature_flags = payload['events'][0]['featureFlags']

assert feature_flags == [
Expand All @@ -144,7 +145,7 @@ def index():

assert self.sent_report_count == 3

payload = self.server.received[2]['json_body']
payload = self.server.events_received[2]['json_body']
feature_flags = payload['events'][0]['featureFlags']

assert feature_flags == []
Loading

0 comments on commit b22ab1f

Please sign in to comment.