Skip to content

Commit

Permalink
sentryio: change back to synchronous
Browse files Browse the repository at this point in the history
  • Loading branch information
naisanzaa committed Sep 25, 2024
1 parent 9e50334 commit def9f85
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 33 deletions.
46 changes: 23 additions & 23 deletions automon/integrations/sentryio/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,50 +40,50 @@ def __init__(self, dsn: str = None, config: SentryConfig = None, *args, **kwargs
def __repr__(self):
return f'{self.__dict__}'

async def isConnected(self):
if await self.config.is_ready():
def isConnected(self):
if self.config.is_ready():
return True

async def setLevel(self, level):
def setLevel(self, level):
return self.config.setLevel(level)

async def capture_exception(self, exception):
def capture_exception(self, exception):
if self.isConnected():
return _capture_exception(exception)
return False

async def capture_event(self, message: str, level):
def capture_event(self, message: str, level):
if self.isConnected():
return _capture_event(dict(
message=message,
level=level
))
return False

async def capture_message(self, message):
if await self.isConnected():
def capture_message(self, message):
if self.isConnected():
return _capture_message(message)
return False

async def error(self, msg: str):
await self.setLevel('error')
return await self.capture_message(f'{msg}')
def error(self, msg: str):
self.setLevel('error')
return self.capture_message(f'{msg}')

async def warning(self, msg: str):
await self.setLevel('warning')
return await self.capture_message(f'{msg}')
def warning(self, msg: str):
self.setLevel('warning')
return self.capture_message(f'{msg}')

async def warn(self, msg: str):
def warn(self, msg: str):
return self.warning(msg=msg)

async def info(self, msg: str):
await self.setLevel('info')
return await self.capture_message(f'{msg}')
def info(self, msg: str):
self.setLevel('info')
return self.capture_message(f'{msg}')

async def debug(self, msg: str):
await self.setLevel('debug')
return await self.capture_message(f'{msg}')
def debug(self, msg: str):
self.setLevel('debug')
return self.capture_message(f'{msg}')

async def critical(self, msg: str):
await self.setLevel('critical')
return await self.capture_message(f'{msg}')
def critical(self, msg: str):
self.setLevel('critical')
return self.capture_message(f'{msg}')
4 changes: 2 additions & 2 deletions automon/integrations/sentryio/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ def __init__(
def __repr__(self):
return f'{self.__dict__}'

async def is_ready(self):
def is_ready(self):
if self.dsn:
return True

async def setLevel(self, level):
def setLevel(self, level):
self.level = level
return sentry_sdk.set_level(self.level)
11 changes: 5 additions & 6 deletions automon/integrations/sentryio/tests/test_sentryio.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import unittest
import asyncio

from datetime import datetime

Expand All @@ -11,11 +10,11 @@


class SentryClientTest(unittest.TestCase):
async def test_sentry(self):
if await s.isConnected():
self.assertTrue(asyncio.run(s.capture_exception(Exception(f'test capture_exception'))))
self.assertTrue(asyncio.run(s.capture_message(f'test capture_message')))
# self.assertTrue(asyncio.run(s.capture_event('test capture_event', 'warning')))
def test_sentry(self):
if s.isConnected():
self.assertTrue(s.capture_exception(Exception(f'test capture_exception')))
self.assertTrue(s.capture_message(f'test capture_message'))
# self.assertTrue(s.capture_event('test capture_event', 'warning'))


if __name__ == '__main__':
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import unittest
import asyncio

from automon import log
from automon.integrations.sentryio.client import SentryClient
Expand All @@ -11,7 +10,7 @@

class CallbackTest(unittest.TestCase):

async def test_sentry(self):
def test_sentry(self):
self.assertIsNone(logger.info('test'))
self.assertIsNone(logger.debug('test'))
self.assertIsNone(logger.error('test'))
Expand Down

0 comments on commit def9f85

Please sign in to comment.