diff --git a/main.py b/main.py
index 87a31fe6c65f3296d8c2ed3990418947b1e1c6c2..9c27cdafa8c8af6a58f661aaa3105c1dfba37329 100644
--- a/main.py
+++ b/main.py
@@ -12,18 +12,22 @@ from opencensus.trace.tracer import Tracer
 from opencensus.ext.flask.flask_middleware import FlaskMiddleware
 from opencensus.trace.samplers import ProbabilitySampler
 
+app = Flask(__name__)
 
-depl_env = os.getenv("DEPLOYMENT_ENVIRONMENT")
-
-if depl_env == 'production' or depl_env == 'staging':
+if os.getenv('GAE_ENV', '').startswith('standard'):
     client = google.cloud.logging.Client()
     handler = CloudLoggingHandler(client)
     setup_logging(handler)
 
 logging.getLogger().setLevel(logging.DEBUG)
 
-app = Flask(__name__)
-app.config.from_pyfile('config/config.py')
+if os.getenv('GAE_ENV', '').startswith('standard'):
+    logging.info("Loading app configuration from file")
+    app.config.from_pyfile('config/config.py')
+
+if not app.secret_key:
+    logging.info("Generating a random secret key")
+    app.secret_key = os.urandom(16)
 
 def main():
     sde = StackdriverExporter(