You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@htrace.apache.org by cm...@apache.org on 2015/07/30 20:25:07 UTC

[1/2] incubator-htrace git commit: HTRACE-217. Rename ProcessId to TracerId (cmccabe)

Repository: incubator-htrace
Updated Branches:
  refs/heads/master 98aecf878 -> 959a6ef03


http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/959a6ef0/htrace-core/src/test/java/org/apache/htrace/impl/TestProcessId.java
----------------------------------------------------------------------
diff --git a/htrace-core/src/test/java/org/apache/htrace/impl/TestProcessId.java b/htrace-core/src/test/java/org/apache/htrace/impl/TestProcessId.java
deleted file mode 100644
index 9e5f6b9..0000000
--- a/htrace-core/src/test/java/org/apache/htrace/impl/TestProcessId.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.htrace.impl;
-
-import java.io.IOException;
-import org.junit.Test;
-import static org.junit.Assert.assertEquals;
-
-public class TestProcessId {
-  private void testProcessIdImpl(String expected, String fmt) {
-    assertEquals(expected, new ProcessId(fmt).get());
-  }
-
-  @Test
-  public void testSimpleProcessIds() {
-    testProcessIdImpl("abc", "abc");
-    testProcessIdImpl("abc", "a\\bc");
-    testProcessIdImpl("abc", "ab\\c");
-    testProcessIdImpl("abc", "\\a\\b\\c");
-    testProcessIdImpl("a\\bc", "a\\\\bc");
-  }
-
-  @Test
-  public void testSubstitutionVariables() throws IOException {
-    testProcessIdImpl(ProcessId.getProcessName(), "${pname}");
-    testProcessIdImpl("my." + ProcessId.getProcessName(), "my.${pname}");
-    testProcessIdImpl(ProcessId.getBestIpString() + ".str", "${ip}.str");
-    testProcessIdImpl("${pname}", "\\${pname}");
-    testProcessIdImpl("$cash$money{}", "$cash$money{}");
-    testProcessIdImpl("Foo." + Long.valueOf(ProcessId.getOsPid()).toString(),
-        "Foo.${pid}");
-  }
-}

http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/959a6ef0/htrace-core/src/test/java/org/apache/htrace/impl/TestTracerId.java
----------------------------------------------------------------------
diff --git a/htrace-core/src/test/java/org/apache/htrace/impl/TestTracerId.java b/htrace-core/src/test/java/org/apache/htrace/impl/TestTracerId.java
new file mode 100644
index 0000000..271d082
--- /dev/null
+++ b/htrace-core/src/test/java/org/apache/htrace/impl/TestTracerId.java
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.htrace.impl;
+
+import java.io.IOException;
+import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+
+public class TestTracerId {
+  private void testTracerIdImpl(String expected, String fmt) {
+    assertEquals(expected, new TracerId(fmt).get());
+  }
+
+  @Test
+  public void testSimpleTracerIds() {
+    testTracerIdImpl("abc", "abc");
+    testTracerIdImpl("abc", "a\\bc");
+    testTracerIdImpl("abc", "ab\\c");
+    testTracerIdImpl("abc", "\\a\\b\\c");
+    testTracerIdImpl("a\\bc", "a\\\\bc");
+  }
+
+  @Test
+  public void testSubstitutionVariables() throws IOException {
+    testTracerIdImpl(TracerId.getProcessName(), "${pname}");
+    testTracerIdImpl("my." + TracerId.getProcessName(), "my.${pname}");
+    testTracerIdImpl(TracerId.getBestIpString() + ".str", "${ip}.str");
+    testTracerIdImpl("${pname}", "\\${pname}");
+    testTracerIdImpl("$cash$money{}", "$cash$money{}");
+    testTracerIdImpl("Foo." + Long.valueOf(TracerId.getOsPid()).toString(),
+        "Foo.${pid}");
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/959a6ef0/htrace-flume/src/main/java/org/apache/htrace/impl/FlumeSpanReceiver.java
----------------------------------------------------------------------
diff --git a/htrace-flume/src/main/java/org/apache/htrace/impl/FlumeSpanReceiver.java b/htrace-flume/src/main/java/org/apache/htrace/impl/FlumeSpanReceiver.java
index baa4fa1..a1352ab 100644
--- a/htrace-flume/src/main/java/org/apache/htrace/impl/FlumeSpanReceiver.java
+++ b/htrace-flume/src/main/java/org/apache/htrace/impl/FlumeSpanReceiver.java
@@ -89,12 +89,12 @@ public class FlumeSpanReceiver implements SpanReceiver {
   private int maxSpanBatchSize;
   private String flumeHostName;
   private int flumePort;
-  private final ProcessId processId;
+  private final TracerId tracerId;
 
   public FlumeSpanReceiver(HTraceConfiguration conf) {
     this.queue = new ArrayBlockingQueue<Span>(1000);
     this.tf = new SimpleThreadFactory();
-    this.processId = new ProcessId(conf);
+    this.tracerId = new TracerId(conf);
     configure(conf);
   }
 
@@ -175,7 +175,7 @@ public class FlumeSpanReceiver implements SpanReceiver {
             Map<String, String> headers = new HashMap<String, String>();
             headers.put("TraceId",      Long.toString(span.getTraceId()));
             headers.put("SpanId",       Long.toString(span.getSpanId()));
-            headers.put("ProcessId",    span.getProcessId());
+            headers.put("TracerId",    span.getTracerId());
             headers.put("Description",  span.getDescription());
 
             String body = span.toJson();
@@ -274,8 +274,8 @@ public class FlumeSpanReceiver implements SpanReceiver {
   public void receiveSpan(Span span) {
     if (running.get()) {
       try {
-        if (span.getProcessId().isEmpty()) {
-          span.setProcessId(processId.get());
+        if (span.getTracerId().isEmpty()) {
+          span.setTracerId(tracerId.get());
         }
         this.queue.add(span);
       } catch (IllegalStateException e) {

http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/959a6ef0/htrace-flume/src/test/java/org/apache/htrace/impl/TestFlumeSpanReceiver.java
----------------------------------------------------------------------
diff --git a/htrace-flume/src/test/java/org/apache/htrace/impl/TestFlumeSpanReceiver.java b/htrace-flume/src/test/java/org/apache/htrace/impl/TestFlumeSpanReceiver.java
index b7f8863..6743c85 100644
--- a/htrace-flume/src/test/java/org/apache/htrace/impl/TestFlumeSpanReceiver.java
+++ b/htrace-flume/src/test/java/org/apache/htrace/impl/TestFlumeSpanReceiver.java
@@ -44,7 +44,7 @@ public class TestFlumeSpanReceiver {
         description("root").
         traceId(1).
         spanId(100).
-        processId("test").
+        tracerId("test").
         begin(System.currentTimeMillis()).
         build();
     Span innerOne = rootSpan.child("Some good work");

http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/959a6ef0/htrace-hbase/src/main/java/org/apache/htrace/impl/HBaseSpanReceiver.java
----------------------------------------------------------------------
diff --git a/htrace-hbase/src/main/java/org/apache/htrace/impl/HBaseSpanReceiver.java b/htrace-hbase/src/main/java/org/apache/htrace/impl/HBaseSpanReceiver.java
index 2faf4bb..beb96b5 100644
--- a/htrace-hbase/src/main/java/org/apache/htrace/impl/HBaseSpanReceiver.java
+++ b/htrace-hbase/src/main/java/org/apache/htrace/impl/HBaseSpanReceiver.java
@@ -126,7 +126,7 @@ public class HBaseSpanReceiver implements SpanReceiver {
   private final byte[] cf;
   private final byte[] icf;
   private final int maxSpanBatchSize;
-  private final ProcessId processId;
+  private final TracerId tracerId;
 
   public HBaseSpanReceiver(HTraceConfiguration conf) {
     this.queue = new ArrayBlockingQueue<Span>(1000);
@@ -154,7 +154,7 @@ public class HBaseSpanReceiver implements SpanReceiver {
     for (int i = 0; i < numThreads; i++) {
       this.service.submit(new WriteSpanRunnable());
     }
-    this.processId = new ProcessId(conf);
+    this.tracerId = new TracerId(conf);
   }
 
   private class WriteSpanRunnable implements Runnable {
@@ -212,7 +212,7 @@ public class HBaseSpanReceiver implements SpanReceiver {
                     .setStart(span.getStartTimeMillis())
                     .setStop(span.getStopTimeMillis())
                     .setSpanId(span.getSpanId())
-                    .setProcessId(span.getProcessId())
+                    .setProcessId(span.getTracerId())
                     .setDescription(span.getDescription());
 
             if (span.getParents().length == 0) {
@@ -333,8 +333,8 @@ public class HBaseSpanReceiver implements SpanReceiver {
   public void receiveSpan(Span span) {
     if (running.get()) {
       try {
-        if (span.getProcessId().isEmpty()) {
-          span.setProcessId(processId.get());
+        if (span.getTracerId().isEmpty()) {
+          span.setTracerId(tracerId.get());
         }
         this.queue.add(span);
       } catch (IllegalStateException e) {

http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/959a6ef0/htrace-hbase/src/test/java/org/apache/htrace/impl/TestHBaseSpanReceiver.java
----------------------------------------------------------------------
diff --git a/htrace-hbase/src/test/java/org/apache/htrace/impl/TestHBaseSpanReceiver.java b/htrace-hbase/src/test/java/org/apache/htrace/impl/TestHBaseSpanReceiver.java
index 0f8eaf5..5027891 100644
--- a/htrace-hbase/src/test/java/org/apache/htrace/impl/TestHBaseSpanReceiver.java
+++ b/htrace-hbase/src/test/java/org/apache/htrace/impl/TestHBaseSpanReceiver.java
@@ -176,12 +176,12 @@ public class TestHBaseSpanReceiver {
     }
 
     @Override
-    public String getProcessId() {
+    public String getTracerId() {
       return span.getProcessId();
     }
 
     @Override
-    public void setProcessId(String processId) {
+    public void setTracerId(String tracerId) {
       throw new UnsupportedOperationException();
     }
 
@@ -192,9 +192,9 @@ public class TestHBaseSpanReceiver {
 
     @Override
     public String toString() {
-      return String.format("Span{Id:0x%16x,parentId:0x%16x,pid:%s,desc:%s}",
+      return String.format("Span{Id:0x%16x,parentId:0x%16x,trid:%s,desc:%s}",
                            getSpanId(), span.getParentId(),
-                           getProcessId(), getDescription());
+                           getTracerId(), getDescription());
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/959a6ef0/htrace-htraced/go/src/org/apache/htrace/client/client.go
----------------------------------------------------------------------
diff --git a/htrace-htraced/go/src/org/apache/htrace/client/client.go b/htrace-htraced/go/src/org/apache/htrace/client/client.go
index 6a62e81..ef827e8 100644
--- a/htrace-htraced/go/src/org/apache/htrace/client/client.go
+++ b/htrace-htraced/go/src/org/apache/htrace/client/client.go
@@ -120,8 +120,8 @@ func (hcl *Client) writeSpansHttp(req *common.WriteSpansReq) error {
 		}
 	}
 	customHeaders := make(map[string]string)
-	if req.DefaultPid != "" {
-		customHeaders["htrace-pid"] = req.DefaultPid
+	if req.DefaultTrid != "" {
+		customHeaders["htrace-trid"] = req.DefaultTrid
 	}
 	_, _, err = hcl.makeRestRequest("POST", "writeSpans",
 		&w, customHeaders)

http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/959a6ef0/htrace-htraced/go/src/org/apache/htrace/common/query.go
----------------------------------------------------------------------
diff --git a/htrace-htraced/go/src/org/apache/htrace/common/query.go b/htrace-htraced/go/src/org/apache/htrace/common/query.go
index aae034c..7a9e523 100644
--- a/htrace-htraced/go/src/org/apache/htrace/common/query.go
+++ b/htrace-htraced/go/src/org/apache/htrace/common/query.go
@@ -81,7 +81,7 @@ const (
 	BEGIN_TIME  Field = "begin"
 	END_TIME    Field = "end"
 	DURATION    Field = "duration"
-	PROCESS_ID  Field = "processid"
+	TRACER_ID   Field = "tracerid"
 )
 
 func (field Field) IsValid() bool {
@@ -96,7 +96,7 @@ func (field Field) IsValid() bool {
 
 func ValidFields() []Field {
 	return []Field{SPAN_ID, DESCRIPTION, BEGIN_TIME, END_TIME,
-		DURATION, PROCESS_ID}
+		DURATION, TRACER_ID}
 }
 
 type Predicate struct {

http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/959a6ef0/htrace-htraced/go/src/org/apache/htrace/common/rpc.go
----------------------------------------------------------------------
diff --git a/htrace-htraced/go/src/org/apache/htrace/common/rpc.go b/htrace-htraced/go/src/org/apache/htrace/common/rpc.go
index fe50a44..28521a5 100644
--- a/htrace-htraced/go/src/org/apache/htrace/common/rpc.go
+++ b/htrace-htraced/go/src/org/apache/htrace/common/rpc.go
@@ -38,8 +38,8 @@ const MAX_HRPC_BODY_LENGTH = 64 * 1024 * 1024
 
 // A request to write spans to htraced.
 type WriteSpansReq struct {
-	DefaultPid string
-	Spans      []*Span
+	DefaultTrid string
+	Spans       []*Span
 }
 
 // A response to a WriteSpansReq

http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/959a6ef0/htrace-htraced/go/src/org/apache/htrace/common/span.go
----------------------------------------------------------------------
diff --git a/htrace-htraced/go/src/org/apache/htrace/common/span.go b/htrace-htraced/go/src/org/apache/htrace/common/span.go
index b276844..720c4cd 100644
--- a/htrace-htraced/go/src/org/apache/htrace/common/span.go
+++ b/htrace-htraced/go/src/org/apache/htrace/common/span.go
@@ -113,7 +113,7 @@ type SpanData struct {
 	TraceId             SpanId               `json:"i"`
 	Parents             []SpanId             `json:"p"`
 	Info                TraceInfoMap         `json:"n,omitempty"`
-	ProcessId           string               `json:"r"`
+	TracerId            string               `json:"r"`
 	TimelineAnnotations []TimelineAnnotation `json:"t,omitempty"`
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/959a6ef0/htrace-htraced/go/src/org/apache/htrace/common/span_test.go
----------------------------------------------------------------------
diff --git a/htrace-htraced/go/src/org/apache/htrace/common/span_test.go b/htrace-htraced/go/src/org/apache/htrace/common/span_test.go
index f218b3a..e3b44fe 100644
--- a/htrace-htraced/go/src/org/apache/htrace/common/span_test.go
+++ b/htrace-htraced/go/src/org/apache/htrace/common/span_test.go
@@ -32,10 +32,10 @@ func TestSpanToJson(t *testing.T) {
 			Description: "getFileDescriptors",
 			TraceId:     999,
 			Parents:     []SpanId{},
-			ProcessId:   "testProcessId",
+			TracerId:    "testTracerId",
 		}}
 	ExpectStrEqual(t,
-		`{"s":"2000000000000000","b":123,"e":456,"d":"getFileDescriptors","i":"00000000000003e7","p":[],"r":"testProcessId"}`,
+		`{"s":"2000000000000000","b":123,"e":456,"d":"getFileDescriptors","i":"00000000000003e7","p":[],"r":"testTracerId"}`,
 		string(span.ToJson()))
 }
 
@@ -48,7 +48,7 @@ func TestAnnotatedSpanToJson(t *testing.T) {
 			Description: "getFileDescriptors2",
 			TraceId:     999,
 			Parents:     []SpanId{},
-			ProcessId:   "testAnnotatedProcessId",
+			TracerId:    "testAnnotatedTracerId",
 			TimelineAnnotations: []TimelineAnnotation{
 				TimelineAnnotation{
 					Time: 7777,
@@ -61,6 +61,6 @@ func TestAnnotatedSpanToJson(t *testing.T) {
 			},
 		}}
 	ExpectStrEqual(t,
-		`{"s":"121f2e036d442000","b":1234,"e":4567,"d":"getFileDescriptors2","i":"00000000000003e7","p":[],"r":"testAnnotatedProcessId","t":[{"t":7777,"m":"contactedServer"},{"t":8888,"m":"passedFd"}]}`,
+		`{"s":"121f2e036d442000","b":1234,"e":4567,"d":"getFileDescriptors2","i":"00000000000003e7","p":[],"r":"testAnnotatedTracerId","t":[{"t":7777,"m":"contactedServer"},{"t":8888,"m":"passedFd"}]}`,
 		string(span.ToJson()))
 }

http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/959a6ef0/htrace-htraced/go/src/org/apache/htrace/htrace/file_test.go
----------------------------------------------------------------------
diff --git a/htrace-htraced/go/src/org/apache/htrace/htrace/file_test.go b/htrace-htraced/go/src/org/apache/htrace/htrace/file_test.go
index b6f9cac..6fd6789 100644
--- a/htrace-htraced/go/src/org/apache/htrace/htrace/file_test.go
+++ b/htrace-htraced/go/src/org/apache/htrace/htrace/file_test.go
@@ -135,7 +135,7 @@ func TestReadSpans(t *testing.T) {
 				Begin:       1424736225037,
 				End:         1424736225901,
 				Description: "ClientNamenodeProtocol#getFileInfo",
-				ProcessId:   "FsShell",
+				TracerId:    "FsShell",
 				Parents:     []common.SpanId{test.SpanId("60538dfb4df91418")},
 			},
 		},
@@ -146,7 +146,7 @@ func TestReadSpans(t *testing.T) {
 				Begin:       1424736224969,
 				End:         1424736225960,
 				Description: "getFileInfo",
-				ProcessId:   "FsShell",
+				TracerId:    "FsShell",
 				Parents:     []common.SpanId{},
 				Info: common.TraceInfoMap{
 					"path": "/",

http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/959a6ef0/htrace-htraced/go/src/org/apache/htrace/htrace/graph_test.go
----------------------------------------------------------------------
diff --git a/htrace-htraced/go/src/org/apache/htrace/htrace/graph_test.go b/htrace-htraced/go/src/org/apache/htrace/htrace/graph_test.go
index 8698a98..e614cec 100644
--- a/htrace-htraced/go/src/org/apache/htrace/htrace/graph_test.go
+++ b/htrace-htraced/go/src/org/apache/htrace/htrace/graph_test.go
@@ -35,7 +35,7 @@ func TestSpansToDot(t *testing.T) {
 				Begin:       1424813349020,
 				End:         1424813349134,
 				Description: "newDFSInputStream",
-				ProcessId:   "FsShell",
+				TracerId:    "FsShell",
 				Parents:     []common.SpanId{},
 				Info: common.TraceInfoMap{
 					"path": "/",
@@ -49,7 +49,7 @@ func TestSpansToDot(t *testing.T) {
 				Begin:       1424813349025,
 				End:         1424813349133,
 				Description: "getBlockLocations",
-				ProcessId:   "FsShell",
+				TracerId:    "FsShell",
 				Parents:     []common.SpanId{test.SpanId("6af3cc058e5d829d")},
 			},
 		},
@@ -60,7 +60,7 @@ func TestSpansToDot(t *testing.T) {
 				Begin:       1424813349027,
 				End:         1424813349073,
 				Description: "ClientNamenodeProtocol#getBlockLocations",
-				ProcessId:   "FsShell",
+				TracerId:    "FsShell",
 				Parents:     []common.SpanId{test.SpanId("75d16cc5b2c07d8a")},
 			},
 		},

http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/959a6ef0/htrace-htraced/go/src/org/apache/htrace/htraced/datastore.go
----------------------------------------------------------------------
diff --git a/htrace-htraced/go/src/org/apache/htrace/htraced/datastore.go b/htrace-htraced/go/src/org/apache/htrace/htraced/datastore.go
index 35c7dad..48f02aa 100644
--- a/htrace-htraced/go/src/org/apache/htrace/htraced/datastore.go
+++ b/htrace-htraced/go/src/org/apache/htrace/htraced/datastore.go
@@ -573,8 +573,8 @@ func loadPredicateData(pred *common.Predicate) (*predicateData, error) {
 		}
 		p.uintKey = s2u64(v)
 		break
-	case common.PROCESS_ID:
-		// Any string is valid for a process ID.
+	case common.TRACER_ID:
+		// Any string is valid for a tracer ID.
 		p.strKey = pred.Val
 		break
 	default:
@@ -638,8 +638,8 @@ func (pred *predicateData) extractRelevantSpanData(span *common.Span) (uint64, s
 		return s2u64(span.End), ""
 	case common.DURATION:
 		return s2u64(span.Duration()), ""
-	case common.PROCESS_ID:
-		return 0, span.ProcessId
+	case common.TRACER_ID:
+		return 0, span.TracerId
 	default:
 		panic(fmt.Sprintf("Field type %s isn't a 64-bit integer.", pred.Field))
 	}

http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/959a6ef0/htrace-htraced/go/src/org/apache/htrace/htraced/datastore_test.go
----------------------------------------------------------------------
diff --git a/htrace-htraced/go/src/org/apache/htrace/htraced/datastore_test.go b/htrace-htraced/go/src/org/apache/htrace/htraced/datastore_test.go
index 4696547..0c122fd 100644
--- a/htrace-htraced/go/src/org/apache/htrace/htraced/datastore_test.go
+++ b/htrace-htraced/go/src/org/apache/htrace/htraced/datastore_test.go
@@ -52,7 +52,7 @@ var SIMPLE_TEST_SPANS []common.Span = []common.Span{
 			Description: "getFileDescriptors",
 			TraceId:     999,
 			Parents:     []common.SpanId{},
-			ProcessId:   "firstd",
+			TracerId:    "firstd",
 		}},
 	common.Span{Id: 2,
 		SpanData: common.SpanData{
@@ -61,7 +61,7 @@ var SIMPLE_TEST_SPANS []common.Span = []common.Span{
 			Description: "openFd",
 			TraceId:     999,
 			Parents:     []common.SpanId{1},
-			ProcessId:   "secondd",
+			TracerId:    "secondd",
 		}},
 	common.Span{Id: 3,
 		SpanData: common.SpanData{
@@ -70,7 +70,7 @@ var SIMPLE_TEST_SPANS []common.Span = []common.Span{
 			Description: "passFd",
 			TraceId:     999,
 			Parents:     []common.SpanId{1},
-			ProcessId:   "thirdd",
+			TracerId:    "thirdd",
 		}},
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/959a6ef0/htrace-htraced/go/src/org/apache/htrace/htraced/hrpc.go
----------------------------------------------------------------------
diff --git a/htrace-htraced/go/src/org/apache/htrace/htraced/hrpc.go b/htrace-htraced/go/src/org/apache/htrace/htraced/hrpc.go
index a53380e..71b9625 100644
--- a/htrace-htraced/go/src/org/apache/htrace/htraced/hrpc.go
+++ b/htrace-htraced/go/src/org/apache/htrace/htraced/hrpc.go
@@ -190,11 +190,11 @@ func (cdc *HrpcServerCodec) Close() error {
 func (hand *HrpcHandler) WriteSpans(req *common.WriteSpansReq,
 	resp *common.WriteSpansResp) (err error) {
 	hand.lg.Debugf("hrpc writeSpansHandler: received %d span(s).  "+
-		"defaultPid = %s\n", len(req.Spans), req.DefaultPid)
+		"defaultTrid = %s\n", len(req.Spans), req.DefaultTrid)
 	for i := range req.Spans {
 		span := req.Spans[i]
-		if span.ProcessId == "" {
-			span.ProcessId = req.DefaultPid
+		if span.TracerId == "" {
+			span.TracerId = req.DefaultTrid
 		}
 		if hand.lg.TraceEnabled() {
 			hand.lg.Tracef("writing span %d: %s\n", i, span.ToJson())

http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/959a6ef0/htrace-htraced/go/src/org/apache/htrace/htraced/rest.go
----------------------------------------------------------------------
diff --git a/htrace-htraced/go/src/org/apache/htrace/htraced/rest.go b/htrace-htraced/go/src/org/apache/htrace/htraced/rest.go
index ee62642..cd90038 100644
--- a/htrace-htraced/go/src/org/apache/htrace/htraced/rest.go
+++ b/htrace-htraced/go/src/org/apache/htrace/htraced/rest.go
@@ -162,7 +162,7 @@ func (hand *writeSpansHandler) ServeHTTP(w http.ResponseWriter, req *http.Reques
 	setResponseHeaders(w.Header())
 	dec := json.NewDecoder(req.Body)
 	spans := make([]*common.Span, 0, 32)
-	defaultPid := req.Header.Get("htrace-pid")
+	defaultTrid := req.Header.Get("htrace-trid")
 	for {
 		var span common.Span
 		err := dec.Decode(&span)
@@ -174,13 +174,13 @@ func (hand *writeSpansHandler) ServeHTTP(w http.ResponseWriter, req *http.Reques
 			}
 			break
 		}
-		if span.ProcessId == "" {
-			span.ProcessId = defaultPid
+		if span.TracerId == "" {
+			span.TracerId = defaultTrid
 		}
 		spans = append(spans, &span)
 	}
-	hand.lg.Debugf("writeSpansHandler: received %d span(s).  defaultPid = %s\n",
-		len(spans), defaultPid)
+	hand.lg.Debugf("writeSpansHandler: received %d span(s).  defaultTrid = %s\n",
+		len(spans), defaultTrid)
 	for spanIdx := range spans {
 		if hand.lg.DebugEnabled() {
 			hand.lg.Debugf("writing span %s\n", spans[spanIdx].ToJson())

http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/959a6ef0/htrace-htraced/go/src/org/apache/htrace/test/random.go
----------------------------------------------------------------------
diff --git a/htrace-htraced/go/src/org/apache/htrace/test/random.go b/htrace-htraced/go/src/org/apache/htrace/test/random.go
index d10e2f9..96a3e8b 100644
--- a/htrace-htraced/go/src/org/apache/htrace/test/random.go
+++ b/htrace-htraced/go/src/org/apache/htrace/test/random.go
@@ -67,6 +67,6 @@ func NewRandomSpan(rnd *rand.Rand, potentialParents []*common.Span) *common.Span
 			Description: "getFileDescriptors",
 			TraceId:     common.SpanId(NonZeroRand64(rnd)),
 			Parents:     parents,
-			ProcessId:   fmt.Sprintf("process%d", NonZeroRand32(rnd)),
+			TracerId:    fmt.Sprintf("tracer%d", NonZeroRand32(rnd)),
 		}}
 }

http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/959a6ef0/htrace-htraced/src/main/java/org/apache/htrace/impl/HTracedRESTReceiver.java
----------------------------------------------------------------------
diff --git a/htrace-htraced/src/main/java/org/apache/htrace/impl/HTracedRESTReceiver.java b/htrace-htraced/src/main/java/org/apache/htrace/impl/HTracedRESTReceiver.java
index 5a4daaf..bd8764b 100644
--- a/htrace-htraced/src/main/java/org/apache/htrace/impl/HTracedRESTReceiver.java
+++ b/htrace-htraced/src/main/java/org/apache/htrace/impl/HTracedRESTReceiver.java
@@ -172,7 +172,7 @@ public class HTracedRESTReceiver implements SpanReceiver {
   /**
    * The process ID to use for all spans.
    */
-  private final ProcessId processId;
+  private final TracerId tracerId;
 
   /**
    * Create an HttpClient instance.
@@ -226,7 +226,7 @@ public class HTracedRESTReceiver implements SpanReceiver {
             capacity + ", url=" + url +  ", periodInMs=" + periodInMs +
             ", maxToSendAtATime=" + maxToSendAtATime);
     }
-    processId = new ProcessId(conf);
+    tracerId = new TracerId(conf);
   }
 
   /**
@@ -322,7 +322,7 @@ public class HTracedRESTReceiver implements SpanReceiver {
       try {
         Request request = httpClient.newRequest(url).method(HttpMethod.POST);
         request.header(HttpHeader.CONTENT_TYPE, "application/json");
-        request.header("htrace-pid", processId.get());
+        request.header("htrace-trid", tracerId.get());
         StringBuilder bld = new StringBuilder();
         for (Span span : spanBuf) {
           bld.append(span.toJson());

http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/959a6ef0/htrace-htraced/src/test/java/org/apache/htrace/impl/TestHTracedRESTReceiver.java
----------------------------------------------------------------------
diff --git a/htrace-htraced/src/test/java/org/apache/htrace/impl/TestHTracedRESTReceiver.java b/htrace-htraced/src/test/java/org/apache/htrace/impl/TestHTracedRESTReceiver.java
index a6faa02..35d1f09 100644
--- a/htrace-htraced/src/test/java/org/apache/htrace/impl/TestHTracedRESTReceiver.java
+++ b/htrace-htraced/src/test/java/org/apache/htrace/impl/TestHTracedRESTReceiver.java
@@ -65,7 +65,7 @@ public class TestHTracedRESTReceiver {
    */
   private final class TestHTraceConfiguration extends HTraceConfiguration {
     private final URL restServerUrl;
-    final static String PROCESS_ID = "TestHTracedRESTReceiver";
+    final static String TRACER_ID = "TestHTracedRESTReceiver";
 
     public TestHTraceConfiguration(final URL restServerUrl) {
       this.restServerUrl = restServerUrl;
@@ -80,8 +80,8 @@ public class TestHTracedRESTReceiver {
     public String get(String key, String defaultValue) {
       if (key.equals(HTracedRESTReceiver.HTRACED_REST_URL_KEY)) {
         return this.restServerUrl.toString();
-      } else if (key.equals(ProcessId.PROCESS_ID_KEY)) {
-        return PROCESS_ID;
+      } else if (key.equals(TracerId.TRACER_ID_KEY)) {
+        return TRACER_ID;
       }
       return defaultValue;
     }
@@ -129,7 +129,7 @@ public class TestHTracedRESTReceiver {
           parents(new long[]{1L}).
           spanId(i);
       if (i == NUM_SPANS - 1) {
-        builder.processId("specialPid");
+        builder.tracerId("specialTrid");
       }
       spans[i] = builder.build();
     }
@@ -161,14 +161,14 @@ public class TestHTracedRESTReceiver {
               LOG.info("Got " + content + " for span " + i);
               MilliSpan dspan = MilliSpan.fromJson(content);
               assertEquals((long)i, dspan.getSpanId());
-              // Every span should have the process ID we set in the
+              // Every span should have the tracer ID we set in the
               // configuration... except for the last span, which had
               // a custom value set.
               if (i == NUM_SPANS - 1) {
-                assertEquals("specialPid", dspan.getProcessId());
+                assertEquals("specialTrid", dspan.getTracerId());
               } else {
-                assertEquals(TestHTraceConfiguration.PROCESS_ID,
-                    dspan.getProcessId());
+                assertEquals(TestHTraceConfiguration.TRACER_ID,
+                    dspan.getTracerId());
               }
             }
             return true;

http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/959a6ef0/htrace-webapp/src/main/web/app/span.js
----------------------------------------------------------------------
diff --git a/htrace-webapp/src/main/web/app/span.js b/htrace-webapp/src/main/web/app/span.js
index d29f020..b56a2c9 100644
--- a/htrace-webapp/src/main/web/app/span.js
+++ b/htrace-webapp/src/main/web/app/span.js
@@ -83,7 +83,7 @@ htrace.Span = Backbone.Model.extend({
     var span = {};
     this.set("spanId", response.s ? response.s : htrace.INVALID_SPAN_ID);
     this.set("traceId", response.i ? response.i : htrace.INVALID_SPAN_ID);
-    this.set("processId", response.r ? response.r : "");
+    this.set("tracerId", response.r ? response.r : "");
     this.set("parents", response.p ? response.p : []);
     this.set("description", response.d ? response.d : "");
     this.set("begin", response.b ? parseInt(response.b, 10) : 0);
@@ -125,8 +125,8 @@ htrace.Span = Backbone.Model.extend({
     if (!(this.get("traceId") === htrace.INVALID_SPAN_ID)) {
       obj.i = this.get("traceId");
     }
-    if (!(this.get("processId") === "")) {
-      obj.r = this.get("processId");
+    if (!(this.get("tracerId") === "")) {
+      obj.r = this.get("tracerId");
     }
     if (this.get("parents").length > 0) {
       obj.p = this.get("parents");

http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/959a6ef0/htrace-webapp/src/main/web/app/span_widget.js
----------------------------------------------------------------------
diff --git a/htrace-webapp/src/main/web/app/span_widget.js b/htrace-webapp/src/main/web/app/span_widget.js
index 1ef402c..50bea91 100644
--- a/htrace-webapp/src/main/web/app/span_widget.js
+++ b/htrace-webapp/src/main/web/app/span_widget.js
@@ -106,7 +106,7 @@ htrace.showSpanDetails = function(span) {
 htrace.SpanWidget = function(params) {
   this.draw = function() {
     this.drawBackground();
-    this.drawProcessId();
+    this.drawTracerId();
     this.drawDescription();
   };
 
@@ -123,14 +123,14 @@ htrace.SpanWidget = function(params) {
   }
 
   // Draw process ID text.
-  this.drawProcessId = function() {
+  this.drawTracerId = function() {
     this.ctx.save();
     this.ctx.fillStyle="#000000";
     this.ctx.font = (this.ySize - 2) + "px sans-serif";
     this.ctx.beginPath();
     this.ctx.rect(this.x0, this.y0, this.xB - this.x0, this.ySize);
     this.ctx.clip();
-    this.ctx.fillText(this.span.get('processId'), this.x0, this.yF - 4);
+    this.ctx.fillText(this.span.get('tracerId'), this.x0, this.yF - 4);
     this.ctx.restore();
   };
 

http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/959a6ef0/htrace-zipkin/src/main/java/org/apache/htrace/impl/ZipkinSpanReceiver.java
----------------------------------------------------------------------
diff --git a/htrace-zipkin/src/main/java/org/apache/htrace/impl/ZipkinSpanReceiver.java b/htrace-zipkin/src/main/java/org/apache/htrace/impl/ZipkinSpanReceiver.java
index c0bacd7..8326100 100644
--- a/htrace-zipkin/src/main/java/org/apache/htrace/impl/ZipkinSpanReceiver.java
+++ b/htrace-zipkin/src/main/java/org/apache/htrace/impl/ZipkinSpanReceiver.java
@@ -140,7 +140,7 @@ public class ZipkinSpanReceiver implements SpanReceiver {
     }
   };
 
-  private final ProcessId processId;
+  private final TracerId tracerId;
 
   ////////////////////
   /// Variables that will change on each call to configure()
@@ -154,7 +154,7 @@ public class ZipkinSpanReceiver implements SpanReceiver {
   public ZipkinSpanReceiver(HTraceConfiguration conf) {
     this.queue = new ArrayBlockingQueue<Span>(1000);
     this.protocolFactory = new TBinaryProtocol.Factory();
-    this.processId = new ProcessId(conf);
+    this.tracerId = new TracerId(conf);
     configure(conf);
   }
 
@@ -374,8 +374,8 @@ public class ZipkinSpanReceiver implements SpanReceiver {
   public void receiveSpan(Span span) {
     if (running.get()) {
       try {
-        if (span.getProcessId().isEmpty()) {
-          span.setProcessId(processId.get());
+        if (span.getTracerId().isEmpty()) {
+          span.setTracerId(tracerId.get());
         }
         this.queue.add(span);
       } catch (IllegalStateException e) {

http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/959a6ef0/htrace-zipkin/src/main/java/org/apache/htrace/zipkin/HTraceToZipkinConverter.java
----------------------------------------------------------------------
diff --git a/htrace-zipkin/src/main/java/org/apache/htrace/zipkin/HTraceToZipkinConverter.java b/htrace-zipkin/src/main/java/org/apache/htrace/zipkin/HTraceToZipkinConverter.java
index 4154d92..f41ec10 100644
--- a/htrace-zipkin/src/main/java/org/apache/htrace/zipkin/HTraceToZipkinConverter.java
+++ b/htrace-zipkin/src/main/java/org/apache/htrace/zipkin/HTraceToZipkinConverter.java
@@ -106,7 +106,7 @@ public class HTraceToZipkinConverter {
    */
   public Span convert(org.apache.htrace.Span hTraceSpan) {
     Span zipkinSpan = new Span();
-    String serviceName = hTraceSpan.getProcessId().toLowerCase();
+    String serviceName = hTraceSpan.getTracerId().toLowerCase();
     Endpoint ep = new Endpoint(ipv4Address, (short) getPort(serviceName), serviceName);
     List<Annotation> annotationList = createZipkinAnnotations(hTraceSpan, ep);
     List<BinaryAnnotation> binaryAnnotationList = createZipkinBinaryAnnotations(hTraceSpan, ep);

http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/959a6ef0/htrace-zipkin/src/test/java/org/apache/htrace/TestHTraceSpanToZipkinSpan.java
----------------------------------------------------------------------
diff --git a/htrace-zipkin/src/test/java/org/apache/htrace/TestHTraceSpanToZipkinSpan.java b/htrace-zipkin/src/test/java/org/apache/htrace/TestHTraceSpanToZipkinSpan.java
index a6790f5..915bb89 100644
--- a/htrace-zipkin/src/test/java/org/apache/htrace/TestHTraceSpanToZipkinSpan.java
+++ b/htrace-zipkin/src/test/java/org/apache/htrace/TestHTraceSpanToZipkinSpan.java
@@ -51,7 +51,7 @@ public class TestHTraceSpanToZipkinSpan {
             traceId(1).
             parents(new long[] { } ).
             spanId(100).
-            processId("test").
+            tracerId("test").
             begin(System.currentTimeMillis()).
             build();
     Span innerOne = rootSpan.child("Some good work");
@@ -76,7 +76,7 @@ public class TestHTraceSpanToZipkinSpan {
     long startTime = System.currentTimeMillis() * 1000;
     Span ms = new MilliSpan.Builder().
         description(traceName).traceId(1).parents(new long[] { }).
-        spanId(2).processId(traceName).begin(System.currentTimeMillis()).
+        spanId(2).tracerId(traceName).begin(System.currentTimeMillis()).
         build();
 
     Thread.sleep(500);
@@ -118,7 +118,7 @@ public class TestHTraceSpanToZipkinSpan {
   public void testHTraceDefaultPort() throws IOException {
     MilliSpan ms = new MilliSpan.Builder().description("test").
                       traceId(1).parents(new long[] { 2 }).
-                      spanId(3).processId("hmaster").
+                      spanId(3).tracerId("hmaster").
                       begin(System.currentTimeMillis()).build();
     com.twitter.zipkin.gen.Span zs = new HTraceToZipkinConverter(12345, (short) -1).convert(ms);
     for (com.twitter.zipkin.gen.Annotation annotation:zs.getAnnotations()) {
@@ -128,7 +128,7 @@ public class TestHTraceSpanToZipkinSpan {
     // make sure it's all lower cased
     ms = new MilliSpan.Builder().description("test").traceId(1).
                       parents(new long[] {2}).spanId(3).
-                      processId("HregIonServer").
+                      tracerId("HregIonServer").
                       begin(System.currentTimeMillis()).build();
     zs = new HTraceToZipkinConverter(12345, (short) -1).convert(ms);
     for (com.twitter.zipkin.gen.Annotation annotation:zs.getAnnotations()) {


[2/2] incubator-htrace git commit: HTRACE-217. Rename ProcessId to TracerId (cmccabe)

Posted by cm...@apache.org.
HTRACE-217. Rename ProcessId to TracerId (cmccabe)


Project: http://git-wip-us.apache.org/repos/asf/incubator-htrace/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-htrace/commit/959a6ef0
Tree: http://git-wip-us.apache.org/repos/asf/incubator-htrace/tree/959a6ef0
Diff: http://git-wip-us.apache.org/repos/asf/incubator-htrace/diff/959a6ef0

Branch: refs/heads/master
Commit: 959a6ef03fec92865bab493bac2a5f20b882fdde
Parents: 98aecf8
Author: Colin Patrick Mccabe <cm...@cloudera.com>
Authored: Thu Jul 30 11:22:17 2015 -0700
Committer: Colin Patrick Mccabe <cm...@cloudera.com>
Committed: Thu Jul 30 11:22:17 2015 -0700

----------------------------------------------------------------------
 htrace-c/src/CMakeLists.txt                     |   6 +-
 htrace-c/src/core/conf.c                        |   2 +-
 htrace-c/src/core/htrace.h                      |   2 +-
 htrace-c/src/core/htracer.c                     |  14 +-
 htrace-c/src/core/htracer.h                     |   4 +-
 htrace-c/src/core/span.c                        |  14 +-
 htrace-c/src/core/span.h                        |   4 +-
 htrace-c/src/receiver/htraced.c                 |   8 +-
 htrace-c/src/receiver/local_file.c              |   6 +-
 htrace-c/src/test/cmp_util-unit.c               |   4 +-
 htrace-c/src/test/process_id-unit.c             |  80 -----
 htrace-c/src/test/rtest.c                       |  18 +-
 htrace-c/src/test/rtestpp.cc                    |  18 +-
 htrace-c/src/test/sampler-unit.c                |   2 +-
 htrace-c/src/test/span-unit.c                   |  10 +-
 htrace-c/src/test/span_table.c                  |   6 +-
 htrace-c/src/test/span_table.h                  |   4 +-
 htrace-c/src/test/span_util.c                   |  14 +-
 htrace-c/src/test/tracer_id-unit.c              |  80 +++++
 htrace-c/src/util/process_id.c                  | 304 -------------------
 htrace-c/src/util/process_id.h                  |  58 ----
 htrace-c/src/util/tracer_id.c                   | 304 +++++++++++++++++++
 htrace-c/src/util/tracer_id.h                   |  58 ++++
 .../src/main/java/org/apache/htrace/Span.java   |  10 +-
 .../main/java/org/apache/htrace/TraceTree.java  |  20 +-
 .../htrace/impl/LocalFileSpanReceiver.java      |   8 +-
 .../java/org/apache/htrace/impl/MilliSpan.java  |  24 +-
 .../java/org/apache/htrace/impl/ProcessId.java  | 291 ------------------
 .../java/org/apache/htrace/impl/TracerId.java   | 291 ++++++++++++++++++
 .../htrace/impl/TestLocalFileSpanReceiver.java  |   4 +-
 .../org/apache/htrace/impl/TestMilliSpan.java   |  10 +-
 .../org/apache/htrace/impl/TestProcessId.java   |  47 ---
 .../org/apache/htrace/impl/TestTracerId.java    |  47 +++
 .../apache/htrace/impl/FlumeSpanReceiver.java   |  10 +-
 .../htrace/impl/TestFlumeSpanReceiver.java      |   2 +-
 .../apache/htrace/impl/HBaseSpanReceiver.java   |  10 +-
 .../htrace/impl/TestHBaseSpanReceiver.java      |   8 +-
 .../go/src/org/apache/htrace/client/client.go   |   4 +-
 .../go/src/org/apache/htrace/common/query.go    |   4 +-
 .../go/src/org/apache/htrace/common/rpc.go      |   4 +-
 .../go/src/org/apache/htrace/common/span.go     |   2 +-
 .../src/org/apache/htrace/common/span_test.go   |   8 +-
 .../src/org/apache/htrace/htrace/file_test.go   |   4 +-
 .../src/org/apache/htrace/htrace/graph_test.go  |   6 +-
 .../src/org/apache/htrace/htraced/datastore.go  |   8 +-
 .../org/apache/htrace/htraced/datastore_test.go |   6 +-
 .../go/src/org/apache/htrace/htraced/hrpc.go    |   6 +-
 .../go/src/org/apache/htrace/htraced/rest.go    |  10 +-
 .../go/src/org/apache/htrace/test/random.go     |   2 +-
 .../apache/htrace/impl/HTracedRESTReceiver.java |   6 +-
 .../htrace/impl/TestHTracedRESTReceiver.java    |  16 +-
 htrace-webapp/src/main/web/app/span.js          |   6 +-
 htrace-webapp/src/main/web/app/span_widget.js   |   6 +-
 .../apache/htrace/impl/ZipkinSpanReceiver.java  |   8 +-
 .../htrace/zipkin/HTraceToZipkinConverter.java  |   2 +-
 .../htrace/TestHTraceSpanToZipkinSpan.java      |   8 +-
 56 files changed, 959 insertions(+), 959 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/959a6ef0/htrace-c/src/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/htrace-c/src/CMakeLists.txt b/htrace-c/src/CMakeLists.txt
index 57558a5..c34a7c2 100644
--- a/htrace-c/src/CMakeLists.txt
+++ b/htrace-c/src/CMakeLists.txt
@@ -88,7 +88,7 @@ set(SRC_ALL
     util/cmp_util.c
     util/htable.c
     util/log.c
-    util/process_id.c
+    util/tracer_id.c
     util/string.c
     util/terror.c
     util/time.c
@@ -175,8 +175,8 @@ add_utest(mini_htraced-unit
     test/mini_htraced-unit.c
 )
 
-add_utest(process_id-unit
-    test/process_id-unit.c
+add_utest(tracer_id-unit
+    test/tracer_id-unit.c
 )
 
 if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")

http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/959a6ef0/htrace-c/src/core/conf.c
----------------------------------------------------------------------
diff --git a/htrace-c/src/core/conf.c b/htrace-c/src/core/conf.c
index d9eed2a..08fbb8c 100644
--- a/htrace-c/src/core/conf.c
+++ b/htrace-c/src/core/conf.c
@@ -32,7 +32,7 @@
      ";" HTRACED_FLUSH_INTERVAL_MS_KEY "=120000"\
      ";" HTRACED_WRITE_TIMEO_MS_KEY "=60000"\
      ";" HTRACED_READ_TIMEO_MS_KEY "=60000"\
-     ";" HTRACE_PROCESS_ID "=%{tname}/%{ip}"\
+     ";" HTRACE_TRACER_ID "=%{tname}/%{ip}"\
      ";" HTRACED_ADDRESS_KEY "=localhost:9095"\
      ";" HTRACED_BUFFER_SEND_TRIGGER_FRACTION "=0.50"\
     )

http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/959a6ef0/htrace-c/src/core/htrace.h
----------------------------------------------------------------------
diff --git a/htrace-c/src/core/htrace.h b/htrace-c/src/core/htrace.h
index 816c222..e7dc93b 100644
--- a/htrace-c/src/core/htrace.h
+++ b/htrace-c/src/core/htrace.h
@@ -150,7 +150,7 @@ extern  "C" {
  *
  * Defaults to %{tname}/%{ip}
  */
-#define HTRACE_PROCESS_ID "process.id"
+#define HTRACE_TRACER_ID "tracer.id"
 
 /**
  * The sampler to use.

http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/959a6ef0/htrace-c/src/core/htracer.c
----------------------------------------------------------------------
diff --git a/htrace-c/src/core/htracer.c b/htrace-c/src/core/htracer.c
index 3305beb..b1bcb61 100644
--- a/htrace-c/src/core/htracer.c
+++ b/htrace-c/src/core/htracer.c
@@ -23,9 +23,9 @@
 #include "core/span.h"
 #include "receiver/receiver.h"
 #include "util/log.h"
-#include "util/process_id.h"
 #include "util/rand.h"
 #include "util/string.h"
+#include "util/tracer_id.h"
 
 #include <errno.h>
 #include <stdint.h>
@@ -67,17 +67,17 @@ struct htracer *htracer_create(const char *tname,
         htracer_free(tracer);
         return NULL;
     }
-    tracer->prid = calculate_process_id(tracer->lg,
-            htrace_conf_get(cnf, HTRACE_PROCESS_ID), tname);
-    if (!tracer->prid) {
+    tracer->trid = calculate_tracer_id(tracer->lg,
+            htrace_conf_get(cnf, HTRACE_TRACER_ID), tname);
+    if (!tracer->trid) {
         htrace_log(tracer->lg, "htracer_create: failed to "
                    "create process id string.\n");
         htracer_free(tracer);
         return NULL;
     }
-    if (!validate_json_string(tracer->lg, tracer->prid)) {
+    if (!validate_json_string(tracer->lg, tracer->trid)) {
         htrace_log(tracer->lg, "htracer_create: process ID string '%s' is "
-                   "problematic.\n", tracer->prid);
+                   "problematic.\n", tracer->trid);
         htracer_free(tracer);
         return NULL;
     }
@@ -117,7 +117,7 @@ void htracer_free(struct htracer *tracer)
     }
     random_src_free(tracer->rnd);
     free(tracer->tname);
-    free(tracer->prid);
+    free(tracer->trid);
     htrace_log_free(tracer->lg);
     free(tracer);
 }

http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/959a6ef0/htrace-c/src/core/htracer.h
----------------------------------------------------------------------
diff --git a/htrace-c/src/core/htracer.h b/htrace-c/src/core/htracer.h
index 2acdf70..76fbbac 100644
--- a/htrace-c/src/core/htracer.h
+++ b/htrace-c/src/core/htracer.h
@@ -50,9 +50,9 @@ struct htracer {
     char *tname;
 
     /**
-     * The process id of this context.
+     * The tracer id of this context.
      */
-    char *prid;
+    char *trid;
 
     /**
      * The random source to use in this context.

http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/959a6ef0/htrace-c/src/core/span.c
----------------------------------------------------------------------
diff --git a/htrace-c/src/core/span.c b/htrace-c/src/core/span.c
index 790afa5..b82f4f1 100644
--- a/htrace-c/src/core/span.c
+++ b/htrace-c/src/core/span.c
@@ -54,7 +54,7 @@ struct htrace_span *htrace_span_alloc(const char *desc,
     span->begin_ms = begin_ms;
     span->end_ms = 0;
     span->span_id = span_id;
-    span->prid = NULL;
+    span->trid = NULL;
     span->num_parents = 0;
     span->parent.single = 0;
     span->parent.list = NULL;
@@ -67,7 +67,7 @@ void htrace_span_free(struct htrace_span *span)
         return;
     }
     free(span->desc);
-    free(span->prid);
+    free(span->trid);
     if (span->num_parents > 1) {
         free(span->parent.list);
     }
@@ -152,8 +152,8 @@ static int span_json_sprintf_impl(const struct htrace_span *span,
     if (span->desc[0]) {
         ret += fwdprintf(&buf, &max, "\"d\":\"%s\",", span->desc);
     }
-    if (span->prid) {
-        ret += fwdprintf(&buf, &max, "\"r\":\"%s\",", span->prid);
+    if (span->trid) {
+        ret += fwdprintf(&buf, &max, "\"r\":\"%s\",", span->trid);
     }
     num_parents = span->num_parents;
     if (num_parents == 0) {
@@ -196,7 +196,7 @@ int span_write_msgpack(const struct htrace_span *span, cmp_ctx_t *ctx)
         1; // span_id
 
     num_parents = span->num_parents;
-    if (span->prid) {
+    if (span->trid) {
         map_size++;
     }
     if (num_parents > 0) {
@@ -229,11 +229,11 @@ int span_write_msgpack(const struct htrace_span *span, cmp_ctx_t *ctx)
     if (!cmp_write_u64(ctx, span->span_id)) {
         return 0;
     }
-    if (span->prid) {
+    if (span->trid) {
         if (!cmp_write_fixstr(ctx, "r", 1)) {
             return 0;
         }
-        if (!cmp_write_str16(ctx, span->prid, strlen(span->prid))) {
+        if (!cmp_write_str16(ctx, span->trid, strlen(span->trid))) {
             return 0;
         }
     }

http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/959a6ef0/htrace-c/src/core/span.h
----------------------------------------------------------------------
diff --git a/htrace-c/src/core/span.h b/htrace-c/src/core/span.h
index 710cff7..4d28e75 100644
--- a/htrace-c/src/core/span.h
+++ b/htrace-c/src/core/span.h
@@ -55,10 +55,10 @@ struct htrace_span {
     uint64_t span_id;
 
     /**
-     * The process ID of this trace scope.
+     * The tracer ID of this trace scope.
      * Dynamically allocated.  May be null.
      */
-    char *prid;
+    char *trid;
 
     /**
      * The number of parents.

http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/959a6ef0/htrace-c/src/receiver/htraced.c
----------------------------------------------------------------------
diff --git a/htrace-c/src/receiver/htraced.c b/htrace-c/src/receiver/htraced.c
index 8f392b7..d92518d 100644
--- a/htrace-c/src/receiver/htraced.c
+++ b/htrace-c/src/receiver/htraced.c
@@ -488,8 +488,8 @@ static int should_xmit(struct htraced_rcv *rcv, uint64_t now)
     return 0; // Let's wait.
 }
 
-#define DEFAULT_PID_STR         "DefaultPid"
-#define DEFAULT_PID_STR_LEN     (sizeof(DEFAULT_PID_STR) - 1)
+#define DEFAULT_TRID_STR        "DefaultTrid"
+#define DEFAULT_TRID_STR_LEN    (sizeof(DEFAULT_TRID_STR) - 1)
 #define SPANS_STR               "Spans"
 #define SPANS_STR_LEN           (sizeof(SPANS_STR) - 1)
 
@@ -505,10 +505,10 @@ static int add_writespans_prequel(struct htraced_rcv *rcv,
     if (!cmp_write_fixmap(ctx, 2)) {
         return -1;
     }
-    if (!cmp_write_fixstr(ctx, DEFAULT_PID_STR, DEFAULT_PID_STR_LEN)) {
+    if (!cmp_write_fixstr(ctx, DEFAULT_TRID_STR, DEFAULT_TRID_STR_LEN)) {
         return -1;
     }
-    if (!cmp_write_str(ctx, rcv->tracer->prid, strlen(rcv->tracer->prid))) {
+    if (!cmp_write_str(ctx, rcv->tracer->trid, strlen(rcv->tracer->trid))) {
         return -1;
     }
     if (!cmp_write_fixstr(ctx, SPANS_STR, SPANS_STR_LEN)) {

http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/959a6ef0/htrace-c/src/receiver/local_file.c
----------------------------------------------------------------------
diff --git a/htrace-c/src/receiver/local_file.c b/htrace-c/src/receiver/local_file.c
index 667da29..05fabee 100644
--- a/htrace-c/src/receiver/local_file.c
+++ b/htrace-c/src/receiver/local_file.c
@@ -114,16 +114,16 @@ static void local_file_rcv_add_span(struct htrace_rcv *r,
     char *buf;
     struct local_file_rcv *rcv = (struct local_file_rcv *)r;
 
-    span->prid = rcv->tracer->prid;
+    span->trid = rcv->tracer->trid;
     len = span_json_size(span);
     buf = malloc(len + 1);
     if (!buf) {
-        span->prid = NULL;
+        span->trid = NULL;
         htrace_log(rcv->tracer->lg, "local_file_rcv_add_span: OOM\n");
         return;
     }
     span_json_sprintf(span, len, buf);
-    span->prid = NULL;
+    span->trid = NULL;
     buf[len - 1] = '\n';
     buf[len] = '\0';
     pthread_mutex_lock(&rcv->lock);

http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/959a6ef0/htrace-c/src/test/cmp_util-unit.c
----------------------------------------------------------------------
diff --git a/htrace-c/src/test/cmp_util-unit.c b/htrace-c/src/test/cmp_util-unit.c
index bfe4edc..4675ca8 100644
--- a/htrace-c/src/test/cmp_util-unit.c
+++ b/htrace-c/src/test/cmp_util-unit.c
@@ -46,7 +46,7 @@ static struct htrace_span **setup_test_spans(void)
     spans[1]->begin_ms = 1950;
     spans[1]->end_ms = 2000;
     spans[1]->span_id = 0xffffffffffffffffULL;
-    spans[1]->prid = xstrdup("SecondSpanProc");
+    spans[1]->trid = xstrdup("SecondSpanProc");
     spans[1]->num_parents = 1;
     spans[1]->parent.single = 1;
 
@@ -55,7 +55,7 @@ static struct htrace_span **setup_test_spans(void)
     spans[2]->begin_ms = 1969;
     spans[2]->end_ms = 1997;
     spans[2]->span_id = 0xcfcfcfcfcfcfcfcfULL;
-    spans[2]->prid = xstrdup("ThirdSpanProc");
+    spans[2]->trid = xstrdup("ThirdSpanProc");
     spans[2]->num_parents = 2;
     spans[2]->parent.list = xcalloc(sizeof(uint64_t) * 2);
     spans[2]->parent.list[0] = 1;

http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/959a6ef0/htrace-c/src/test/process_id-unit.c
----------------------------------------------------------------------
diff --git a/htrace-c/src/test/process_id-unit.c b/htrace-c/src/test/process_id-unit.c
deleted file mode 100644
index 5454eb0..0000000
--- a/htrace-c/src/test/process_id-unit.c
+++ /dev/null
@@ -1,80 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "core/conf.h"
-#include "test/test.h"
-#include "util/log.h"
-#include "util/process_id.h"
-
-#include <inttypes.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/types.h>
-#include <unistd.h>
-
-static struct htrace_conf *g_cnf;
-
-static struct htrace_log *g_lg;
-
-static int test_calculate_process_id(const char *expected, const char *fmt)
-{
-    char *process_id;
-
-    process_id = calculate_process_id(g_lg, fmt, "fooproc");
-    EXPECT_NONNULL(process_id);
-    EXPECT_STR_EQ(expected, process_id);
-    free(process_id);
-
-    return EXIT_SUCCESS;
-}
-
-static int test_calculate_process_ids(void)
-{
-    char buf[128];
-
-    EXPECT_INT_ZERO(test_calculate_process_id("my.name", "my.name"));
-    EXPECT_INT_ZERO(test_calculate_process_id("my.fooproc", "my.%{tname}"));
-    EXPECT_INT_ZERO(test_calculate_process_id("\%foo", "\%foo"));
-    EXPECT_INT_ZERO(test_calculate_process_id("fooproc", "%{tname}"));
-    EXPECT_INT_ZERO(test_calculate_process_id("\\fooproc", "\\\\%{tname}"));
-    EXPECT_INT_ZERO(test_calculate_process_id("\%{tname}", "\\%{tname}"));
-
-    snprintf(buf, sizeof(buf), "me.%lld", (long long)getpid());
-    EXPECT_INT_ZERO(test_calculate_process_id(buf, "me.%{pid}"));
-
-    get_best_ip(g_lg, buf, sizeof(buf));
-    EXPECT_INT_ZERO(test_calculate_process_id(buf, "%{ip}"));
-
-    return EXIT_SUCCESS;
-}
-
-int main(void)
-{
-    g_cnf = htrace_conf_from_strs("", "");
-    EXPECT_NONNULL(g_cnf);
-    g_lg = htrace_log_alloc(g_cnf);
-    EXPECT_NONNULL(g_lg);
-    EXPECT_INT_ZERO(test_calculate_process_ids());
-    htrace_log_free(g_lg);
-    htrace_conf_free(g_cnf);
-
-    return EXIT_SUCCESS;
-}
-
-// vim: ts=4:sw=4:tw=79:et

http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/959a6ef0/htrace-c/src/test/rtest.c
----------------------------------------------------------------------
diff --git a/htrace-c/src/test/rtest.c b/htrace-c/src/test/rtest.c
index b299376..ccae241 100644
--- a/htrace-c/src/test/rtest.c
+++ b/htrace-c/src/test/rtest.c
@@ -45,9 +45,9 @@ struct rtest_data {
     struct htracer *tracer;
 };
 
-static void get_receiver_test_prid(char *prid, size_t prid_len)
+static void get_receiver_test_trid(char *trid, size_t trid_len)
 {
-    snprintf(prid, prid_len, RECEIVER_TEST_TNAME "/%lld", (long long)getpid());
+    snprintf(trid, trid_len, RECEIVER_TEST_TNAME "/%lld", (long long)getpid());
 }
 
 static int rtest_data_init(const char *conf_str, struct rtest_data **out)
@@ -55,7 +55,7 @@ static int rtest_data_init(const char *conf_str, struct rtest_data **out)
     char *econf_str = NULL;
     struct rtest_data *rdata = calloc(1, sizeof(*(rdata)));
     EXPECT_NONNULL(rdata);
-    if (asprintf(&econf_str, HTRACE_PROCESS_ID"=%%{tname}/%%{pid};sampler=always;"
+    if (asprintf(&econf_str, HTRACE_TRACER_ID"=%%{tname}/%%{pid};sampler=always;"
               "%s", conf_str) < 0) {
         fprintf(stderr, "asprintf(econf_str) failed: OOM\n");
         return EXIT_FAILURE;
@@ -123,24 +123,24 @@ int rtest_simple_verify(struct rtest *rt, struct span_table *st)
 {
     struct htrace_span *span;
     uint64_t doit_id, part2_id;
-    char prid[128];
+    char trid[128];
 
     EXPECT_INT_ZERO(rtest_verify_table_size(rt, st));
-    get_receiver_test_prid(prid, sizeof(prid));
-    EXPECT_INT_ZERO(span_table_get(st, &span, "doit", prid));
+    get_receiver_test_trid(trid, sizeof(trid));
+    EXPECT_INT_ZERO(span_table_get(st, &span, "doit", trid));
     doit_id = span->span_id;
     EXPECT_INT_ZERO(span->num_parents);
 
-    EXPECT_INT_ZERO(span_table_get(st, &span, "part1", prid));
+    EXPECT_INT_ZERO(span_table_get(st, &span, "part1", trid));
     EXPECT_INT_EQ(1, span->num_parents);
     EXPECT_UINT64_EQ(doit_id, span->parent.single);
 
-    EXPECT_INT_ZERO(span_table_get(st, &span, "part2", prid));
+    EXPECT_INT_ZERO(span_table_get(st, &span, "part2", trid));
     EXPECT_INT_EQ(1, span->num_parents);
     part2_id = span->span_id;
     EXPECT_UINT64_EQ(doit_id, span->parent.single);
 
-    EXPECT_INT_ZERO(span_table_get(st, &span, "part2.5", prid));
+    EXPECT_INT_ZERO(span_table_get(st, &span, "part2.5", trid));
     EXPECT_INT_EQ(1, span->num_parents);
     EXPECT_UINT64_EQ(part2_id, span->parent.single);
 

http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/959a6ef0/htrace-c/src/test/rtestpp.cc
----------------------------------------------------------------------
diff --git a/htrace-c/src/test/rtestpp.cc b/htrace-c/src/test/rtestpp.cc
index 649826c..0cd7120 100644
--- a/htrace-c/src/test/rtestpp.cc
+++ b/htrace-c/src/test/rtestpp.cc
@@ -48,7 +48,7 @@ class RTestData {
 public:
     RTestData(struct rtest *rt, const char *conf_str)
         : rt_(rt),
-          cnf_(string(HTRACE_PROCESS_ID"=%{tname}/%{pid};sampler=always;") +
+          cnf_(string(HTRACE_TRACER_ID"=%{tname}/%{pid};sampler=always;") +
                string(conf_str).c_str()),
           tracer_(RECEIVER_TEST_TNAME, cnf_),
           always_(&tracer_, cnf_)
@@ -72,9 +72,9 @@ private:
     RTestData& operator=(const RTestData &other); // disallow assignment
 };
 
-static void get_receiver_test_prid(char *prid, size_t prid_len)
+static void get_receiver_test_trid(char *trid, size_t trid_len)
 {
-    snprintf(prid, prid_len, RECEIVER_TEST_TNAME "/%lld", (long long)getpid());
+    snprintf(trid, trid_len, RECEIVER_TEST_TNAME "/%lld", (long long)getpid());
 }
 
 static int rtest_generic_verify(struct rtest *rt, struct span_table *st)
@@ -116,24 +116,24 @@ int rtestpp_simple_verify(struct rtest *rt, struct span_table *st)
 {
     struct htrace_span *span;
     uint64_t doit_id, part2_id;
-    char prid[128];
+    char trid[128];
 
     EXPECT_INT_ZERO(rtest_generic_verify(rt, st));
-    get_receiver_test_prid(prid, sizeof(prid));
-    EXPECT_INT_ZERO(span_table_get(st, &span, "doit", prid));
+    get_receiver_test_trid(trid, sizeof(trid));
+    EXPECT_INT_ZERO(span_table_get(st, &span, "doit", trid));
     doit_id = span->span_id;
     EXPECT_INT_ZERO(span->num_parents);
 
-    EXPECT_INT_ZERO(span_table_get(st, &span, "part1", prid));
+    EXPECT_INT_ZERO(span_table_get(st, &span, "part1", trid));
     EXPECT_INT_EQ(1, span->num_parents);
     EXPECT_UINT64_EQ(doit_id, span->parent.single);
 
-    EXPECT_INT_ZERO(span_table_get(st, &span, "part2", prid));
+    EXPECT_INT_ZERO(span_table_get(st, &span, "part2", trid));
     EXPECT_INT_EQ(1, span->num_parents);
     part2_id = span->span_id;
     EXPECT_UINT64_EQ(doit_id, span->parent.single);
 
-    EXPECT_INT_ZERO(span_table_get(st, &span, "part2.5", prid));
+    EXPECT_INT_ZERO(span_table_get(st, &span, "part2.5", trid));
     EXPECT_INT_EQ(1, span->num_parents);
     EXPECT_UINT64_EQ(part2_id, span->parent.single);
 

http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/959a6ef0/htrace-c/src/test/sampler-unit.c
----------------------------------------------------------------------
diff --git a/htrace-c/src/test/sampler-unit.c b/htrace-c/src/test/sampler-unit.c
index 2a42292..b1f7391 100644
--- a/htrace-c/src/test/sampler-unit.c
+++ b/htrace-c/src/test/sampler-unit.c
@@ -115,7 +115,7 @@ static int test_prob_sampler(double target, double slop)
 
 int main(void)
 {
-    g_test_conf = htrace_conf_from_strs("", HTRACE_PROCESS_ID"=sampler-unit");
+    g_test_conf = htrace_conf_from_strs("", HTRACE_TRACER_ID"=sampler-unit");
     EXPECT_NONNULL(g_test_conf);
     g_test_lg = htrace_log_alloc(g_test_conf);
     EXPECT_NONNULL(g_test_lg);

http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/959a6ef0/htrace-c/src/test/span-unit.c
----------------------------------------------------------------------
diff --git a/htrace-c/src/test/span-unit.c b/htrace-c/src/test/span-unit.c
index da6ca66..5482b8d 100644
--- a/htrace-c/src/test/span-unit.c
+++ b/htrace-c/src/test/span-unit.c
@@ -43,7 +43,7 @@ static struct htracer *g_test_tracer;
 
 static struct htrace_span *create_span(const char *desc,
         uint64_t begin_ms, uint64_t end_ms, uint64_t span_id,
-        const char *prid, ...) __attribute__((sentinel));
+        const char *trid, ...) __attribute__((sentinel));
 
 static int test_span_to_json(const char *expected,
                              struct htrace_span *span)
@@ -83,14 +83,14 @@ static int test_span_to_json(const char *expected,
 
 static struct htrace_span *create_span(const char *desc,
         uint64_t begin_ms, uint64_t end_ms, uint64_t span_id,
-        const char *prid, ...)
+        const char *trid, ...)
 {
     struct htrace_span* span = NULL;
     uint64_t *parents, parent;
     int i, num_parents = 0;
     va_list ap, ap2;
 
-    va_start(ap, prid);
+    va_start(ap, trid);
     va_copy(ap2, ap);
     while (1) {
         parent = va_arg(ap2, uint64_t);
@@ -110,7 +110,7 @@ static struct htrace_span *create_span(const char *desc,
     span = htrace_span_alloc(desc, begin_ms, span_id);
     span->end_ms = end_ms;
     span->span_id = span_id;
-    span->prid = xstrdup(prid);
+    span->trid = xstrdup(trid);
     span->num_parents = num_parents;
     if (num_parents == 1) {
         span->parent.single = parents[0];
@@ -155,7 +155,7 @@ static int test_spans_to_str(void)
 
 int main(void)
 {
-    g_test_conf = htrace_conf_from_strs("", HTRACE_PROCESS_ID"=span-unit");
+    g_test_conf = htrace_conf_from_strs("", HTRACE_TRACER_ID"=span-unit");
     EXPECT_NONNULL(g_test_conf);
     g_test_lg = htrace_log_alloc(g_test_conf);
     EXPECT_NONNULL(g_test_lg);

http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/959a6ef0/htrace-c/src/test/span_table.c
----------------------------------------------------------------------
diff --git a/htrace-c/src/test/span_table.c b/htrace-c/src/test/span_table.c
index 8840fbf..42ed5f6 100644
--- a/htrace-c/src/test/span_table.c
+++ b/htrace-c/src/test/span_table.c
@@ -41,7 +41,7 @@ struct span_table *span_table_alloc(void)
 }
 
 int span_table_get(struct span_table *st, struct htrace_span **out,
-                   const char *desc, const char *prid)
+                   const char *desc, const char *trid)
 {
     struct htable *ht = (struct htable *)st;
     struct htrace_span *span;
@@ -51,8 +51,8 @@ int span_table_get(struct span_table *st, struct htrace_span **out,
     EXPECT_STR_EQ(desc, span->desc);
     EXPECT_UINT64_GE(span->begin_ms, span->end_ms);
     EXPECT_UINT64_GT(0L, span->span_id);
-    EXPECT_NONNULL(span->prid);
-    EXPECT_STR_EQ(prid, span->prid);
+    EXPECT_NONNULL(span->trid);
+    EXPECT_STR_EQ(trid, span->trid);
     *out = span;
     return EXIT_SUCCESS;
 }

http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/959a6ef0/htrace-c/src/test/span_table.h
----------------------------------------------------------------------
diff --git a/htrace-c/src/test/span_table.h b/htrace-c/src/test/span_table.h
index b55cd92..28399dd 100644
--- a/htrace-c/src/test/span_table.h
+++ b/htrace-c/src/test/span_table.h
@@ -45,12 +45,12 @@ struct span_table *span_table_alloc(void);
  * @param out           (out param) the span.  This pointer will be valid until
  *                          the span table is freed.
  * @param desc          The span description to look for.
- * @param prid          The process ID to verify that the span has.
+ * @param trid          The process ID to verify that the span has.
  *
  * @return              0 on success; nonzero otherwise.
  */
 int span_table_get(struct span_table *st, struct htrace_span **out,
-                   const char *desc, const char *prid);
+                   const char *desc, const char *trid);
 
 /**
  * Add a span to the table.

http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/959a6ef0/htrace-c/src/test/span_util.c
----------------------------------------------------------------------
diff --git a/htrace-c/src/test/span_util.c b/htrace-c/src/test/span_util.c
index 2069cdc..625ba86 100644
--- a/htrace-c/src/test/span_util.c
+++ b/htrace-c/src/test/span_util.c
@@ -150,11 +150,11 @@ static void span_json_parse_impl(struct json_object *root,
         }
     }
     if (json_object_object_get_ex(root, "r", &r)) {
-        span->prid = strdup(json_object_get_string(r));
+        span->trid = strdup(json_object_get_string(r));
     } else {
-        span->prid = strdup("");
+        span->trid = strdup("");
     }
-    if (!span->prid) {
+    if (!span->trid) {
         snprintf(err, err_len, "out of memory allocating process id");
         return;
     }
@@ -285,7 +285,7 @@ int span_compare(struct htrace_span *a, struct htrace_span *b)
     if (c) {
         return c;
     }
-    c = strcmp_handle_null(a->prid, b->prid);
+    c = strcmp_handle_null(a->trid, b->trid);
     if (c) {
         return c;
     }
@@ -444,10 +444,10 @@ struct htrace_span *span_read_msgpack(struct cmp_ctx_s *ctx,
             }
             break;
         case 'r':
-            if (span->prid) {
-                free(span->prid);
+            if (span->trid) {
+                free(span->trid);
             }
-            span->prid = cmp_read_malloced_string(ctx, "process_id",
+            span->trid = cmp_read_malloced_string(ctx, "tracer_id",
                                                   err, err_len);
             if (err[0]) {
                 goto error;

http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/959a6ef0/htrace-c/src/test/tracer_id-unit.c
----------------------------------------------------------------------
diff --git a/htrace-c/src/test/tracer_id-unit.c b/htrace-c/src/test/tracer_id-unit.c
new file mode 100644
index 0000000..fe034b4
--- /dev/null
+++ b/htrace-c/src/test/tracer_id-unit.c
@@ -0,0 +1,80 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "core/conf.h"
+#include "test/test.h"
+#include "util/log.h"
+#include "util/tracer_id.h"
+
+#include <inttypes.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+static struct htrace_conf *g_cnf;
+
+static struct htrace_log *g_lg;
+
+static int test_calculate_tracer_id(const char *expected, const char *fmt)
+{
+    char *tracer_id;
+
+    tracer_id = calculate_tracer_id(g_lg, fmt, "fooproc");
+    EXPECT_NONNULL(tracer_id);
+    EXPECT_STR_EQ(expected, tracer_id);
+    free(tracer_id);
+
+    return EXIT_SUCCESS;
+}
+
+static int test_calculate_tracer_ids(void)
+{
+    char buf[128];
+
+    EXPECT_INT_ZERO(test_calculate_tracer_id("my.name", "my.name"));
+    EXPECT_INT_ZERO(test_calculate_tracer_id("my.fooproc", "my.%{tname}"));
+    EXPECT_INT_ZERO(test_calculate_tracer_id("\%foo", "\%foo"));
+    EXPECT_INT_ZERO(test_calculate_tracer_id("fooproc", "%{tname}"));
+    EXPECT_INT_ZERO(test_calculate_tracer_id("\\fooproc", "\\\\%{tname}"));
+    EXPECT_INT_ZERO(test_calculate_tracer_id("\%{tname}", "\\%{tname}"));
+
+    snprintf(buf, sizeof(buf), "me.%lld", (long long)getpid());
+    EXPECT_INT_ZERO(test_calculate_tracer_id(buf, "me.%{pid}"));
+
+    get_best_ip(g_lg, buf, sizeof(buf));
+    EXPECT_INT_ZERO(test_calculate_tracer_id(buf, "%{ip}"));
+
+    return EXIT_SUCCESS;
+}
+
+int main(void)
+{
+    g_cnf = htrace_conf_from_strs("", "");
+    EXPECT_NONNULL(g_cnf);
+    g_lg = htrace_log_alloc(g_cnf);
+    EXPECT_NONNULL(g_lg);
+    EXPECT_INT_ZERO(test_calculate_tracer_ids());
+    htrace_log_free(g_lg);
+    htrace_conf_free(g_cnf);
+
+    return EXIT_SUCCESS;
+}
+
+// vim: ts=4:sw=4:tw=79:et

http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/959a6ef0/htrace-c/src/util/process_id.c
----------------------------------------------------------------------
diff --git a/htrace-c/src/util/process_id.c b/htrace-c/src/util/process_id.c
deleted file mode 100644
index c11b693..0000000
--- a/htrace-c/src/util/process_id.c
+++ /dev/null
@@ -1,304 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "util/log.h"
-#include "util/process_id.h"
-
-#include <arpa/inet.h>
-#include <errno.h>
-#include <ifaddrs.h>
-#include <stdint.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/socket.h>
-#include <sys/types.h>
-#include <unistd.h>
-
-/**
- * @file process_id.c
- *
- * Implements process IDs for the HTrace C client.
- */
-
-/**
- * The maximum number of bytes that can be in a process ID substitution
- * variable.
- */
-#define MAX_VAR_NAME 32
-
-enum ip_addr_type {
-    ADDR_TYPE_IPV6_LOOPBACK = 0,
-    ADDR_TYPE_IPV4_LOOPBACK,
-    ADDR_TYPE_IPV6_OTHER,
-    ADDR_TYPE_IPV4_OTHER,
-    ADDR_TYPE_IPV6_SITE_LOCAL,
-    ADDR_TYPE_IPV4_SITE_LOCAL
-};
-
-static int handle_process_subst_var(struct htrace_log *lg, char **out,
-                                    const char *var, const char *tname);
-
-enum ip_addr_type get_ipv4_addr_type(const struct sockaddr_in *ip);
-
-enum ip_addr_type get_ipv6_addr_type(const struct sockaddr_in6 *ip);
-
-static int append_char(char **out, int *j, char c)
-{
-    char *nout = realloc(*out, *j + 2); // leave space for NULL
-    if (!nout) {
-        return 0;
-    }
-    *out = nout;
-    (*out)[*j] = c;
-    *j = *j + 1;
-    (*out)[*j] = '\0';
-    return 1;
-}
-
-char *calculate_process_id(struct htrace_log *lg, const char *fmt,
-                           const char *tname)
-{
-    int i = 0, j = 0, escaping = 0, v = 0;
-    char *out = NULL, *var = NULL;
-
-    out = strdup("");
-    if (!out) {
-        goto oom;
-    }
-    while (1) {
-        char c = fmt[i++];
-        if (c == '\0') {
-            break;
-        } else if (c == '\\') {
-            if (!escaping) {
-                escaping = 1;
-                continue;
-            }
-        }
-        switch (v) {
-        case 0:
-            if (c == '%') {
-                if (!escaping) {
-                    if (!append_char(&var, &v, '%')) {
-                        goto oom;
-                    }
-                    continue;
-                }
-            }
-            break;
-        case 1:
-            if (c == '{') {
-                if (!escaping) {
-                    if (!append_char(&var, &v, '{')) {
-                        goto oom;
-                    }
-                    continue;
-                }
-            }
-            if (!append_char(&out, &j, '%')) {
-                goto oom;
-            }
-            break;
-        default:
-            if (c == '}') {
-                if (!escaping) {
-                    if (!append_char(&var, &v, '}')) {
-                        goto oom;
-                    }
-                    var[v++] = '\0';
-                    if (!handle_process_subst_var(lg, &out, var, tname)) {
-                        goto oom;
-                    }
-                    free(var);
-                    var = NULL;
-                    j = strlen(out);
-                    v = 0;
-                    continue;
-                }
-            }
-            escaping = 0;
-            if (!append_char(&var, &v, c)) {
-                goto oom;
-            }
-            continue;
-        }
-        escaping = 0;
-        v = 0;
-        if (!append_char(&out, &j, c)) {
-            goto oom;
-        }
-    }
-    out[j] = '\0';
-    if (v > 0) {
-      htrace_log(lg, "calculate_process_id(%s): unterminated process ID "
-                 "substitution variable at the end of the format string.",
-                 fmt);
-    }
-    free(var);
-    return out;
-
-oom:
-    htrace_log(lg, "calculate_process_id(tname=%s): OOM\n", tname);
-    free(out);
-    free(var);
-    return NULL;
-}
-
-static int handle_process_subst_var(struct htrace_log *lg, char **out,
-                                    const char *var, const char *tname)
-{
-    char *nout = NULL;
-
-    if (strcmp(var, "%{tname}") == 0) {
-        if (asprintf(&nout, "%s%s", *out, tname) < 0) {
-            htrace_log(lg, "handle_process_subst_var(var=%s): OOM", var);
-            return 0;
-        }
-        free(*out);
-        *out = nout;
-    } else if (strcmp(var, "%{ip}") == 0) {
-        char ip_str[256];
-        get_best_ip(lg, ip_str, sizeof(ip_str));
-        if (asprintf(&nout, "%s%s", *out, ip_str) < 0) {
-            htrace_log(lg, "handle_process_subst_var(var=%s): OOM", var);
-            return 0;
-        }
-        free(*out);
-        *out = nout;
-    } else if (strcmp(var, "%{pid}") == 0) {
-        char pid_str[64];
-        pid_t pid = getpid();
-
-        snprintf(pid_str, sizeof(pid_str), "%lld", (long long)pid);
-        if (asprintf(&nout, "%s%s", *out, pid_str) < 0) {
-            htrace_log(lg, "handle_process_subst_var(var=%s): OOM", var);
-            return 0;
-        }
-        free(*out);
-        *out = nout;
-    } else {
-        htrace_log(lg, "handle_process_subst_var(var=%s): unknown process "
-                   "ID substitution variable.\n", var);
-    }
-    return 1;
-}
-
-/**
- * Get the "best" IP address for this node.
- *
- * This is complicated since nodes can have multiple network interfaces,
- * and each network interface can have multiple IP addresses.  What we're
- * looking for here is an IP address that will serve to identify this node
- * to HTrace.  So we prefer site-local addresess (i.e. private ones on the
- * LAN) to publicly routable interfaces.  If there are multiple addresses
- * to choose from, we select the one which comes first in textual sort
- * order.  This should ensure that we at least consistently call each node
- * by a single name.
- */
-void get_best_ip(struct htrace_log *lg, char *ip_str, size_t ip_str_len)
-{
-    struct ifaddrs *head, *ifa;
-    enum ip_addr_type ty = ADDR_TYPE_IPV4_LOOPBACK, nty;
-    char temp_ip_str[128];
-
-    snprintf(ip_str, ip_str_len, "%s", "127.0.0.1");
-    if (getifaddrs(&head) < 0) {
-        int res = errno;
-        htrace_log(lg, "get_best_ip: getifaddrs failed: %s\n", terror(res));
-        return;
-    }
-    for (ifa = head; ifa; ifa = ifa->ifa_next){
-        if (!ifa->ifa_addr) {
-            continue;
-        }
-        if (ifa->ifa_addr->sa_family == AF_INET) {
-            struct sockaddr_in *addr =
-                (struct sockaddr_in *)ifa->ifa_addr;
-            nty = get_ipv4_addr_type(addr);
-            if (nty < ty) {
-                continue;
-            }
-            if (!inet_ntop(AF_INET, &addr->sin_addr, temp_ip_str,
-                           sizeof(temp_ip_str))) {
-                htrace_log(lg, "get_best_ip_impl: inet_ntop(%s, AF_INET) "
-                           "failed\n", ifa->ifa_name);
-                continue;
-            }
-            if ((nty == ty) && (strcmp(temp_ip_str, ip_str) > 0)) {
-                continue;
-            }
-            snprintf(ip_str, ip_str_len, "%s", temp_ip_str);
-            ty = nty;
-        } else if (ifa->ifa_addr->sa_family == AF_INET6) {
-            struct sockaddr_in6 *addr =
-                (struct sockaddr_in6 *)ifa->ifa_addr;
-            nty = get_ipv6_addr_type(addr);
-            if (nty < ty) {
-                continue;
-            }
-            if (!inet_ntop(AF_INET6, &addr->sin6_addr, temp_ip_str,
-                           sizeof(temp_ip_str))) {
-                htrace_log(lg, "get_best_ip_impl: inet_ntop(%s, AF_INET6) "
-                           "failed\n", ifa->ifa_name);
-                continue;
-            }
-            if ((nty == ty) && (strcmp(temp_ip_str, ip_str) > 0)) {
-                continue;
-            }
-            snprintf(ip_str, ip_str_len, "%s", temp_ip_str);
-            ty = nty;
-        }
-    }
-    freeifaddrs(head);
-}
-
-enum ip_addr_type get_ipv4_addr_type(const struct sockaddr_in *ip)
-{
-    union {
-        uint8_t b[4];
-        uint32_t addr;
-    } addr;
-    addr.addr = ip->sin_addr.s_addr; // always big-endian
-    if (addr.b[0] == 127) { // 127.0.0.0/24
-        return ADDR_TYPE_IPV4_LOOPBACK;
-    }
-    if ((addr.b[0] == 10) && (addr.b[1] == 0) && (addr.b[2] == 0)) {
-        return ADDR_TYPE_IPV4_SITE_LOCAL; // 10.0.0.0/8
-    }
-    if ((addr.b[0] == 192) && (addr.b[1] == 168)) {
-        return ADDR_TYPE_IPV4_SITE_LOCAL; // 192.168.0.0/16
-    }
-    if ((addr.b[0] == 172) && (addr.b[1] == 16) && ((addr.b[2] & 0xf0) == 0)) {
-        return ADDR_TYPE_IPV4_SITE_LOCAL; // 172.16.0.0/12
-    }
-    return ADDR_TYPE_IPV4_OTHER;
-}
-
-enum ip_addr_type get_ipv6_addr_type(const struct sockaddr_in6 *ip)
-{
-    if (IN6_IS_ADDR_LOOPBACK(ip)) {
-        return ADDR_TYPE_IPV6_LOOPBACK;
-    } else if (IN6_IS_ADDR_SITELOCAL(ip)) {
-        return ADDR_TYPE_IPV6_SITE_LOCAL;
-    } else {
-        return ADDR_TYPE_IPV6_OTHER;
-    }
-}
-
-// vim:ts=4:sw=4:et

http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/959a6ef0/htrace-c/src/util/process_id.h
----------------------------------------------------------------------
diff --git a/htrace-c/src/util/process_id.h b/htrace-c/src/util/process_id.h
deleted file mode 100644
index ff702ce..0000000
--- a/htrace-c/src/util/process_id.h
+++ /dev/null
@@ -1,58 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef APACHE_HTRACE_UTIL_PROCESS_ID_H
-#define APACHE_HTRACE_UTIL_PROCESS_ID_H
-
-#include <unistd.h> /* for size_t */
-
-/**
- * @file process_id.h
- *
- * Implements process IDs for the HTrace C client.
- *
- * This is an internal header, not intended for external use.
- */
-
-struct htrace_log;
-
-/**
- * Calculate the process ID.
- *
- * @param lg                A log object which will be used to report warnings.
- * @param fmt               The user-provided string to use when calculating the
- *                              process ID.
- * @param tname             The name supplied when creating the htracer.
- *
- * @return                  NULL on OOM; the process ID otherwise.
- */
-char *calculate_process_id(struct htrace_log *lg, const char *fmt,
-                           const char *tname);
-
-/**
- * Get the best IP address representing this host.
- *
- * @param lg                A log object which will be used to report warnings.
- * @param ip_str            (out param) output string
- * @param ip_str_len        Length of output string
- */
-void get_best_ip(struct htrace_log *lg, char *ip_str, size_t ip_str_len);
-
-#endif
-
-// vim: ts=4: sw=4: et

http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/959a6ef0/htrace-c/src/util/tracer_id.c
----------------------------------------------------------------------
diff --git a/htrace-c/src/util/tracer_id.c b/htrace-c/src/util/tracer_id.c
new file mode 100644
index 0000000..9d4812d
--- /dev/null
+++ b/htrace-c/src/util/tracer_id.c
@@ -0,0 +1,304 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "util/log.h"
+#include "util/tracer_id.h"
+
+#include <arpa/inet.h>
+#include <errno.h>
+#include <ifaddrs.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/socket.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+/**
+ * @file tracer_id.c
+ *
+ * Implements process IDs for the HTrace C client.
+ */
+
+/**
+ * The maximum number of bytes that can be in a process ID substitution
+ * variable.
+ */
+#define MAX_VAR_NAME 32
+
+enum ip_addr_type {
+    ADDR_TYPE_IPV6_LOOPBACK = 0,
+    ADDR_TYPE_IPV4_LOOPBACK,
+    ADDR_TYPE_IPV6_OTHER,
+    ADDR_TYPE_IPV4_OTHER,
+    ADDR_TYPE_IPV6_SITE_LOCAL,
+    ADDR_TYPE_IPV4_SITE_LOCAL
+};
+
+static int handle_process_subst_var(struct htrace_log *lg, char **out,
+                                    const char *var, const char *tname);
+
+enum ip_addr_type get_ipv4_addr_type(const struct sockaddr_in *ip);
+
+enum ip_addr_type get_ipv6_addr_type(const struct sockaddr_in6 *ip);
+
+static int append_char(char **out, int *j, char c)
+{
+    char *nout = realloc(*out, *j + 2); // leave space for NULL
+    if (!nout) {
+        return 0;
+    }
+    *out = nout;
+    (*out)[*j] = c;
+    *j = *j + 1;
+    (*out)[*j] = '\0';
+    return 1;
+}
+
+char *calculate_tracer_id(struct htrace_log *lg, const char *fmt,
+                           const char *tname)
+{
+    int i = 0, j = 0, escaping = 0, v = 0;
+    char *out = NULL, *var = NULL;
+
+    out = strdup("");
+    if (!out) {
+        goto oom;
+    }
+    while (1) {
+        char c = fmt[i++];
+        if (c == '\0') {
+            break;
+        } else if (c == '\\') {
+            if (!escaping) {
+                escaping = 1;
+                continue;
+            }
+        }
+        switch (v) {
+        case 0:
+            if (c == '%') {
+                if (!escaping) {
+                    if (!append_char(&var, &v, '%')) {
+                        goto oom;
+                    }
+                    continue;
+                }
+            }
+            break;
+        case 1:
+            if (c == '{') {
+                if (!escaping) {
+                    if (!append_char(&var, &v, '{')) {
+                        goto oom;
+                    }
+                    continue;
+                }
+            }
+            if (!append_char(&out, &j, '%')) {
+                goto oom;
+            }
+            break;
+        default:
+            if (c == '}') {
+                if (!escaping) {
+                    if (!append_char(&var, &v, '}')) {
+                        goto oom;
+                    }
+                    var[v++] = '\0';
+                    if (!handle_process_subst_var(lg, &out, var, tname)) {
+                        goto oom;
+                    }
+                    free(var);
+                    var = NULL;
+                    j = strlen(out);
+                    v = 0;
+                    continue;
+                }
+            }
+            escaping = 0;
+            if (!append_char(&var, &v, c)) {
+                goto oom;
+            }
+            continue;
+        }
+        escaping = 0;
+        v = 0;
+        if (!append_char(&out, &j, c)) {
+            goto oom;
+        }
+    }
+    out[j] = '\0';
+    if (v > 0) {
+      htrace_log(lg, "calculate_tracer_id(%s): unterminated process ID "
+                 "substitution variable at the end of the format string.",
+                 fmt);
+    }
+    free(var);
+    return out;
+
+oom:
+    htrace_log(lg, "calculate_tracer_id(tname=%s): OOM\n", tname);
+    free(out);
+    free(var);
+    return NULL;
+}
+
+static int handle_process_subst_var(struct htrace_log *lg, char **out,
+                                    const char *var, const char *tname)
+{
+    char *nout = NULL;
+
+    if (strcmp(var, "%{tname}") == 0) {
+        if (asprintf(&nout, "%s%s", *out, tname) < 0) {
+            htrace_log(lg, "handle_process_subst_var(var=%s): OOM", var);
+            return 0;
+        }
+        free(*out);
+        *out = nout;
+    } else if (strcmp(var, "%{ip}") == 0) {
+        char ip_str[256];
+        get_best_ip(lg, ip_str, sizeof(ip_str));
+        if (asprintf(&nout, "%s%s", *out, ip_str) < 0) {
+            htrace_log(lg, "handle_process_subst_var(var=%s): OOM", var);
+            return 0;
+        }
+        free(*out);
+        *out = nout;
+    } else if (strcmp(var, "%{pid}") == 0) {
+        char pid_str[64];
+        pid_t pid = getpid();
+
+        snprintf(pid_str, sizeof(pid_str), "%lld", (long long)pid);
+        if (asprintf(&nout, "%s%s", *out, pid_str) < 0) {
+            htrace_log(lg, "handle_process_subst_var(var=%s): OOM", var);
+            return 0;
+        }
+        free(*out);
+        *out = nout;
+    } else {
+        htrace_log(lg, "handle_process_subst_var(var=%s): unknown process "
+                   "ID substitution variable.\n", var);
+    }
+    return 1;
+}
+
+/**
+ * Get the "best" IP address for this node.
+ *
+ * This is complicated since nodes can have multiple network interfaces,
+ * and each network interface can have multiple IP addresses.  What we're
+ * looking for here is an IP address that will serve to identify this node
+ * to HTrace.  So we prefer site-local addresess (i.e. private ones on the
+ * LAN) to publicly routable interfaces.  If there are multiple addresses
+ * to choose from, we select the one which comes first in textual sort
+ * order.  This should ensure that we at least consistently call each node
+ * by a single name.
+ */
+void get_best_ip(struct htrace_log *lg, char *ip_str, size_t ip_str_len)
+{
+    struct ifaddrs *head, *ifa;
+    enum ip_addr_type ty = ADDR_TYPE_IPV4_LOOPBACK, nty;
+    char temp_ip_str[128];
+
+    snprintf(ip_str, ip_str_len, "%s", "127.0.0.1");
+    if (getifaddrs(&head) < 0) {
+        int res = errno;
+        htrace_log(lg, "get_best_ip: getifaddrs failed: %s\n", terror(res));
+        return;
+    }
+    for (ifa = head; ifa; ifa = ifa->ifa_next){
+        if (!ifa->ifa_addr) {
+            continue;
+        }
+        if (ifa->ifa_addr->sa_family == AF_INET) {
+            struct sockaddr_in *addr =
+                (struct sockaddr_in *)ifa->ifa_addr;
+            nty = get_ipv4_addr_type(addr);
+            if (nty < ty) {
+                continue;
+            }
+            if (!inet_ntop(AF_INET, &addr->sin_addr, temp_ip_str,
+                           sizeof(temp_ip_str))) {
+                htrace_log(lg, "get_best_ip_impl: inet_ntop(%s, AF_INET) "
+                           "failed\n", ifa->ifa_name);
+                continue;
+            }
+            if ((nty == ty) && (strcmp(temp_ip_str, ip_str) > 0)) {
+                continue;
+            }
+            snprintf(ip_str, ip_str_len, "%s", temp_ip_str);
+            ty = nty;
+        } else if (ifa->ifa_addr->sa_family == AF_INET6) {
+            struct sockaddr_in6 *addr =
+                (struct sockaddr_in6 *)ifa->ifa_addr;
+            nty = get_ipv6_addr_type(addr);
+            if (nty < ty) {
+                continue;
+            }
+            if (!inet_ntop(AF_INET6, &addr->sin6_addr, temp_ip_str,
+                           sizeof(temp_ip_str))) {
+                htrace_log(lg, "get_best_ip_impl: inet_ntop(%s, AF_INET6) "
+                           "failed\n", ifa->ifa_name);
+                continue;
+            }
+            if ((nty == ty) && (strcmp(temp_ip_str, ip_str) > 0)) {
+                continue;
+            }
+            snprintf(ip_str, ip_str_len, "%s", temp_ip_str);
+            ty = nty;
+        }
+    }
+    freeifaddrs(head);
+}
+
+enum ip_addr_type get_ipv4_addr_type(const struct sockaddr_in *ip)
+{
+    union {
+        uint8_t b[4];
+        uint32_t addr;
+    } addr;
+    addr.addr = ip->sin_addr.s_addr; // always big-endian
+    if (addr.b[0] == 127) { // 127.0.0.0/24
+        return ADDR_TYPE_IPV4_LOOPBACK;
+    }
+    if ((addr.b[0] == 10) && (addr.b[1] == 0) && (addr.b[2] == 0)) {
+        return ADDR_TYPE_IPV4_SITE_LOCAL; // 10.0.0.0/8
+    }
+    if ((addr.b[0] == 192) && (addr.b[1] == 168)) {
+        return ADDR_TYPE_IPV4_SITE_LOCAL; // 192.168.0.0/16
+    }
+    if ((addr.b[0] == 172) && (addr.b[1] == 16) && ((addr.b[2] & 0xf0) == 0)) {
+        return ADDR_TYPE_IPV4_SITE_LOCAL; // 172.16.0.0/12
+    }
+    return ADDR_TYPE_IPV4_OTHER;
+}
+
+enum ip_addr_type get_ipv6_addr_type(const struct sockaddr_in6 *ip)
+{
+    if (IN6_IS_ADDR_LOOPBACK(ip)) {
+        return ADDR_TYPE_IPV6_LOOPBACK;
+    } else if (IN6_IS_ADDR_SITELOCAL(ip)) {
+        return ADDR_TYPE_IPV6_SITE_LOCAL;
+    } else {
+        return ADDR_TYPE_IPV6_OTHER;
+    }
+}
+
+// vim:ts=4:sw=4:et

http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/959a6ef0/htrace-c/src/util/tracer_id.h
----------------------------------------------------------------------
diff --git a/htrace-c/src/util/tracer_id.h b/htrace-c/src/util/tracer_id.h
new file mode 100644
index 0000000..ccc0bbb
--- /dev/null
+++ b/htrace-c/src/util/tracer_id.h
@@ -0,0 +1,58 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef APACHE_HTRACE_UTIL_TRACER_ID_H
+#define APACHE_HTRACE_UTIL_TRACER_ID_H
+
+#include <unistd.h> /* for size_t */
+
+/**
+ * @file tracer_id.h
+ *
+ * Implements process IDs for the HTrace C client.
+ *
+ * This is an internal header, not intended for external use.
+ */
+
+struct htrace_log;
+
+/**
+ * Calculate the tracer ID.
+ *
+ * @param lg                A log object which will be used to report warnings.
+ * @param fmt               The user-provided string to use when calculating the
+ *                              tracer ID.
+ * @param tname             The name supplied when creating the htracer.
+ *
+ * @return                  NULL on OOM; the tracer ID otherwise.
+ */
+char *calculate_tracer_id(struct htrace_log *lg, const char *fmt,
+                           const char *tname);
+
+/**
+ * Get the best IP address representing this host.
+ *
+ * @param lg                A log object which will be used to report warnings.
+ * @param ip_str            (out param) output string
+ * @param ip_str_len        Length of output string
+ */
+void get_best_ip(struct htrace_log *lg, char *ip_str, size_t ip_str_len);
+
+#endif
+
+// vim: ts=4: sw=4: et

http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/959a6ef0/htrace-core/src/main/java/org/apache/htrace/Span.java
----------------------------------------------------------------------
diff --git a/htrace-core/src/main/java/org/apache/htrace/Span.java b/htrace-core/src/main/java/org/apache/htrace/Span.java
index b28ff8c..f41da30 100644
--- a/htrace-core/src/main/java/org/apache/htrace/Span.java
+++ b/htrace-core/src/main/java/org/apache/htrace/Span.java
@@ -134,12 +134,12 @@ public interface Span {
    *
    * Will never be null.
    */
-  String getProcessId();
+  String getTracerId();
 
   /**
    * Set the process id of a span.
    */
-  void setProcessId(String s);
+  void setTracerId(String s);
 
   /**
    * Serialize to Json
@@ -166,9 +166,9 @@ public interface Span {
       if (!span.getDescription().isEmpty()) {
         jgen.writeStringField("d", span.getDescription());
       }
-      String processId = span.getProcessId();
-      if (!processId.isEmpty()) {
-        jgen.writeStringField("r", processId);
+      String tracerId = span.getTracerId();
+      if (!tracerId.isEmpty()) {
+        jgen.writeStringField("r", tracerId);
       }
       jgen.writeArrayFieldStart("p");
       for (long parent : span.getParents()) {

http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/959a6ef0/htrace-core/src/main/java/org/apache/htrace/TraceTree.java
----------------------------------------------------------------------
diff --git a/htrace-core/src/main/java/org/apache/htrace/TraceTree.java b/htrace-core/src/main/java/org/apache/htrace/TraceTree.java
index 5edfde0..db781cb 100644
--- a/htrace-core/src/main/java/org/apache/htrace/TraceTree.java
+++ b/htrace-core/src/main/java/org/apache/htrace/TraceTree.java
@@ -99,7 +99,7 @@ public class TraceTree {
     }
   }
 
-  public static class SpansByProcessId {
+  public static class SpansByTracerId {
     /**
      * Compare two spans by process ID, and then by span ID.
      */
@@ -107,7 +107,7 @@ public class TraceTree {
         new Comparator<Span>() {
           @Override
           public int compare(Span a, Span b) {
-            int cmp = a.getProcessId().compareTo(b.getProcessId());
+            int cmp = a.getTracerId().compareTo(b.getTracerId());
             if (cmp != 0) {
               return cmp;
             } else if (a.getSpanId() < b.getSpanId()) {
@@ -122,7 +122,7 @@ public class TraceTree {
 
     private final TreeSet<Span> treeSet;
 
-    SpansByProcessId(Collection<Span> spans) {
+    SpansByTracerId(Collection<Span> spans) {
       TreeSet<Span> treeSet = new TreeSet<Span>(COMPARATOR);
       for (Span span : spans) {
         treeSet.add(span);
@@ -130,19 +130,19 @@ public class TraceTree {
       this.treeSet = treeSet;
     }
 
-    public List<Span> find(String processId) {
+    public List<Span> find(String tracerId) {
       List<Span> spans = new ArrayList<Span>();
       Span span = new MilliSpan.Builder().
                     traceId(Long.MIN_VALUE).
                     spanId(Long.MIN_VALUE).
-                    processId(processId).
+                    tracerId(tracerId).
                     build();
       while (true) {
         span = treeSet.higher(span);
         if (span == null) {
           break;
         }
-        if (span.getProcessId().equals(processId)) {
+        if (span.getTracerId().equals(tracerId)) {
           break;
         }
         spans.add(span);
@@ -156,7 +156,7 @@ public class TraceTree {
   }
 
   private final SpansByParent spansByParent;
-  private final SpansByProcessId spansByProcessId;
+  private final SpansByTracerId spansByTracerId;
 
   /**
    * Create a new TraceTree
@@ -166,15 +166,15 @@ public class TraceTree {
    */
   public TraceTree(Collection<Span> spans) {
     this.spansByParent = new SpansByParent(spans);
-    this.spansByProcessId = new SpansByProcessId(spans);
+    this.spansByTracerId = new SpansByTracerId(spans);
   }
 
   public SpansByParent getSpansByParent() {
     return spansByParent;
   }
 
-  public SpansByProcessId getSpansByProcessId() {
-    return spansByProcessId;
+  public SpansByTracerId getSpansByTracerId() {
+    return spansByTracerId;
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/959a6ef0/htrace-core/src/main/java/org/apache/htrace/impl/LocalFileSpanReceiver.java
----------------------------------------------------------------------
diff --git a/htrace-core/src/main/java/org/apache/htrace/impl/LocalFileSpanReceiver.java b/htrace-core/src/main/java/org/apache/htrace/impl/LocalFileSpanReceiver.java
index 95da72c..dfb701d 100644
--- a/htrace-core/src/main/java/org/apache/htrace/impl/LocalFileSpanReceiver.java
+++ b/htrace-core/src/main/java/org/apache/htrace/impl/LocalFileSpanReceiver.java
@@ -59,7 +59,7 @@ public class LocalFileSpanReceiver implements SpanReceiver {
   private final FileOutputStream stream;
   private final FileChannel channel;
   private final ReentrantLock channelLock = new ReentrantLock();
-  private final ProcessId processId;
+  private final TracerId tracerId;
 
   public LocalFileSpanReceiver(HTraceConfiguration conf) {
     int capacity = conf.getInt(CAPACITY_KEY, CAPACITY_DEFAULT);
@@ -94,7 +94,7 @@ public class LocalFileSpanReceiver implements SpanReceiver {
       LOG.debug("Created new LocalFileSpanReceiver with path = " + path +
                 ", capacity = " + capacity);
     }
-    this.processId = new ProcessId(conf);
+    this.tracerId = new TracerId(conf);
   }
 
   /**
@@ -137,8 +137,8 @@ public class LocalFileSpanReceiver implements SpanReceiver {
 
   @Override
   public void receiveSpan(Span span) {
-    if (span.getProcessId().isEmpty()) {
-      span.setProcessId(processId.get());
+    if (span.getTracerId().isEmpty()) {
+      span.setTracerId(tracerId.get());
     }
 
     // Serialize the span data into a byte[].  Note that we're not holding the

http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/959a6ef0/htrace-core/src/main/java/org/apache/htrace/impl/MilliSpan.java
----------------------------------------------------------------------
diff --git a/htrace-core/src/main/java/org/apache/htrace/impl/MilliSpan.java b/htrace-core/src/main/java/org/apache/htrace/impl/MilliSpan.java
index ffec117..3f6e700 100644
--- a/htrace-core/src/main/java/org/apache/htrace/impl/MilliSpan.java
+++ b/htrace-core/src/main/java/org/apache/htrace/impl/MilliSpan.java
@@ -62,7 +62,7 @@ public class MilliSpan implements Span {
   private long parents[];
   private final long spanId;
   private Map<String, String> traceInfo = null;
-  private String processId;
+  private String tracerId;
   private List<TimelineAnnotation> timeline = null;
 
   private static long nonZeroRandom64() {
@@ -83,7 +83,7 @@ public class MilliSpan implements Span {
       traceId(traceId).
       parents(new long[] {spanId}).
       spanId(nonZeroRandom64()).
-      processId(processId).
+      tracerId(tracerId).
       build();
   }
 
@@ -98,7 +98,7 @@ public class MilliSpan implements Span {
     private long parents[] = EMPTY_PARENT_ARRAY;
     private long spanId;
     private Map<String, String> traceInfo = null;
-    private String processId = EMPTY_STRING;
+    private String tracerId = EMPTY_STRING;
     private List<TimelineAnnotation> timeline = null;
 
     public Builder() {
@@ -148,8 +148,8 @@ public class MilliSpan implements Span {
       return this;
     }
 
-    public Builder processId(String processId) {
-      this.processId = processId;
+    public Builder tracerId(String tracerId) {
+      this.tracerId = tracerId;
       return this;
     }
 
@@ -171,7 +171,7 @@ public class MilliSpan implements Span {
     this.parents = EMPTY_PARENT_ARRAY;
     this.spanId = 0;
     this.traceInfo = null;
-    this.processId = EMPTY_STRING;
+    this.tracerId = EMPTY_STRING;
     this.timeline = null;
   }
 
@@ -183,7 +183,7 @@ public class MilliSpan implements Span {
     this.parents = builder.parents;
     this.spanId = builder.spanId;
     this.traceInfo = builder.traceInfo;
-    this.processId = builder.processId;
+    this.tracerId = builder.tracerId;
     this.timeline = builder.timeline;
   }
 
@@ -287,13 +287,13 @@ public class MilliSpan implements Span {
   }
 
   @Override
-  public String getProcessId() {
-    return processId;
+  public String getTracerId() {
+    return tracerId;
   }
 
   @Override
-  public void setProcessId(String processId) {
-    this.processId = processId;
+  public void setTracerId(String tracerId) {
+    this.tracerId = tracerId;
   }
 
   @Override
@@ -341,7 +341,7 @@ public class MilliSpan implements Span {
       }
       JsonNode rNode = root.get("r");
       if (rNode != null) {
-        builder.processId(rNode.asText());
+        builder.tracerId(rNode.asText());
       }
       JsonNode parentsNode = root.get("p");
       LinkedList<Long> parents = new LinkedList<Long>();

http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/959a6ef0/htrace-core/src/main/java/org/apache/htrace/impl/ProcessId.java
----------------------------------------------------------------------
diff --git a/htrace-core/src/main/java/org/apache/htrace/impl/ProcessId.java b/htrace-core/src/main/java/org/apache/htrace/impl/ProcessId.java
deleted file mode 100644
index a6a954d..0000000
--- a/htrace-core/src/main/java/org/apache/htrace/impl/ProcessId.java
+++ /dev/null
@@ -1,291 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.htrace.impl;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.htrace.HTraceConfiguration;
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.lang.management.ManagementFactory;
-import java.net.InetAddress;
-import java.net.NetworkInterface;
-import java.net.SocketException;
-import java.util.Enumeration;
-import java.util.Locale;
-import java.util.TreeSet;
-
-/**
- * The HTrace process ID.<p/>
- *
- * HTrace process IDs are created from format strings.
- * Format strings contain variables which the ProcessId class will
- * replace with the correct values at runtime.<p/>
- *
- * <ul>
- * <li>${ip}: will be replaced with an ip address.</li>
- * <li>${pname}: will be replaced the process name obtained from java.</li>
- * </ul><p/>
- *
- * For example, the string "${pname}/${ip}" will be replaced with something
- * like: DataNode/192.168.0.1, assuming that the process' name is DataNode
- * and its IP address is 192.168.0.1.<p/>
- *
- * Process ID strings can contain backslashes as escapes.
- * For example, "\a" will map to "a".  "\${ip}" will map to the literal
- * string "${ip}", not the IP address.  A backslash itself can be escaped by a
- * preceding backslash.
- */
-public final class ProcessId {
-  private static final Log LOG = LogFactory.getLog(ProcessId.class);
-
-  /**
-   * The configuration key to use for process id
-   */
-  public static final String PROCESS_ID_KEY = "process.id";
-
-  /**
-   * The default process ID to use if no other ID is configured.
-   */
-  private static final String DEFAULT_PROCESS_ID = "${pname}/${ip}";
-
-  private final String processId;
-
-  ProcessId(String fmt) {
-    StringBuilder bld = new StringBuilder();
-    StringBuilder varBld = null;
-    boolean escaping = false;
-    int varSeen = 0;
-    for (int i = 0, len = fmt.length() ; i < len; i++) {
-      char c = fmt.charAt(i);
-      if (c == '\\') {
-        if (!escaping) {
-          escaping = true;
-          continue;
-        }
-      }
-      switch (varSeen) {
-        case 0:
-          if (c == '$') {
-            if (!escaping) {
-              varSeen = 1;
-              continue;
-            }
-          }
-          escaping = false;
-          varSeen = 0;
-          bld.append(c);
-          break;
-        case 1:
-          if (c == '{') {
-            if (!escaping) {
-              varSeen = 2;
-              varBld = new StringBuilder();
-              continue;
-            }
-          }
-          escaping = false;
-          varSeen = 0;
-          bld.append("$").append(c);
-          break;
-        default:
-          if (c == '}') {
-            if (!escaping) {
-              String var = varBld.toString();
-              bld.append(processShellVar(var));
-              varBld = null;
-              varSeen = 0;
-              continue;
-            }
-          }
-          escaping = false;
-          varBld.append(c);
-          varSeen++;
-          break;
-      }
-    }
-    if (varSeen > 0) {
-      LOG.warn("Unterminated process ID substitution variable at the end " +
-          "of format string " + fmt);
-    }
-    this.processId = bld.toString();
-    if (LOG.isTraceEnabled()) {
-      LOG.trace("ProcessID(fmt=" + fmt + "): computed process ID of \"" +
-          this.processId + "\"");
-    }
-  }
-
-  public ProcessId(HTraceConfiguration conf) {
-    this(conf.get(PROCESS_ID_KEY, DEFAULT_PROCESS_ID));
-  }
-
-  private String processShellVar(String var) {
-    if (var.equals("pname")) {
-      return getProcessName();
-    } else if (var.equals("ip")) {
-      return getBestIpString();
-    } else if (var.equals("pid")) {
-      return Long.valueOf(getOsPid()).toString();
-    } else {
-      LOG.warn("unknown ProcessID variable " + var);
-      return "";
-    }
-  }
-
-  static String getProcessName() {
-    String cmdLine = System.getProperty("sun.java.command");
-    if (cmdLine != null && !cmdLine.isEmpty()) {
-      String fullClassName = cmdLine.split("\\s+")[0];
-      String[] classParts = fullClassName.split("\\.");
-      cmdLine = classParts[classParts.length - 1];
-    }
-    return (cmdLine == null || cmdLine.isEmpty()) ? "Unknown" : cmdLine;
-  }
-
-  /**
-   * Get the best IP address that represents this node.<p/>
-   *
-   * This is complicated since nodes can have multiple network interfaces,
-   * and each network interface can have multiple IP addresses.  What we're
-   * looking for here is an IP address that will serve to identify this node
-   * to HTrace.  So we prefer site-local addresess (i.e. private ones on the
-   * LAN) to publicly routable interfaces.  If there are multiple addresses
-   * to choose from, we select the one which comes first in textual sort
-   * order.  This should ensure that we at least consistently call each node
-   * by a single name.
-   */
-  static String getBestIpString() {
-    Enumeration<NetworkInterface> ifaces;
-    try {
-      ifaces = NetworkInterface.getNetworkInterfaces();
-    } catch (SocketException e) {
-      LOG.error("Error getting network interfaces", e);
-      return "127.0.0.1";
-    }
-    TreeSet<String> siteLocalCandidates = new TreeSet<String>();
-    TreeSet<String> candidates = new TreeSet<String>();
-    while (ifaces.hasMoreElements()) {
-      NetworkInterface iface = ifaces.nextElement();
-      for (Enumeration<InetAddress> addrs =
-               iface.getInetAddresses(); addrs.hasMoreElements();) {
-        InetAddress addr = addrs.nextElement();
-        if (!addr.isLoopbackAddress()) {
-          if (addr.isSiteLocalAddress()) {
-            siteLocalCandidates.add(addr.getHostAddress());
-          } else {
-            candidates.add(addr.getHostAddress());
-          }
-        }
-      }
-    }
-    if (!siteLocalCandidates.isEmpty()) {
-      return siteLocalCandidates.first();
-    }
-    if (!candidates.isEmpty()) {
-      return candidates.first();
-    }
-    return "127.0.0.1";
-  }
-
-  /**
-   * Get the process id from the operating system.<p/>
-   *
-   * Unfortunately, there is no simple method to get the process id in Java.
-   * The approach we take here is to use the shell method (see
-   * {ProcessId#getOsPidFromShellPpid}) unless we are on Windows, where the
-   * shell is not available.  On Windows, we use
-   * {ProcessId#getOsPidFromManagementFactory}, which depends on some
-   * undocumented features of the JVM, but which doesn't require a shell.
-   */
-  static long getOsPid() {
-    if ((System.getProperty("os.name", "generic").toLowerCase(Locale.ENGLISH)).
-        contains("windows")) {
-      return getOsPidFromManagementFactory();
-    } else {
-      return getOsPidFromShellPpid();
-    }
-  }
-
-  /**
-   * Get the process ID by executing a shell and printing the PPID (parent
-   * process ID).<p/>
-   *
-   * This method of getting the process ID doesn't depend on any undocumented
-   * features of the virtual machine, and should work on almost any UNIX
-   * operating system.
-   */
-  private static long getOsPidFromShellPpid() {
-    Process p = null;
-    StringBuilder sb = new StringBuilder();
-    try {
-      p = new ProcessBuilder("/usr/bin/env", "sh", "-c", "echo $PPID").
-        redirectErrorStream(true).start();
-      BufferedReader reader = new BufferedReader(
-          new InputStreamReader(p.getInputStream()));
-      String line = "";
-      while ((line = reader.readLine()) != null) {
-        sb.append(line.trim());
-      }
-      int exitVal = p.waitFor();
-      if (exitVal != 0) {
-        throw new IOException("Process exited with error code " +
-            Integer.valueOf(exitVal).toString());
-      }
-    } catch (InterruptedException e) {
-      LOG.error("Interrupted while getting operating system pid from " +
-          "the shell.", e);
-      return 0L;
-    } catch (IOException e) {
-      LOG.error("Error getting operating system pid from the shell.", e);
-      return 0L;
-    } finally {
-      if (p != null) {
-        p.destroy();
-      }
-    }
-    try {
-      return Long.parseLong(sb.toString());
-    } catch (NumberFormatException e) {
-      LOG.error("Error parsing operating system pid from the shell.", e);
-      return 0L;
-    }
-  }
-
-  /**
-   * Get the process ID by looking at the name of the managed bean for the
-   * runtime system of the Java virtual machine.<p/>
-   *
-   * Although this is undocumented, in the Oracle JVM this name is of the form
-   * [OS_PROCESS_ID]@[HOSTNAME].
-   */
-  private static long getOsPidFromManagementFactory() {
-    try {
-      return Long.parseLong(ManagementFactory.getRuntimeMXBean().
-          getName().split("@")[0]);
-    } catch (NumberFormatException e) {
-      LOG.error("Failed to get the operating system process ID from the name " +
-          "of the managed bean for the JVM.", e);
-      return 0L;
-    }
-  }
-
-  public String get() {
-    return processId;
-  }
-}

http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/959a6ef0/htrace-core/src/main/java/org/apache/htrace/impl/TracerId.java
----------------------------------------------------------------------
diff --git a/htrace-core/src/main/java/org/apache/htrace/impl/TracerId.java b/htrace-core/src/main/java/org/apache/htrace/impl/TracerId.java
new file mode 100644
index 0000000..83fa558
--- /dev/null
+++ b/htrace-core/src/main/java/org/apache/htrace/impl/TracerId.java
@@ -0,0 +1,291 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.htrace.impl;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.htrace.HTraceConfiguration;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.lang.management.ManagementFactory;
+import java.net.InetAddress;
+import java.net.NetworkInterface;
+import java.net.SocketException;
+import java.util.Enumeration;
+import java.util.Locale;
+import java.util.TreeSet;
+
+/**
+ * The HTrace tracer ID.<p/>
+ *
+ * HTrace tracer IDs are created from format strings.
+ * Format strings contain variables which the TracerId class will
+ * replace with the correct values at runtime.<p/>
+ *
+ * <ul>
+ * <li>${ip}: will be replaced with an ip address.</li>
+ * <li>${pname}: will be replaced the process name obtained from java.</li>
+ * </ul><p/>
+ *
+ * For example, the string "${pname}/${ip}" will be replaced with something
+ * like: DataNode/192.168.0.1, assuming that the process' name is DataNode
+ * and its IP address is 192.168.0.1.<p/>
+ *
+ * Process ID strings can contain backslashes as escapes.
+ * For example, "\a" will map to "a".  "\${ip}" will map to the literal
+ * string "${ip}", not the IP address.  A backslash itself can be escaped by a
+ * preceding backslash.
+ */
+public final class TracerId {
+  private static final Log LOG = LogFactory.getLog(TracerId.class);
+
+  /**
+   * The configuration key to use for process id
+   */
+  public static final String TRACER_ID_KEY = "process.id";
+
+  /**
+   * The default process ID to use if no other ID is configured.
+   */
+  private static final String DEFAULT_TRACER_ID = "${pname}/${ip}";
+
+  private final String tracerId;
+
+  TracerId(String fmt) {
+    StringBuilder bld = new StringBuilder();
+    StringBuilder varBld = null;
+    boolean escaping = false;
+    int varSeen = 0;
+    for (int i = 0, len = fmt.length() ; i < len; i++) {
+      char c = fmt.charAt(i);
+      if (c == '\\') {
+        if (!escaping) {
+          escaping = true;
+          continue;
+        }
+      }
+      switch (varSeen) {
+        case 0:
+          if (c == '$') {
+            if (!escaping) {
+              varSeen = 1;
+              continue;
+            }
+          }
+          escaping = false;
+          varSeen = 0;
+          bld.append(c);
+          break;
+        case 1:
+          if (c == '{') {
+            if (!escaping) {
+              varSeen = 2;
+              varBld = new StringBuilder();
+              continue;
+            }
+          }
+          escaping = false;
+          varSeen = 0;
+          bld.append("$").append(c);
+          break;
+        default:
+          if (c == '}') {
+            if (!escaping) {
+              String var = varBld.toString();
+              bld.append(processShellVar(var));
+              varBld = null;
+              varSeen = 0;
+              continue;
+            }
+          }
+          escaping = false;
+          varBld.append(c);
+          varSeen++;
+          break;
+      }
+    }
+    if (varSeen > 0) {
+      LOG.warn("Unterminated process ID substitution variable at the end " +
+          "of format string " + fmt);
+    }
+    this.tracerId = bld.toString();
+    if (LOG.isTraceEnabled()) {
+      LOG.trace("ProcessID(fmt=" + fmt + "): computed process ID of \"" +
+          this.tracerId + "\"");
+    }
+  }
+
+  public TracerId(HTraceConfiguration conf) {
+    this(conf.get(TRACER_ID_KEY, DEFAULT_TRACER_ID));
+  }
+
+  private String processShellVar(String var) {
+    if (var.equals("pname")) {
+      return getProcessName();
+    } else if (var.equals("ip")) {
+      return getBestIpString();
+    } else if (var.equals("pid")) {
+      return Long.valueOf(getOsPid()).toString();
+    } else {
+      LOG.warn("unknown ProcessID variable " + var);
+      return "";
+    }
+  }
+
+  static String getProcessName() {
+    String cmdLine = System.getProperty("sun.java.command");
+    if (cmdLine != null && !cmdLine.isEmpty()) {
+      String fullClassName = cmdLine.split("\\s+")[0];
+      String[] classParts = fullClassName.split("\\.");
+      cmdLine = classParts[classParts.length - 1];
+    }
+    return (cmdLine == null || cmdLine.isEmpty()) ? "Unknown" : cmdLine;
+  }
+
+  /**
+   * Get the best IP address that represents this node.<p/>
+   *
+   * This is complicated since nodes can have multiple network interfaces,
+   * and each network interface can have multiple IP addresses.  What we're
+   * looking for here is an IP address that will serve to identify this node
+   * to HTrace.  So we prefer site-local addresess (i.e. private ones on the
+   * LAN) to publicly routable interfaces.  If there are multiple addresses
+   * to choose from, we select the one which comes first in textual sort
+   * order.  This should ensure that we at least consistently call each node
+   * by a single name.
+   */
+  static String getBestIpString() {
+    Enumeration<NetworkInterface> ifaces;
+    try {
+      ifaces = NetworkInterface.getNetworkInterfaces();
+    } catch (SocketException e) {
+      LOG.error("Error getting network interfaces", e);
+      return "127.0.0.1";
+    }
+    TreeSet<String> siteLocalCandidates = new TreeSet<String>();
+    TreeSet<String> candidates = new TreeSet<String>();
+    while (ifaces.hasMoreElements()) {
+      NetworkInterface iface = ifaces.nextElement();
+      for (Enumeration<InetAddress> addrs =
+               iface.getInetAddresses(); addrs.hasMoreElements();) {
+        InetAddress addr = addrs.nextElement();
+        if (!addr.isLoopbackAddress()) {
+          if (addr.isSiteLocalAddress()) {
+            siteLocalCandidates.add(addr.getHostAddress());
+          } else {
+            candidates.add(addr.getHostAddress());
+          }
+        }
+      }
+    }
+    if (!siteLocalCandidates.isEmpty()) {
+      return siteLocalCandidates.first();
+    }
+    if (!candidates.isEmpty()) {
+      return candidates.first();
+    }
+    return "127.0.0.1";
+  }
+
+  /**
+   * Get the process id from the operating system.<p/>
+   *
+   * Unfortunately, there is no simple method to get the process id in Java.
+   * The approach we take here is to use the shell method (see
+   * {TracerId#getOsPidFromShellPpid}) unless we are on Windows, where the
+   * shell is not available.  On Windows, we use
+   * {TracerId#getOsPidFromManagementFactory}, which depends on some
+   * undocumented features of the JVM, but which doesn't require a shell.
+   */
+  static long getOsPid() {
+    if ((System.getProperty("os.name", "generic").toLowerCase(Locale.ENGLISH)).
+        contains("windows")) {
+      return getOsPidFromManagementFactory();
+    } else {
+      return getOsPidFromShellPpid();
+    }
+  }
+
+  /**
+   * Get the process ID by executing a shell and printing the PPID (parent
+   * process ID).<p/>
+   *
+   * This method of getting the process ID doesn't depend on any undocumented
+   * features of the virtual machine, and should work on almost any UNIX
+   * operating system.
+   */
+  private static long getOsPidFromShellPpid() {
+    Process p = null;
+    StringBuilder sb = new StringBuilder();
+    try {
+      p = new ProcessBuilder("/usr/bin/env", "sh", "-c", "echo $PPID").
+        redirectErrorStream(true).start();
+      BufferedReader reader = new BufferedReader(
+          new InputStreamReader(p.getInputStream()));
+      String line = "";
+      while ((line = reader.readLine()) != null) {
+        sb.append(line.trim());
+      }
+      int exitVal = p.waitFor();
+      if (exitVal != 0) {
+        throw new IOException("Process exited with error code " +
+            Integer.valueOf(exitVal).toString());
+      }
+    } catch (InterruptedException e) {
+      LOG.error("Interrupted while getting operating system pid from " +
+          "the shell.", e);
+      return 0L;
+    } catch (IOException e) {
+      LOG.error("Error getting operating system pid from the shell.", e);
+      return 0L;
+    } finally {
+      if (p != null) {
+        p.destroy();
+      }
+    }
+    try {
+      return Long.parseLong(sb.toString());
+    } catch (NumberFormatException e) {
+      LOG.error("Error parsing operating system pid from the shell.", e);
+      return 0L;
+    }
+  }
+
+  /**
+   * Get the process ID by looking at the name of the managed bean for the
+   * runtime system of the Java virtual machine.<p/>
+   *
+   * Although this is undocumented, in the Oracle JVM this name is of the form
+   * [OS_PROCESS_ID]@[HOSTNAME].
+   */
+  private static long getOsPidFromManagementFactory() {
+    try {
+      return Long.parseLong(ManagementFactory.getRuntimeMXBean().
+          getName().split("@")[0]);
+    } catch (NumberFormatException e) {
+      LOG.error("Failed to get the operating system process ID from the name " +
+          "of the managed bean for the JVM.", e);
+      return 0L;
+    }
+  }
+
+  public String get() {
+    return tracerId;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/959a6ef0/htrace-core/src/test/java/org/apache/htrace/impl/TestLocalFileSpanReceiver.java
----------------------------------------------------------------------
diff --git a/htrace-core/src/test/java/org/apache/htrace/impl/TestLocalFileSpanReceiver.java b/htrace-core/src/test/java/org/apache/htrace/impl/TestLocalFileSpanReceiver.java
index 634bef8..311ddc6 100644
--- a/htrace-core/src/test/java/org/apache/htrace/impl/TestLocalFileSpanReceiver.java
+++ b/htrace-core/src/test/java/org/apache/htrace/impl/TestLocalFileSpanReceiver.java
@@ -57,7 +57,7 @@ public class TestLocalFileSpanReceiver {
     confMap.put(LocalFileSpanReceiver.PATH_KEY, traceFileName);
     confMap.put(SpanReceiverBuilder.SPAN_RECEIVER_CONF_KEY,
                 LocalFileSpanReceiver.class.getName());
-    confMap.put(ProcessId.PROCESS_ID_KEY, "testPid");
+    confMap.put(TracerId.TRACER_ID_KEY, "testTrid");
     SpanReceiver rcvr =
         new SpanReceiverBuilder(HTraceConfiguration.fromMap(confMap))
             .logErrors(false).build();
@@ -70,6 +70,6 @@ public class TestLocalFileSpanReceiver {
     ObjectMapper mapper = new ObjectMapper();
     MilliSpan span = mapper.readValue(new File(traceFileName), MilliSpan.class);
     assertEquals("testWriteToLocalFile", span.getDescription());
-    assertEquals("testPid", span.getProcessId());
+    assertEquals("testTrid", span.getTracerId());
   }
 }

http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/959a6ef0/htrace-core/src/test/java/org/apache/htrace/impl/TestMilliSpan.java
----------------------------------------------------------------------
diff --git a/htrace-core/src/test/java/org/apache/htrace/impl/TestMilliSpan.java b/htrace-core/src/test/java/org/apache/htrace/impl/TestMilliSpan.java
index 2e0edde..74ee562 100644
--- a/htrace-core/src/test/java/org/apache/htrace/impl/TestMilliSpan.java
+++ b/htrace-core/src/test/java/org/apache/htrace/impl/TestMilliSpan.java
@@ -39,7 +39,7 @@ public class TestMilliSpan {
     assertEquals(expected.getDescription(), got.getDescription());
     assertEquals(expected.getTraceId(), got.getTraceId());
     assertEquals(expected.getSpanId(), got.getSpanId());
-    assertEquals(expected.getProcessId(), got.getProcessId());
+    assertEquals(expected.getTracerId(), got.getTracerId());
     assertTrue(Arrays.equals(expected.getParents(), got.getParents()));
     Map<String, String> expectedT = expected.getKVAnnotations();
     Map<String, String> gotT = got.getKVAnnotations();
@@ -75,7 +75,7 @@ public class TestMilliSpan {
         begin(123L).
         end(456L).
         parents(new long[] { 7L }).
-        processId("b2404.halxg.com:8080").
+        tracerId("b2404.halxg.com:8080").
         spanId(989L).
         traceId(444).build();
     String json = span.toJson();
@@ -90,7 +90,7 @@ public class TestMilliSpan {
         begin(-1L).
         end(-1L).
         parents(new long[] { -1L }).
-        processId("b2404.halxg.com:8080").
+        tracerId("b2404.halxg.com:8080").
         spanId(-1L).
         traceId(-1L).build();
     String json = span.toJson();
@@ -106,7 +106,7 @@ public class TestMilliSpan {
         begin(random.nextLong()).
         end(random.nextLong()).
         parents(new long[] { random.nextLong() }).
-        processId("b2404.halxg.com:8080").
+        tracerId("b2404.halxg.com:8080").
         spanId(random.nextLong()).
         traceId(random.nextLong()).build();
     String json = span.toJson();
@@ -121,7 +121,7 @@ public class TestMilliSpan {
         begin(300).
         end(400).
         parents(new long[] { }).
-        processId("b2408.halxg.com:8080").
+        tracerId("b2408.halxg.com:8080").
         spanId(111111111L).
         traceId(4443);
     Map<String, String> traceInfo = new HashMap<String, String>();