From 6a88004a7110319b2036becb5ce7c56a207d9d17 Mon Sep 17 00:00:00 2001 From: Art Goldhammer Date: Wed, 22 Jan 2025 14:47:59 -0500 Subject: [PATCH 1/8] basic sentry setup working --- actur/sentry_div.py | 10 ++++++++++ actur/sentry_test.py | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 actur/sentry_div.py create mode 100644 actur/sentry_test.py 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() From 91e037840c8cdd302604b24ebec2df7a6128de00 Mon Sep 17 00:00:00 2001 From: Art Goldhammer Date: Wed, 22 Jan 2025 16:52:24 -0500 Subject: [PATCH 2/8] sentry tracing db inserts on read; stop print of feedname on silent --- actur/reader.py | 3 ++- actur/utils/dbif.py | 34 ++++++++++++++++++++++++---------- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/actur/reader.py b/actur/reader.py index e8228eb..0a0f897 100644 --- a/actur/reader.py +++ b/actur/reader.py @@ -71,7 +71,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: diff --git a/actur/utils/dbif.py b/actur/utils/dbif.py index 5505546..fd6464f 100644 --- a/actur/utils/dbif.py +++ b/actur/utils/dbif.py @@ -2,6 +2,18 @@ import pymongo from bson.json_util import dumps, RELAXED_JSON_OPTIONS from actur.config import readconf as rc +import sentry_sdk + +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, + # Set profiles_sample_rate to 1.0 to profile 100% + # of sampled transactions. + # We recommend adjusting this value in production. + profiles_sample_rate=1.0, +) _host: str | None = None _client: pymongo.MongoClient @@ -37,8 +49,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 +60,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): From 068078d26bed5f2b14f7e6c51caf405c988a65c7 Mon Sep 17 00:00:00 2001 From: Art Goldhammer Date: Wed, 22 Jan 2025 16:56:56 -0500 Subject: [PATCH 3/8] edited notes.md --- notes.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) 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 From 3b157a6740fa206659b49ee9b0bdbe5a8cdd31f7 Mon Sep 17 00:00:00 2001 From: Art Goldhammer Date: Thu, 23 Jan 2025 06:08:49 -0500 Subject: [PATCH 4/8] bumped version to 0.2; reduced sample rate to 0.5 --- actur/utils/dbif.py | 4 ++-- setup.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/actur/utils/dbif.py b/actur/utils/dbif.py index fd6464f..2b0a2c6 100644 --- a/actur/utils/dbif.py +++ b/actur/utils/dbif.py @@ -8,11 +8,11 @@ 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, + traces_sample_rate=0.5, # Set profiles_sample_rate to 1.0 to profile 100% # of sampled transactions. # We recommend adjusting this value in production. - profiles_sample_rate=1.0, + profiles_sample_rate=0.5, ) _host: str | None = None diff --git a/setup.py b/setup.py index 28aa9a5..95c37a8 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.0", zip_safe=False, ) From dc134336e7395513b6b5c9493ccf01d2cbfdaeaa Mon Sep 17 00:00:00 2001 From: Art Goldhammer Date: Thu, 23 Jan 2025 10:49:50 -0500 Subject: [PATCH 5/8] added capture_msg in reader.py; bump version to 0.2.1 --- actur/reader.py | 3 +++ setup.py | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/actur/reader.py b/actur/reader.py index 0a0f897..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 @@ -110,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: @@ -153,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/setup.py b/setup.py index 95c37a8..b144ebd 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.2.0", + version="0.2.1", zip_safe=False, ) From 25d3af3412693201b8ff5ecd69158c726bdf5187 Mon Sep 17 00:00:00 2001 From: Art Goldhammer Date: Fri, 24 Jan 2025 12:52:51 -0500 Subject: [PATCH 6/8] move sample rate setting to toml config --- actur/utils/dbif.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/actur/utils/dbif.py b/actur/utils/dbif.py index 2b0a2c6..ea6c3ad 100644 --- a/actur/utils/dbif.py +++ b/actur/utils/dbif.py @@ -1,18 +1,20 @@ +from random import sample import pendulum 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=0.5, + 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=0.5, + profiles_sample_rate=sentry_sample_rate, ) _host: str | None = None From 0741150f5c7c4b5646ac9be7ab4a2e28bf3f4e4a Mon Sep 17 00:00:00 2001 From: Art Goldhammer Date: Fri, 24 Jan 2025 12:56:49 -0500 Subject: [PATCH 7/8] removed extraneous import --- actur/utils/dbif.py | 1 - 1 file changed, 1 deletion(-) diff --git a/actur/utils/dbif.py b/actur/utils/dbif.py index ea6c3ad..807f62e 100644 --- a/actur/utils/dbif.py +++ b/actur/utils/dbif.py @@ -1,4 +1,3 @@ -from random import sample import pendulum import pymongo from bson.json_util import dumps, RELAXED_JSON_OPTIONS From ea21442befe57b348b4a6b16f9873d16e540b23d Mon Sep 17 00:00:00 2001 From: Art Goldhammer Date: Fri, 24 Jan 2025 14:19:22 -0500 Subject: [PATCH 8/8] version to 0.2.2 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index b144ebd..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.2.1", + version="0.2.2", zip_safe=False, )