From 2b04ebc4f3656d49170c3bdc2abea40f4952b3d8 Mon Sep 17 00:00:00 2001 From: David Bosschaert Date: Fri, 10 May 2024 14:25:39 +0100 Subject: [PATCH 1/2] Debug potential bot --- src/utils.mjs | 5 +++++ test/utils.test.mjs | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/src/utils.mjs b/src/utils.mjs index 186d433..a9302cf 100644 --- a/src/utils.mjs +++ b/src/utils.mjs @@ -141,6 +141,11 @@ export function getMaskedUserAgent(headers) { return `bot${getBotType(lcUA)}`; } + if (userAgent === 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36') { + // This might be a bot, let's see if we can find more information. + console.log('Potential bot:', headers); + } + return `desktop${getDesktopOS(lcUA)}`; } diff --git a/test/utils.test.mjs b/test/utils.test.mjs index 1c97093..fbee6de 100644 --- a/test/utils.test.mjs +++ b/test/utils.test.mjs @@ -151,4 +151,11 @@ describe('Test Utils', () => { headers, })); }); + + it('Debug potential bot', () => { + const headers = new Map(); + headers.set('user-agent', 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36'); + headers.set('foo', 'bar'); + assert.equal('desktop:linux', getMaskedUserAgent(headers)); + }); }); From c8e681e5a2116e13db795ec2c5e3bd2a5e93695c Mon Sep 17 00:00:00 2001 From: David Bosschaert Date: Fri, 10 May 2024 14:44:14 +0100 Subject: [PATCH 2/2] Dump to Coralogix --- src/coralogix-logger.mjs | 8 +++++++- src/utils.mjs | 5 ----- test/coralogix-logger.test.mjs | 17 +++++++++++++++++ test/utils.test.mjs | 7 ------- 4 files changed, 24 insertions(+), 13 deletions(-) diff --git a/src/coralogix-logger.mjs b/src/coralogix-logger.mjs index 666a530..6e028d2 100644 --- a/src/coralogix-logger.mjs +++ b/src/coralogix-logger.mjs @@ -79,8 +79,14 @@ export class CoralogixLogger { }), }; console.log('ready to log (coralogix)'); - // console.log(JSON.stringify(data)); + this.logger.log(JSON.stringify(data)); + + if (this.req.headers.get('user-agent') === 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36') { + // This might be a bot, let's see if we can find more information. + this.logger.log(JSON.stringify(Object.fromEntries(this.req.headers))); + } + console.log('done'); } } diff --git a/src/utils.mjs b/src/utils.mjs index a9302cf..186d433 100644 --- a/src/utils.mjs +++ b/src/utils.mjs @@ -141,11 +141,6 @@ export function getMaskedUserAgent(headers) { return `bot${getBotType(lcUA)}`; } - if (userAgent === 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36') { - // This might be a bot, let's see if we can find more information. - console.log('Potential bot:', headers); - } - return `desktop${getDesktopOS(lcUA)}`; } diff --git a/test/coralogix-logger.test.mjs b/test/coralogix-logger.test.mjs index bf5781d..ee18582 100644 --- a/test/coralogix-logger.test.mjs +++ b/test/coralogix-logger.test.mjs @@ -71,4 +71,21 @@ describe('Test Coralogix Logger', () => { assert.equal('bar', loggedJSON.rum.foo); assert.equal(777, loggedJSON.rum.zoo); }); + + it('Debug potential bot', () => { + const headers = new Map(); + headers.set('user-agent', 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36'); + headers.set('foo', 'bar'); + + const method = 'GET'; + const url = new URL('http://www.foo.com/testing123'); + + const req = { headers, method, url }; + const cl = new CoralogixLogger(req); + + cl.logRUM({}); + + const logged = JSON.parse(lastLogMessage); + assert.equal('bar', logged.foo); + }); }); diff --git a/test/utils.test.mjs b/test/utils.test.mjs index fbee6de..1c97093 100644 --- a/test/utils.test.mjs +++ b/test/utils.test.mjs @@ -151,11 +151,4 @@ describe('Test Utils', () => { headers, })); }); - - it('Debug potential bot', () => { - const headers = new Map(); - headers.set('user-agent', 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36'); - headers.set('foo', 'bar'); - assert.equal('desktop:linux', getMaskedUserAgent(headers)); - }); });