Skip to content

Commit

Permalink
adding on/off switch for xray (#2261)
Browse files Browse the repository at this point in the history
  • Loading branch information
P0NDER0SA authored Aug 21, 2024
1 parent 36666c8 commit 70c478f
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
15 changes: 8 additions & 7 deletions app/celery/celery.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,14 @@ def init_app(self, app):
task_cls=make_task(app),
)

# Register the xray handlers
signals.after_task_publish.connect(xray_after_task_publish)
signals.before_task_publish.connect(xray_before_task_publish)
signals.task_failure.connect(xray_task_failure)
signals.task_postrun.connect(xray_task_postrun)
signals.task_prerun.connect(xray_task_prerun)
signals.beat_init.connect(xray_task_prerun)
if app.config["AWS_XRAY_ENABLED"] == "true":
# Register the xray handlers
signals.after_task_publish.connect(xray_after_task_publish)
signals.before_task_publish.connect(xray_before_task_publish)
signals.task_failure.connect(xray_task_failure)
signals.task_postrun.connect(xray_task_postrun)
signals.task_prerun.connect(xray_task_prerun)
signals.beat_init.connect(xray_task_prerun)

# See https://docs.celeryproject.org/en/stable/userguide/configuration.html
self.conf.update(
Expand Down
3 changes: 3 additions & 0 deletions app/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,9 @@ class Config(object):
DEBUG = False
NOTIFY_LOG_PATH = os.getenv("NOTIFY_LOG_PATH")

# AWS Xray
AWS_XRAY_ENABLED = os.getenv("AWS_XRAY_ENABLED", "false")

# Cronitor
CRONITOR_ENABLED = False
CRONITOR_KEYS = json.loads(os.getenv("CRONITOR_KEYS", "{}"))
Expand Down
5 changes: 3 additions & 2 deletions application.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@

app = create_app(application)

xray_recorder.configure(service='api')
XRayMiddleware(app, xray_recorder)
if app.config["AWS_XRAY_ENABLED"] == "true":
xray_recorder.configure(service='api')
XRayMiddleware(app, xray_recorder)

apig_wsgi_handler = make_lambda_handler(app, binary_support=True)

Expand Down
5 changes: 3 additions & 2 deletions run_celery.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
application = Flask("celery")
create_app(application)

xray_recorder.configure(service='celery')
XRayMiddleware(application, xray_recorder)
if application.config["AWS_XRAY_ENABLED"] == "true":
xray_recorder.configure(service='celery')
XRayMiddleware(application, xray_recorder)

application.app_context().push()

0 comments on commit 70c478f

Please sign in to comment.