fix(metrics): fix the data on email sent events
https://github.com/mozilla/fxa-auth-server/pull/2139 r=rfk
This commit is contained in:
Родитель
5990da6aae
Коммит
4f6f367f5e
|
@ -75,10 +75,10 @@ function logEmailEventSent(log, message) {
|
||||||
const emailEventInfo = {
|
const emailEventInfo = {
|
||||||
op: 'emailEvent',
|
op: 'emailEvent',
|
||||||
template: message.template,
|
template: message.template,
|
||||||
type: 'sent'
|
type: 'sent',
|
||||||
|
flow_id: message.flowId
|
||||||
}
|
}
|
||||||
|
|
||||||
emailEventInfo['flow_id'] = getHeaderValue('X-Flow-Id', message)
|
|
||||||
emailEventInfo.locale = getHeaderValue('Content-Language', message)
|
emailEventInfo.locale = getHeaderValue('Content-Language', message)
|
||||||
|
|
||||||
const addrs = [message.email].concat(message.ccEmails || [])
|
const addrs = [message.email].concat(message.ccEmails || [])
|
||||||
|
@ -112,11 +112,12 @@ function logAmplitudeEvent (log, message, eventInfo) {
|
||||||
query: {},
|
query: {},
|
||||||
payload: {}
|
payload: {}
|
||||||
}, {
|
}, {
|
||||||
device_id: getHeaderValue('X-Device-Id', message),
|
device_id: message.deviceId || getHeaderValue('X-Device-Id', message),
|
||||||
email_domain: eventInfo.domain,
|
email_domain: eventInfo.domain,
|
||||||
service: getHeaderValue('X-Service-Id', message),
|
service: message.service || getHeaderValue('X-Service-Id', message),
|
||||||
uid: getHeaderValue('X-Uid', message)
|
uid: message.uid || getHeaderValue('X-Uid', message)
|
||||||
}, {
|
}, {
|
||||||
|
flowBeginTime: message.flowBeginTime || getHeaderValue('X-Flow-Begin-Time', message),
|
||||||
flow_id: eventInfo.flow_id,
|
flow_id: eventInfo.flow_id,
|
||||||
time: Date.now()
|
time: Date.now()
|
||||||
})
|
})
|
||||||
|
|
|
@ -87,12 +87,13 @@ describe('email utils helpers', () => {
|
||||||
ccEmails: [ 'bar@example.com', 'baz@example.com' ],
|
ccEmails: [ 'bar@example.com', 'baz@example.com' ],
|
||||||
template: 'verifyEmail',
|
template: 'verifyEmail',
|
||||||
headers: [
|
headers: [
|
||||||
{ name: 'Content-Language', value: 'aaa' },
|
{ name: 'Content-Language', value: 'aaa' }
|
||||||
{ name: 'X-Device-Id', value: 'bbb' },
|
],
|
||||||
{ name: 'X-Flow-Id', value: 'ccc' },
|
deviceId: 'bbb',
|
||||||
{ name: 'X-Service-Id', value: 'ddd' },
|
flowBeginTime: 42,
|
||||||
{ name: 'X-Uid', value: 'eee' }
|
flowId: 'ccc',
|
||||||
]
|
service: 'ddd',
|
||||||
|
uid: 'eee'
|
||||||
})
|
})
|
||||||
assert.equal(amplitude.callCount, 1)
|
assert.equal(amplitude.callCount, 1)
|
||||||
const args = amplitude.args[0]
|
const args = amplitude.args[0]
|
||||||
|
@ -118,6 +119,7 @@ describe('email utils helpers', () => {
|
||||||
uid: 'eee'
|
uid: 'eee'
|
||||||
})
|
})
|
||||||
assert.equal(args[3].flow_id, 'ccc')
|
assert.equal(args[3].flow_id, 'ccc')
|
||||||
|
assert.equal(args[3].flowBeginTime, 42)
|
||||||
assert.ok(args[3].time > Date.now() - 1000)
|
assert.ok(args[3].time > Date.now() - 1000)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -128,6 +130,7 @@ describe('email utils helpers', () => {
|
||||||
headers: [
|
headers: [
|
||||||
{ name: 'Content-Language', value: 'a' },
|
{ name: 'Content-Language', value: 'a' },
|
||||||
{ name: 'X-Device-Id', value: 'b' },
|
{ name: 'X-Device-Id', value: 'b' },
|
||||||
|
{ name: 'X-Flow-Begin-Time', value: 1 },
|
||||||
{ name: 'X-Flow-Id', value: 'c' },
|
{ name: 'X-Flow-Id', value: 'c' },
|
||||||
{ name: 'X-Service-Id', value: 'd' },
|
{ name: 'X-Service-Id', value: 'd' },
|
||||||
{ name: 'X-Template-Name', value: 'verifyLoginEmail' },
|
{ name: 'X-Template-Name', value: 'verifyLoginEmail' },
|
||||||
|
@ -158,6 +161,7 @@ describe('email utils helpers', () => {
|
||||||
uid: 'e'
|
uid: 'e'
|
||||||
})
|
})
|
||||||
assert.equal(args[3].flow_id, 'c')
|
assert.equal(args[3].flow_id, 'c')
|
||||||
|
assert.equal(args[3].flowBeginTime, 1)
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('logErrorIfHeadersAreWeirdOrMissing', () => {
|
describe('logErrorIfHeadersAreWeirdOrMissing', () => {
|
||||||
|
|
|
@ -122,6 +122,10 @@ describe(
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
mockLog.info.reset()
|
||||||
|
})
|
||||||
|
|
||||||
messageTypes.forEach(
|
messageTypes.forEach(
|
||||||
function (type) {
|
function (type) {
|
||||||
var message = {
|
var message = {
|
||||||
|
@ -631,10 +635,9 @@ describe(
|
||||||
it(
|
it(
|
||||||
'logs emailEvent on send',
|
'logs emailEvent on send',
|
||||||
function () {
|
function () {
|
||||||
mockLog.info.reset()
|
|
||||||
|
|
||||||
var message = {
|
var message = {
|
||||||
email: 'test@restmail.net',
|
email: 'test@restmail.net',
|
||||||
|
flowId: 'wibble',
|
||||||
subject: 'subject',
|
subject: 'subject',
|
||||||
template: 'verifyLoginEmail',
|
template: 'verifyLoginEmail',
|
||||||
uid: 'foo'
|
uid: 'foo'
|
||||||
|
@ -646,6 +649,7 @@ describe(
|
||||||
const emailEventLog = mockLog.info.getCalls()[2]
|
const emailEventLog = mockLog.info.getCalls()[2]
|
||||||
assert.equal(emailEventLog.args[0].op, 'emailEvent', 'logs emailEvent')
|
assert.equal(emailEventLog.args[0].op, 'emailEvent', 'logs emailEvent')
|
||||||
assert.equal(emailEventLog.args[0].domain, 'other', 'logs domain')
|
assert.equal(emailEventLog.args[0].domain, 'other', 'logs domain')
|
||||||
|
assert.equal(emailEventLog.args[0].flow_id, 'wibble', 'logs flow id')
|
||||||
assert.equal(emailEventLog.args[0].template, 'verifyLoginEmail', 'logs correct template')
|
assert.equal(emailEventLog.args[0].template, 'verifyLoginEmail', 'logs correct template')
|
||||||
assert.equal(emailEventLog.args[0].type, 'sent', 'logs correct type')
|
assert.equal(emailEventLog.args[0].type, 'sent', 'logs correct type')
|
||||||
})
|
})
|
||||||
|
@ -655,8 +659,6 @@ describe(
|
||||||
it(
|
it(
|
||||||
'rejects sendMail status',
|
'rejects sendMail status',
|
||||||
function () {
|
function () {
|
||||||
mailer.mailer.sendMail.reset()
|
|
||||||
|
|
||||||
var message = {
|
var message = {
|
||||||
email: 'test@restmail.net',
|
email: 'test@restmail.net',
|
||||||
subject: 'subject',
|
subject: 'subject',
|
||||||
|
|
Загрузка…
Ссылка в новой задаче