Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debug potential bot #312

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/coralogix-logger.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}
17 changes: 17 additions & 0 deletions test/coralogix-logger.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
Loading