Sentry Doesn't Capture Environment Variables when application started with docker

I noticed that when you view an Issue created from an unhandled exception in Sentry, the issue does not capture all the Environment variables available to the application. My scenario is a python flask application using sentry and running inside a docker container. If I view an issue the only environment variables that show up in the summary are SERVER_NAME and SERVER_PORT. However, I have 5 other Environment variables that the flask app is accessing while processing requests. These are defined in my docker-compose file and are passed to the flask app on environment on start of the container. Why is sentry not able to capture those?

Hi, the SDK (both raven and sentry-sdk) do not capture all environment variables, only some from a whitelist. Capturing all environment variables by default would probably capture more credentials than people would be comfortable with.

Here is the function in sentry-sdk that does this:

If you want to attach the other environment variables, check for the new SDK and for raven.

That makes sense. Is it something that would be acceptable to add to the sdk as an optional parameter to include specific env vars if they are defined? If so I can take a stab at it and submit a PR?

I mean, you can already do that like this (at import time):

with configure_scope() as scope:
    for k in ("FOO_ENV", "BAR_ENV"):
        scope.set_extra(k, os.environ.get(k))

Not sure if it’s worth adding an extra config option upstream.

So like this?

yup that should do it