mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-09-21 15:56:10 +08:00
[*] metrics(Part 6) MetricsReporter.reportEvent now requires a nylasId
Summary: This will help us aggregate metrics by user. This also makes it so we don't report events in dev mode Test Plan: manual Reviewers: spang, evan Reviewed By: spang, evan Differential Revision: https://phab.nylas.com/D3981
This commit is contained in:
parent
39c6c04bc4
commit
9f78574c3d
|
@ -10,6 +10,7 @@ const {
|
|||
APIError,
|
||||
NylasAPI,
|
||||
N1CloudAPI,
|
||||
IdentityStore,
|
||||
NylasAPIRequest,
|
||||
BatteryStatusManager,
|
||||
Account: {SYNC_STATE_RUNNING, SYNC_STATE_AUTH_FAILED, SYNC_STATE_ERROR},
|
||||
|
@ -62,19 +63,23 @@ class SyncWorker {
|
|||
// TODO extract this into its own module, can use later on for exchange
|
||||
let seen = 0;
|
||||
db.Thread.addHook('afterCreate', 'metricsCollection', () => {
|
||||
const identity = IdentityStore.identity()
|
||||
const nylasId = identity ? identity.id : null;
|
||||
if (seen === 0) {
|
||||
MetricsReporter.reportEvent({
|
||||
nylasId,
|
||||
type: 'imap',
|
||||
provider: account.provider,
|
||||
accountId: account.id,
|
||||
emailAddress: account.emailAddress,
|
||||
msecToFirstThread: (Date.now() - new Date(account.createdAt).getTime()),
|
||||
})
|
||||
}
|
||||
if (seen === 500) {
|
||||
MetricsReporter.reportEvent({
|
||||
nylasId,
|
||||
type: 'imap',
|
||||
provider: account.provider,
|
||||
accountId: account.id,
|
||||
emailAddress: account.emailAddress,
|
||||
msecToFirst500Threads: (Date.now() - new Date(account.createdAt).getTime()),
|
||||
})
|
||||
}
|
||||
|
|
|
@ -36,8 +36,8 @@ class MetricsReporter {
|
|||
}
|
||||
|
||||
async reportEvent(info) {
|
||||
if (!info.accountId) {
|
||||
throw new Error("Metrics Reporter: You must include an accountId");
|
||||
if (!info.nylasId) {
|
||||
throw new Error("Metrics Reporter: You must include an nylasId");
|
||||
}
|
||||
const logger = global.Logger.child({accountEmail: info.emailAddress})
|
||||
const {workingSetSize, privateBytes, sharedBytes} = process.getProcessMemoryInfo();
|
||||
|
@ -53,6 +53,11 @@ class MetricsReporter {
|
|||
|
||||
try {
|
||||
if (isClientEnv()) {
|
||||
if (NylasEnv.inDevMode()) { return }
|
||||
if (!info.accountId) {
|
||||
throw new Error("Metrics Reporter: You must include an accountId");
|
||||
}
|
||||
|
||||
const {N1CloudAPI, NylasAPIRequest} = require('nylas-exports') // eslint-disable-line
|
||||
const req = new NylasAPIRequest({
|
||||
api: N1CloudAPI,
|
||||
|
@ -67,8 +72,8 @@ class MetricsReporter {
|
|||
} else {
|
||||
this.sendToHoneycomb(info)
|
||||
}
|
||||
} catch (err) {
|
||||
logger.log(info, "Metrics Reporter: Submitted.", info);
|
||||
} catch (err) {
|
||||
logger.warn("Metrics Reporter: Submission Failed.", {error: err, ...info});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue