diff --git a/actur/reader.py b/actur/reader.py index e8228eb..ccebd5e 100644 --- a/actur/reader.py +++ b/actur/reader.py @@ -4,6 +4,7 @@ import time import feedparser +import sentry_sdk from actur.config import readconf as rc from actur.utils import dbif, feeds, hasher @@ -71,7 +72,8 @@ def process_feed( global _logger bump_processed, bump_added, bump_skipped, get_counts = pcounters() feedname = feed.name - print("feedname", feedname) + if not silent: + print("feedname", feedname) url = feed.url d = feedparser.parse(url) if not silent: @@ -109,6 +111,7 @@ def process_feed( # print(f"title {title} classified as {category}") except Exception as e: msg = f"Classifier exception on title {title}: {e}" + sentry_sdk.capture_message(msg) if not silent: print(msg) if not no_logging: @@ -152,6 +155,7 @@ def process_pubs(xgroup: str | None, silent: bool, no_logging: bool, categorize: parse_pub(pub, silent, categorize, no_logging) except Exception as e: msg = f"Could not read {pub.name}: {e}" + sentry_sdk.capture_message(msg) if not silent: print(msg) if not no_logging: diff --git a/actur/sentry_div.py b/actur/sentry_div.py new file mode 100644 index 0000000..a5c3d73 --- /dev/null +++ b/actur/sentry_div.py @@ -0,0 +1,10 @@ +import sentry_sdk +from config import readconf as rc + +dsn = rc.get_conf_by_key("sentry")["dsn"] + +sentry_sdk.init( + dsn=rc.get_conf_by_key("sentry")["dsn"], +) + +div_by_zero = 1 / 0 diff --git a/actur/sentry_test.py b/actur/sentry_test.py new file mode 100644 index 0000000..cf40250 --- /dev/null +++ b/actur/sentry_test.py @@ -0,0 +1,38 @@ +import sentry_sdk +import sentry_sdk.profiler +from config import readconf as rc + + +sentry_sdk.init( + dsn=rc.get_conf_by_key("sentry")["dsn"], + # Set traces_sample_rate to 1.0 to capture 100% + # of transactions for tracing. + traces_sample_rate=1.0, +) + + +def slow_function(): + import time + + time.sleep(0.1) + return "done" + + +def fast_function(): + import time + + time.sleep(0.05) + return "done" + + +# Manually call start_profiler and stop_profiler +# to profile the code in between +sentry_sdk.profiler.start_profiler() +for i in range(0, 10): + slow_function() + fast_function() +# +# Calls to stop_profiler are optional - +# if you don't stop the profiler, it will keep profiling +# your application until the process exits or stop_profiler is called. +sentry_sdk.profiler.stop_profiler() diff --git a/actur/utils/dbif.py b/actur/utils/dbif.py index 5505546..807f62e 100644 --- a/actur/utils/dbif.py +++ b/actur/utils/dbif.py @@ -2,6 +2,19 @@ import pymongo from bson.json_util import dumps, RELAXED_JSON_OPTIONS from actur.config import readconf as rc +import sentry_sdk + +sentry_sample_rate = rc.get_conf_by_key("sentry")["sample_rate"] +sentry_sdk.init( + dsn=rc.get_conf_by_key("sentry")["dsn"], + # Set traces_sample_rate to 1.0 to capture 100% + # of transactions for tracing. + traces_sample_rate=sentry_sample_rate, + # Set profiles_sample_rate to 1.0 to profile 100% + # of sampled transactions. + # We recommend adjusting this value in production. + profiles_sample_rate=sentry_sample_rate, +) _host: str | None = None _client: pymongo.MongoClient @@ -37,8 +50,9 @@ def _init_db(): def save_article(entry): - db = get_db() - db.articles.insert_one(entry) + with sentry_sdk.start_transaction(op="save_article"): + db = get_db() + db.articles.insert_one(entry) def get_article_count() -> int: @@ -47,14 +61,15 @@ def get_article_count() -> int: def is_summary_in_db(target_hash, summary): - db = get_db() - articles_with_target_hash = db.articles.find({"hash": target_hash}) - for article in articles_with_target_hash: - if article["summary"] == summary: - return True - else: - continue - return False + with sentry_sdk.start_transaction(op="is_summary_in_db"): + db = get_db() + articles_with_target_hash = db.articles.find({"hash": target_hash}) + for article in articles_with_target_hash: + if article["summary"] == summary: + return True + else: + continue + return False def find_text(collname: str, search_text: str): diff --git a/notes.md b/notes.md index f8435a4..52a008c 100644 --- a/notes.md +++ b/notes.md @@ -13,7 +13,6 @@ pytest --cov=actur tests/ - ## proposed signal handler ```python @@ -75,14 +74,14 @@ For display to work, must export ACTUCONF=$HOME/.actur/local.toml (this is now t Copy sup-actur.conf to /etc/supervisor/conf.d/actur.conf -and restart supervisor supervisorctl start actur-local [or start all if actuproxy being used] +and restart supervisor supervisorctl start actur-local [or start all if actuproxy being used] New openai interface: -https://github.com/openai/openai-python/discussions/742 -discussion +discussion [https://github.com/openai/openai-python/discussions/742] ## commands + actu read --categorize [--silent] [-d] actu show -h 3 all diff --git a/setup.py b/setup.py index 28aa9a5..5cd7e91 100644 --- a/setup.py +++ b/setup.py @@ -50,6 +50,6 @@ test_suite="tests", tests_require=test_requirements, url="https://github.com/agoldhammer/actur", - version="0.1.0", + version="0.2.2", zip_safe=False, )