Skip to content
This repository has been archived by the owner on Jul 25, 2018. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
Add New Relic support to WSGI file.
  • Loading branch information
Michael Kelly committed Apr 10, 2013
1 parent ad69c9e commit c1ee702
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions wsgi/index.wsgi
Expand Up @@ -3,6 +3,20 @@ import site
import sys
from datetime import datetime

try:
import newrelic.agent
except ImportError:
newrelic = False


# If New Relic was imported successfully, load the configuration.
if newrelic:
newrelic_ini = os.getenv('NEWRELIC_PYTHON_INI_FILE', False)
if newrelic_ini:
newrelic.agent.initialize(newrelic_ini)
else:
newrelic = False

# fix markdown.py (and potentially others) using stdout
sys.stdout = sys.stderr

Expand Down Expand Up @@ -30,14 +44,11 @@ command.validate()
# This is what mod_wsgi runs.
django_app = django.core.handlers.wsgi.WSGIHandler()


def application(env, start_response):
env['wsgi.loaded'] = wsgi_loaded
return django_app(env, start_response)

# Uncomment this to figure out what's going on with the mod_wsgi environment.
# def application(env, start_response):
# start_response('200 OK', [('Content-Type', 'text/plain')])
# return '\n'.join('%r: %r' % item for item in sorted(env.items()))

# vim: ft=python

# Wrap the WSGI application with New Relic if we're able to.
if newrelic:
application = newrelic.agent.wsgi_application()(application)

0 comments on commit c1ee702

Please sign in to comment.