Skip to content

Commit

Permalink
Resolved id issue
Browse files Browse the repository at this point in the history
  • Loading branch information
k-macmillan committed Dec 2, 2024
1 parent ff21988 commit b03bc17
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions app/celery/celery.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,13 @@ def filter(self, record):

@task_prerun.connect
def add_id_to_logger(task_id, task, *args, **kwargs):
logger = logging.getLogger()
logger.info('celery args: %s | kwargs: %s | task_id: %s', args, kwargs, task_id)
request_id = kwargs.get('notification_id', task_id)
request_id = kwargs.get('kwargs', {}).get('notification_id', task_id)
current_app.logger.addFilter(CeleryRequestIdFilter(request_id, f'celery-{request_id}'))


@task_postrun.connect
def id_cleanup_logger(task_id, task, *args, **kwargs):
request_id = kwargs.get('notification_id', task_id)
request_id = kwargs.get('kwargs', {}).get('notification_id', task_id)
for filter in current_app.logger.filters:
if filter.name == f'celery-{request_id}':
current_app.logger.removeFilter(filter)

0 comments on commit b03bc17

Please sign in to comment.