cknd / stackprinter

Debugging-friendly exceptions for Python
MIT License
1.28k stars 37 forks source link

Add a way to redact some variables #50

Closed Schnouki closed 2 years ago

Schnouki commented 3 years ago

Hey there,

I'm considering using stackprinter at my company to help with some debugging tasks. Its output would be in our logs, and thus be sent to DataDog. But we don't really want to do that unless we have more control over the output.

More specifically: we want to redact some variables based on their name, because they can contain sensitive user data. For instance, content or *_token are replaced by "**" in our current system and in Sentry, and I'd like to do the same with stackprinter.

Is there already a way to do that? If not, what would be a good way to add such a filter?

Thanks!

Mcsavvy commented 3 years ago

You should consider forking this repo.

ale-dd commented 2 years ago

I have the same needs. Certain variables and dictionary fields in my software contain full blown URLs. I already feed them through a function of mine that redact the passwords, but they are now creeping up in these stack traces. @Schnouki what did you end up doing?

cknd commented 2 years ago

Try pip install -U stackprinter: I just pushed the new version 0.2.6 to pypi which brings an option to redact variables, using stackprinter.format(suppressed_vars=[r".*token.*", r".*secret"])) etc

cknd commented 2 years ago

Link to the new docs https://github.com/cknd/stackprinter/pull/51/files#diff-91da0cc91398ea49c7111d1e47ce703e5ae297ed7ff2daf87625dc83a8fd6841

cknd commented 2 years ago

feel free to reopen if it doesn't fully adress the issue!