Skip to content

Commit 008faf5

Browse files
committed
improve sentry reporting, add metrics for hydro
1 parent adb81ce commit 008faf5

2 files changed

Lines changed: 17 additions & 4 deletions

File tree

lib/hydro.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
const crypto = require('crypto')
22
const fetch = require('node-fetch')
3+
const statsd = require('../lib/statsd')
4+
5+
const hydroStats = statsd.childClient({
6+
prefix: 'hydro.'
7+
})
38

49
const SCHEMAS = {
510
page: 'docs.v0.PageEvent',
@@ -62,7 +67,7 @@ module.exports = class Hydro {
6267
})
6368
const token = this.generatePayloadHmac(body)
6469

65-
return fetch(this.endpoint, {
70+
const fn = () => fetch(this.endpoint, {
6671
method: 'POST',
6772
body,
6873
headers: {
@@ -71,5 +76,12 @@ module.exports = class Hydro {
7176
'X-Hydro-App': 'docs-production'
7277
}
7378
})
79+
80+
const res = await hydroStats.asyncTimer(fn, 'response_time')
81+
82+
hydroStats.increment(`response_code.${res.statusCode}`, 1)
83+
hydroStats.increment('response_code.all', 1)
84+
85+
return res;
7486
}
7587
}

middleware/events.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,16 @@ router.post('/', async function postEvents (req, res, next) {
2626
req.hydro.schemas[fields.type],
2727
omit(fields, OMIT_FIELDS)
2828
).then(async (hydroRes) => {
29-
if (!hydroRes.ok) {
30-
const err = new Error('Hydro request failed')
29+
// Track hydro exceptions in Sentry, but don't track 503s because we can't do anything about service availability
30+
if (!hydroRes.ok && hydroRes.status !== 503) {
31+
const err = new Error(`Hydro request failed: ${hydroRes.statusText}`)
3132
err.status = hydroRes.status
3233
err.path = fields.path
3334

3435
await FailBot.report(err, {
3536
path: fields.path,
3637
hydroStatus: hydroRes.status,
37-
hydroText: await hydroRes.text()
38+
hydroText: hydroRes.statusText
3839
})
3940

4041
throw err

0 commit comments

Comments
 (0)