From 1f724ecff66319194bd219c58f1160aca4eb8e33 Mon Sep 17 00:00:00 2001
From: Lloyd Hilaiel <lloyd@hilaiel.com>
Date: Mon, 10 Oct 2011 11:55:01 -0600
Subject: [PATCH] log x-real-ip rather than remote ip in metrics stuff to get
 the proper ip in anonymous metrics logs.  closes #391

---
 libs/metrics.js | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/libs/metrics.js b/libs/metrics.js
index 22e4c0330..8d04b805c 100644
--- a/libs/metrics.js
+++ b/libs/metrics.js
@@ -108,10 +108,13 @@ exports.report = function(type, entry) {
 
 // utility function to log a bunch of stuff at user entry point
 exports.userEntry = function(req) {
+  var ipAddress = req.connection.remoteAddress;
+  if (req.headers['x-real-ip']) ipAddress = req.headers['x-real-ip'];
+
   exports.report('signin', {
     browser: req.headers['user-agent'],
     rp: req.headers['referer'],
     // IP address (this probably needs to be replaced with the X-forwarded-for value
-    ip: req.connection.remoteAddress
+    ip: ipAddress
   });
 };
-- 
GitLab