Add event capturing to monitoring services
Updated the monitoring services - baselime-server and sentry-server, to capture specific events. This includes modifications in their respective fetch methods for logging these events. Also, expanded the core monitoring service to allow for event tracking.
This commit is contained in:
@@ -31,7 +31,7 @@ export class BaselimeServerMonitoringService implements MonitoringService {
|
||||
message: error ? `${error.name}: ${error.message}` : `Unknown error`,
|
||||
};
|
||||
|
||||
const response = await fetch(`https://events.baselime.io/v1/web`, {
|
||||
const response = await fetch(`https://events.baselime.io/v1/logs`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
contentType: 'application/json',
|
||||
@@ -60,6 +60,42 @@ export class BaselimeServerMonitoringService implements MonitoringService {
|
||||
}
|
||||
}
|
||||
|
||||
async captureEvent<
|
||||
Extra extends {
|
||||
sessionId?: string;
|
||||
namespace?: string;
|
||||
service?: string;
|
||||
},
|
||||
>(event: string, extra?: Extra) {
|
||||
const response = await fetch(`https://events.baselime.io/v1/logs`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
contentType: 'application/json',
|
||||
'x-api-key': apiKey,
|
||||
'x-service': extra?.service ?? '',
|
||||
'x-namespace': extra?.namespace ?? '',
|
||||
},
|
||||
body: JSON.stringify([
|
||||
{
|
||||
userId: this.userId,
|
||||
sessionId: extra?.sessionId,
|
||||
namespace: extra?.namespace,
|
||||
message: event,
|
||||
},
|
||||
]),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
console.error(
|
||||
{
|
||||
response,
|
||||
event,
|
||||
},
|
||||
'Failed to send event to Baselime',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
identifyUser<Info extends { id: string }>(info: Info) {
|
||||
this.userId = info.id;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user