Skip to content
Merged
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
21 changes: 18 additions & 3 deletions glean/src/core/metrics/types/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ export class InternalEventMetricType<
return;
}

const ts = Date.now();

try {
// Create metric here, in order to run the validations and throw in case input in invalid.
const metric = new RecordedEvent({
Expand All @@ -59,9 +61,8 @@ export class InternalEventMetricType<
});

// Truncate the extra keys, if needed.
let truncatedExtra: ExtraMap | undefined = undefined;
const truncatedExtra: ExtraMap = {};
if (extra && this.allowedExtraKeys) {
truncatedExtra = {};
for (const [name, value] of Object.entries(extra)) {
if (this.allowedExtraKeys.includes(name)) {
if (isString(value)) {
Expand All @@ -84,6 +85,8 @@ export class InternalEventMetricType<
}
}

// Glean wall-clock timestamp added to all events
truncatedExtra["glean_timestamp"] = ts.toString();
metric.set({
...metric.get(),
extra: truncatedExtra
Expand Down Expand Up @@ -111,7 +114,19 @@ export class InternalEventMetricType<
*/
testGetValue(ping: string = this.sendInPings[0]): Event[] | undefined {
if (testOnlyCheck("testGetValue", LOG_TAG)) {
return Context.eventsDatabase.getEvents(ping, this);
const events = Context.eventsDatabase.getEvents(ping, this);
if (!events) return events;

events.forEach((ev) => {
if (ev.extra) {
delete ev.extra["glean_timestamp"];
if (Object.keys(ev.extra).length == 0) {
ev.extra = undefined;
}
}
});

return events;
}
}
}
Expand Down