Skip to content

Commit

Permalink
Add Sentry support to servicelayer workers (#88)
Browse files Browse the repository at this point in the history
* Add Sentry support to servicelayer workers

* Add shell target

* Add sentry support to workers

* Make Sentry environment and release optional
  • Loading branch information
stchris committed Jun 8, 2023
1 parent 50d4a1f commit a3c8850
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@

all: clean install test

.PHONY: build

build-docker:
docker-compose build --no-rm --parallel

Expand All @@ -11,8 +13,11 @@ install:
test:
docker-compose run --rm shell pytest --cov=servicelayer

shell:
docker-compose run --rm shell

build:
python setup.py sdist bdist_wheel
python3 setup.py sdist bdist_wheel

release: clean build
twine upload dist/*
Expand Down
5 changes: 5 additions & 0 deletions servicelayer/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,8 @@
QUEUE_ALEPH = "aleph_queue"
QUEUE_INGEST = "ingest_queue"
QUEUE_INDEX = "index_queue"

# Sentry
SENTRY_DSN = env.get("SENTRY_DSN")
SENTRY_ENVIRONMENT = env.get("SENTRY_ENVIRONMENT", "")
SENTRY_RELEASE = env.get("SENTRY_RELEASE", "")
17 changes: 16 additions & 1 deletion servicelayer/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,26 @@
class Worker(ABC):
"""Workers of all microservices, unite!"""

def __init__(self, conn=None, stages=None, num_threads=settings.WORKER_THREADS):
def __init__(
self,
conn=None,
stages=None,
num_threads=settings.WORKER_THREADS,
):
self.conn = conn or get_redis()
self.stages = stages
self.num_threads = num_threads
self.exit_code = 0
if settings.SENTRY_DSN:
import sentry_sdk

sentry_sdk.init(
dsn=settings.SENTRY_DSN,
traces_sample_rate=0,
release=settings.SENTRY_RELEASE,
environment=settings.SENTRY_ENVIRONMENT,
send_default_pii=False,
)

def _handle_signal(self, signal, frame):
log.warning(f"Shutting down worker (signal {signal})")
Expand Down

0 comments on commit a3c8850

Please sign in to comment.