Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lost logs from threads #84

Merged
merged 5 commits into from
Nov 6, 2024
Merged

Lost logs from threads #84

merged 5 commits into from
Nov 6, 2024

Conversation

Geary-Layne
Copy link
Contributor

@Geary-Layne Geary-Layne commented Nov 1, 2024

Linear Issue

IDSSE-1011

Changes

  • There wasn't so much as a bug, as missing logic
    • We use python's ContextVars to make corr_id available to logging
    • It turns out that a thread doesn't inherit ContextVars automatically
    • There are two ways to get logs from threads
        1. We can initialize our logger to not use corr_id logging.config.dictConfig(get_default_log_config('INFO', with_corr_id=False))
        1. Pass ContextVars to threads
    • I added tests two test_log_util.py that test getting logs from a thread running a function and from Classes that extend Threads
    • I added passing ContextVars to Consume/Publisher in rabbitmq_utils.py
  • There are likely other places in our code that logs are getting lost in threads, and the test in log_util.py will serve as example code

Explanation

N/A

Copy link
Contributor

@mackenzie-grimes-noaa mackenzie-grimes-noaa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had never heard of Python ContextVars before. From the docs it looks like it's effectively a dictionary where you can hide variables to sneak them across the scope borders of individual threads. Not sure how Python does it, but if it works it works.

@Geary-Layne Geary-Layne merged commit 134f80a into main Nov 6, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants