@@ -14,6 +14,7 @@ interface Params {
1414 requestSize ?: number ;
1515 responseSize ?: number ;
1616 userAgent ?: string ;
17+ ip ?: string ;
1718 apilyticsIntegration ?: string ;
1819 integratedLibrary ?: string ;
1920}
@@ -38,6 +39,8 @@ interface Params {
3839 * @param params.responseSize - Size of the sent HTTP response's body in bytes.
3940 * @param params.userAgent - Value of the `User-Agent` header from the user's
4041 * HTTP request.
42+ * @param params.ip - User's IP address (used for geolocation,
43+ * never stored nor sent to 3rd parties).
4144 * @param params.apilyticsIntegration - Name of the Apilytics integration that's
4245 * calling this, e.g. 'apilytics-node-express'.
4346 * No need to pass this when calling from user code.
@@ -49,6 +52,7 @@ interface Params {
4952 *
5053 * const timer = milliSecondTimer();
5154 * const res = await handler(req);
55+ *
5256 * sendApilyticsMetrics({
5357 * apikey: "<your-api-key>",
5458 * path: req.path,
@@ -58,6 +62,7 @@ interface Params {
5862 * requestSize: req.bodyBytes.length,
5963 * responseSize: res.bodyBytes.length,
6064 * userAgent: req.headers['user-agent'],
65+ * ip: req.headers['x-forwarded-for']?.split(',')[0].trim(),
6166 * timeMillis: timer(),
6267 * });
6368 */
@@ -71,6 +76,7 @@ export const sendApilyticsMetrics = ({
7176 requestSize,
7277 responseSize,
7378 userAgent,
79+ ip,
7480 apilyticsIntegration,
7581 integratedLibrary,
7682} : Params ) : void => {
@@ -86,6 +92,7 @@ export const sendApilyticsMetrics = ({
8692 requestSize,
8793 responseSize,
8894 userAgent : userAgent || undefined ,
95+ ip : ip || undefined ,
8996 cpuUsage,
9097 memoryUsage,
9198 memoryTotal,
0 commit comments