You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Let EventRenamer defaults to None in case event key is missing.
Long one (more context)
I'm new to python development in general. I am adding structlog to my uvicorn app, so that the logs are parseable by the logs processor. My current orgs setup expect message key, hence I am using EventRenamer. But when my logger get passed None or [] (empty array), it will break the logger.
Other considerations and questions:
Maybe let None be passed as event?
In the _base.py_process_event, there's this if-clause.
I haven't done anything more than just this small change. I would like to validate my understanding first.
Do not open pull requests from your main branch – use a separate branch!
There's a ton of footguns waiting if you don't heed this warning. You can still go back to your project, create a branch from your main branch, push it, and open the pull request from the new branch.
This is not a pre-requisite for your pull request to be accepted, but you have been warned.
New functions/classes have to be added to docs/api.rst by hand.
Changed/added classes/methods/functions have appropriate versionadded, versionchanged, or deprecateddirectives.
The next version is the second number in the current release + 1. The first number represents the current year. So if the current version on PyPI is 23.1.0, the next version is gonna be 23.2.0. If the next version is the first in the new year, it'll be 24.1.0.
Documentation in .rst and .md files is written using semantic newlines.
Changes (and possible deprecations) are documented in the changelog.
Hi Ben, sorry for not getting back to you earlier.
Summary
Let EventRenamer defaults to None in case event key is missing.
Long one (more context)
I'm new to python development in general. I am adding structlog to my uvicorn app, so that the logs are parseable by the logs processor. My current orgs setup expect message key, hence I am using EventRenamer. But when my logger get passed None or [] (empty array), it will break the logger.
What kind of configuration are you using exactly? IIUC, you're violating the typing contract of the log methods that all require event to be a string?
I'm somewhat sure that you're doing something you shouldn't based on some misunderstanding so it would be better to sort that out first.
Other considerations and questions:
Maybe let None be passed as event?
In the _base.py_process_event, there's this if-clause.
ifeventisnotNone:
event_dict["event"] =event
I wonder why do this?
I think this is from the olden days with a more dynamic logger implementation where event was in fact optional. Although I'm looking at stdlib and it looks like the type hints there are still str | None. 🙈
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Let
EventRenamerdefaults toNonein caseeventkey is missing.Long one (more context)
I'm new to python development in general. I am adding
structlogto myuvicornapp, so that the logs are parseable by the logs processor. My current orgs setup expectmessagekey, hence I am usingEventRenamer. But when my logger get passedNoneor[](empty array), it will break the logger.Other considerations and questions:
Maybe let
Nonebe passed asevent?In the
_base.py_process_event, there's this if-clause.I wonder why do this?
Other approach
I've added new custom processors like this:
Pull Request Check List
I haven't done anything more than just this small change. I would like to validate my understanding first.
mainbranch – use a separate branch!api.py.docs/api.rstby hand.versionadded,versionchanged, ordeprecateddirectives..rstand.mdfiles is written using semantic newlines.