This is an automated email from the ASF dual-hosted git repository.

zwoop pushed a commit to branch master
in repository https://git-dual.apache.org/repos/asf/trafficserver.git

The following commit(s) were added to refs/heads/master by this push:
       new  a56c5ac   TS-4550 Adds X-Transaction-Id to xdebug
a56c5ac is described below

commit a56c5ac0cf02b26335c533f538459145073743d8
Author: Leif Hedstrom <[email protected]>
AuthorDate: Thu Jun 16 15:29:59 2016 -0600

    TS-4550 Adds X-Transaction-Id to xdebug
    
    This makes a header value that matches the new log tag, %<cruuid>.
---
 doc/admin-guide/plugins/xdebug.en.rst |  4 ++++
 plugins/experimental/xdebug/xdebug.cc | 32 ++++++++++++++++++++++++++++----
 2 files changed, 32 insertions(+), 4 deletions(-)

diff --git a/doc/admin-guide/plugins/xdebug.en.rst 
b/doc/admin-guide/plugins/xdebug.en.rst
index 688b290..e4c1043 100644
--- a/doc/admin-guide/plugins/xdebug.en.rst
+++ b/doc/admin-guide/plugins/xdebug.en.rst
@@ -83,3 +83,7 @@ X-Milestones
     :c:func:`TSHttpTxnMilestoneGet` API. Each milestone value is a
     fractional number of seconds since the beginning of the
     transaction.
+
+X-Transaction-ID
+    A unique transaction ID, which identifies this request / transaction. This
+    matches the log field format that is also available, %<cruuid>.
diff --git a/plugins/experimental/xdebug/xdebug.cc 
b/plugins/experimental/xdebug/xdebug.cc
index fa4ee93..fd9c347 100644
--- a/plugins/experimental/xdebug/xdebug.cc
+++ b/plugins/experimental/xdebug/xdebug.cc
@@ -30,10 +30,13 @@ static struct {
   int len;
 } xDebugHeader = {NULL, 0};
 
-#define XHEADER_X_CACHE_KEY 0x0004u
-#define XHEADER_X_MILESTONES 0x0008u
-#define XHEADER_X_CACHE 0x0010u
-#define XHEADER_X_GENERATION 0x0020u
+enum {
+  XHEADER_X_CACHE_KEY      = 0x0004u,
+  XHEADER_X_MILESTONES     = 0x0008u,
+  XHEADER_X_CACHE          = 0x0010u,
+  XHEADER_X_GENERATION     = 0x0020u,
+  XHEADER_X_TRANSACTION_ID = 0x0040u,
+};
 
 static int XArgIndex             = 0;
 static TSCont XInjectHeadersCont = NULL;
@@ -234,6 +237,21 @@ done:
   }
 }
 
+static void
+InjectTxnUuidHeader(TSHttpTxn txn, TSMBuffer buffer, TSMLoc hdr)
+{
+  TSMLoc dst = FindOrMakeHdrField(buffer, hdr, "X-Transaction-ID", 
lengthof("X-Transaction-ID"));
+
+  if (TS_NULL_MLOC != dst) {
+    char buf[TS_UUID_STRING_LEN + 22]; // Padded for int64_t (20) + 1 ('-') + 
1 ('\0')
+    TSUuid uuid = TSProcessUuidGet();
+    int len     = snprintf(buf, sizeof(buf) - 1, "%s-%" PRIu64 "", 
TSUuidStringGet(uuid), TSHttpTxnIdGet(txn));
+
+    TSReleaseAssert(TSMimeHdrFieldValueStringInsert(buffer, hdr, dst, 0 /* idx 
*/, buf, len) == TS_SUCCESS);
+    TSHandleMLocRelease(buffer, hdr, dst);
+  }
+}
+
 static int
 XInjectResponseHeaders(TSCont /* contp */, TSEvent event, void *edata)
 {
@@ -269,6 +287,10 @@ XInjectResponseHeaders(TSCont /* contp */, TSEvent event, 
void *edata)
     InjectGenerationHeader(txn, buffer, hdr);
   }
 
+  if (xheaders & XHEADER_X_TRANSACTION_ID) {
+    InjectTxnUuidHeader(txn, buffer, hdr);
+  }
+
 done:
   TSHttpTxnReenable(txn, TS_EVENT_HTTP_CONTINUE);
   return TS_EVENT_NONE;
@@ -317,6 +339,8 @@ XScanRequestHeaders(TSCont /* contp */, TSEvent event, void 
*edata)
         xheaders |= XHEADER_X_CACHE;
       } else if (header_field_eq("x-cache-generation", value, vsize)) {
         xheaders |= XHEADER_X_GENERATION;
+      } else if (header_field_eq("x-transaction-id", value, vsize)) {
+        xheaders |= XHEADER_X_TRANSACTION_ID;
       } else if (header_field_eq("via", value, vsize)) {
         // If the client requests the Via header, enable verbose Via debugging 
for this transaction.
         TSHttpTxnConfigIntSet(txn, TS_CONFIG_HTTP_INSERT_RESPONSE_VIA_STR, 3);

-- 
To stop receiving notification emails like this one, please contact
['"[email protected]" <[email protected]>'].

Reply via email to