Skip to content
This repository has been archived by the owner on Mar 24, 2021. It is now read-only.

Commit

Permalink
Merge pull request #357 from alphagov/feature/log-request-id
Browse files Browse the repository at this point in the history
Log Request-Id
  • Loading branch information
robyoung committed Sep 9, 2014
2 parents b0993f2 + 7a9b538 commit b1eebc0
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
10 changes: 8 additions & 2 deletions backdrop/core/log_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ def set_up_logging(app, env):

def create_request_logger(app):
def log_request():
app.logger.info("request: %s - %s" % (request.method, request.url))
app.logger.info("request: %s - %s" % (request.method, request.url),
extra=create_logging_extra_dict())
return log_request


Expand All @@ -50,7 +51,12 @@ def log_response(response):
app.logger.info(
"response: %s - %s - %s" % (
request.method, request.url, response.status
)
),
extra=create_logging_extra_dict()
)
return response
return log_response


def create_logging_extra_dict():
return { 'request_id': request.headers.get('Request-Id')}
6 changes: 6 additions & 0 deletions backdrop/read/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,16 @@
app.config['MONGO_PORT'],
app.config['DATABASE_NAME'])


def generate_request_id():
return request.headers.get('Request-Id')


admin_api = client.AdminAPI(
app.config['STAGECRAFT_URL'],
app.config['SIGNON_API_USER_TOKEN'],
dry_run=False,
request_id_fn = generate_request_id,
)

DEFAULT_DATA_SET_QUERYABLE = True
Expand Down
6 changes: 6 additions & 0 deletions backdrop/write/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,16 @@
app.config['MONGO_PORT'],
app.config['DATABASE_NAME'])


def generate_request_id():
return request.headers.get('Request-Id')


admin_api = client.AdminAPI(
app.config['STAGECRAFT_URL'],
app.config['SIGNON_API_USER_TOKEN'],
dry_run=False,
request_id_fn = generate_request_id,
)

log_handler.set_up_logging(app, GOVUK_ENV)
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ gunicorn==19.1.1
invoke
isodate==0.5.0
jsonschema==2.4
performanceplatform-client==0.0.8
performanceplatform-client==0.0.9
pip==1.5.6
pymongo==2.7.2
python-dateutil==2.2
Expand Down

0 comments on commit b1eebc0

Please sign in to comment.