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

Send timestamp in "dt" field to be accepted by Better Stack #21

Merged
merged 4 commits into from
Nov 26, 2024
Merged
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
4 changes: 2 additions & 2 deletions src/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export class Logger {
}
const logEvent: LogEvent = { level, message, _time: new Date(Date.now()).toISOString(), fields: this.args || {} };

// check if passed args is an object, if its not an object, add it to fields.args
// check if passed args is an object, if it's not an object, add it to fields.args
if (args instanceof Error) {
logEvent.fields = { ...logEvent.fields, message: args.message, stack: args.stack, name: args.name };
} else if (typeof args === 'object' && args !== null && Object.keys(args).length > 0) {
Expand Down Expand Up @@ -139,7 +139,7 @@ export class Logger {

const method = 'POST';
const keepalive = true;
const body = JSON.stringify(this.logEvents);
const body = JSON.stringify(this.logEvents.map((event) => ({ dt: event._time, ...event })));
// clear pending logs
this.logEvents = [];
const headers = {
Expand Down
16 changes: 9 additions & 7 deletions src/platform/generic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default class GenericConfig implements Provider {
shouldSendEdgeReport = false;
token = process.env.LOGTAIL_SOURCE_TOKEN;
environment: string = process.env.NODE_ENV;
logtailUrl = process.env.LOGTAIL_URL || 'https://in.logtail.com';
logtailUrl = process.env.LOGTAIL_URL || 'https://in.logs.betterstack.com';
region = process.env.REGION || undefined;

isEnvVarsSet(): boolean {
Expand Down Expand Up @@ -43,13 +43,15 @@ export default class GenericConfig implements Provider {
}

wrapWebVitalsObject(metrics: any[]): any {
const time = new Date().getTime();
return metrics.map(m => ({
webVital: m,
_time: new Date().getTime(),
platform: {
environment: this.environment,
source: 'web-vital',
},
webVital: m,
dt: time,
_time: time,
platform: {
environment: this.environment,
source: 'web-vital',
},
}))
}

Expand Down
22 changes: 12 additions & 10 deletions src/platform/netlify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,20 @@ export interface NetlifyInfo extends PlatformInfo {
export default class NetlifyConfig extends GenericConfig implements Provider {

wrapWebVitalsObject(metrics: any[]): any {
const time = new Date().getTime();
return metrics.map(m => ({
webVital: m,
_time: new Date().getTime(),
netlify: {
environment: this.environment,
source: 'web-vital',
siteId: netlifySiteId,
buildId: netlifyBuildId,
context: netlifyContext,
deploymentUrl: netlifyDeploymentUrl,
deploymentId: netlifyDeploymentId,
},
dt: time,
_time: time,
netlify: {
environment: this.environment,
source: 'web-vital',
siteId: netlifySiteId,
buildId: netlifyBuildId,
context: netlifyContext,
deploymentUrl: netlifyDeploymentUrl,
deploymentId: netlifyDeploymentId,
},
}))
}

Expand Down