summaryrefslogtreecommitdiff
path: root/swift/common/middleware/catch_errors.py
diff options
context:
space:
mode:
authorSamuel Merritt <sam@swiftstack.com>2014-05-16 14:31:08 -0400
committerSamuel Merritt <sam@swiftstack.com>2014-05-16 15:29:47 -0400
commitd8e2043b2f57550570b5bd088b927fc8241b4188 (patch)
tree78701bc415bdcdb612c24d4392baba0601b6aa9b /swift/common/middleware/catch_errors.py
parent04b486e10fce7cf18cf69661ade0314847c2b62d (diff)
downloadswift-d8e2043b2f57550570b5bd088b927fc8241b4188.tar.gz
Let users add their own txid suffixes
The value of the X-Trans-Id-Extra header on the request (if any) will now be appended to the transaction ID. This lets users put their own information into transaction IDs. For example, Glance folks upload images as large objects, so they'd like to be able to tie together all the segment PUTs and the manifest PUT with some operation ID in the logs. This would let them pass in that operation ID as X-Trans-Id-Extra, and then when things went wrong, it'd be much easier to find all the requests in Swift's logs. Also, this aids debuggability when requests fail to receive responses. If a user is sending in their own X-Trans-Id-Extra strings, then that gives operators something to search for in the logs. The normal txid won't work since that's in the response, but the client didn't receive one. Swift will only use the first 32 characters of X-Trans-Id-Extra so that its log lines stay a manageable length. Also, it's URL-quoted so that users cannot inject double quotes into X-Trans-Id-Extra and screw up log parsers. DocImpact Change-Id: I3c51d0c5ac55697ac230001840da219e73a03157
Diffstat (limited to 'swift/common/middleware/catch_errors.py')
-rw-r--r--swift/common/middleware/catch_errors.py7
1 files changed, 6 insertions, 1 deletions
diff --git a/swift/common/middleware/catch_errors.py b/swift/common/middleware/catch_errors.py
index 15c081463..feeca6ea8 100644
--- a/swift/common/middleware/catch_errors.py
+++ b/swift/common/middleware/catch_errors.py
@@ -28,7 +28,12 @@ class CatchErrorsContext(WSGIContext):
self.trans_id_suffix = trans_id_suffix
def handle_request(self, env, start_response):
- trans_id = generate_trans_id(self.trans_id_suffix)
+ trans_id_suffix = self.trans_id_suffix
+ trans_id_extra = env.get('HTTP_X_TRANS_ID_EXTRA')
+ if trans_id_extra:
+ trans_id_suffix += '-' + trans_id_extra[:32]
+
+ trans_id = generate_trans_id(trans_id_suffix)
env['swift.trans_id'] = trans_id
self.logger.txn_id = trans_id
try: