title: Logging proper user ip behind a reverse proxy in GAE
body: <p>I'm using cloudflare as a reverse proxy in front of AppEngine. Hence, in GCP Logging request log, the IP being logged is Cloudflare's.</p>
  <p>Behind cloudflare, the actual user IP is <code>req.headers['x-forwarded-for'].split(',')[0]</code>, so I've been trying to work through <a href="https://github.com/googleapis/nodejs-logging-winston" rel="nofollow noreferrer">Google Logging</a> log correlation to get it right (in an express middleware):</p>
  <pre><code>const forwardedForHeader = req.headers['x-forwarded-for']
  const userIp = forwardedForHeader ? forwardedForHeader.split(',')[0] : req.ip
  res.on('finish', () =&gt; {
      logger.info(req.originalUrl, {
          httpRequest: {
              status: res.statusCode,
              requestUrl: req.originalUrl,
              requestMethod: req.method,
              remoteIp: userIp,
          },
          remoteIp: userIp, // workaround to get remote IP as metadata - GAE has everything else
      })
  })
  </code></pre>
  <p><code>LOGGING_SPAN_KEY</code> &amp; <code>LOGGING_TRACE_KEY</code> are both set properly.</p>
  <p>Unfortunately, I'm still getting 2 log entries (GAE generated 1 in request log; mine generated as above).</p>
  <p>Is there any way to get the actual user ip in the request log ?</p>