-
Notifications
You must be signed in to change notification settings - Fork 547
Make the structlog integration for Sentry logs #4417
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
Comments
Hi @sector119, thank you for raising this issue. While we would be open to considering adding a Calling Here is an example of how you can get your import sentry_sdk
import structlog
def main():
sentry_sdk.init(
dsn="your dsn here",
_experiments={
"enable_logs": True,
},
)
structlog.stdlib.recreate_defaults() # Add this call
logger = structlog.get_logger()
logger.info("Hello, world!") # This gets logged in Sentry
if __name__ == "__main__":
main() Does this solution work for you? If yes, please close the issue. If not, please explain why this does not work, and we will use that information to inform our decision on whether to create a dedicated |
Thanks a lot, it works for me, but that is not what I exactly want to get. for example I perform logger.error("Account not found", person_id=person_id, street_id=street_id, building=building, apartment=apartment) with structlog json formatter I get message like this, so I have message and arguments logged separately {"person_id":2036273,"street_id":null,"building":null,"apartment":null,"event":"Account not found","level":"error","logger":"epsilon-xmlrpc","timestamp":"2025-05-27T00:05:19.820515","sentry_id":"f54adb5462254e0fb42111e3d3149452"} I thought that with sentry logging I would get something similar, so I would be able to search by all that args Right now I just have message with all args in the same line ( 2025-05-27 00:01:20 [error ] Account not found [epsilon-xmlrpc] apartment=None building=None person_id=2036273 street_id=None |
Ah okay, I understand now! Basically, you would like us to attach this information as attributes onto the log that we send to Sentry. I believe this is a completely valid request and should be possible for us to implement, so I will add this to our backlog as a feature request. |
Yes, as attributes, hints or something similar that we can search by Thank you |
Uh oh!
There was an error while loading. Please reload this page.
Problem Statement
structlog
logs can be sent to Sentry via the existingLoggingIntegration
; however, this does not preserve the structuring of the logs (e.g. if the logs have custom attributes set, these are included in the log message). See this exampleSolution Brainstorm
Instead, create a dedicated
structlog
integration, which would add these logs to the log event as custom attributes.The text was updated successfully, but these errors were encountered: