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


#1

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?


#2

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: https://github.com/getsentry/sentry-python/blob/66ffc91ec27d8ddbee7dc2b96cfcdc5fc9a44bac/sentry_sdk/integrations/wsgi.py#L32-L42

If you want to attach the other environment variables, check https://docs.sentry.io/enriching-error-data/context/?platform=python#extra-context for the new SDK and https://docs.sentry.io/clients/python/usage/#adding-context for raven.


#3

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?


#4

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.


#5

So like this?


#6

yup that should do it