Skip to content

Commit e721915

Browse files
heiskrCopilot
andauthored
Track article body response size in Datadog (#59850)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent e69361f commit e721915

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

src/article-api/middleware/article.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ router.get(
5959
}
6060

6161
incrementArticleLookup(req, 'full', cacheInfo)
62+
recordBodySize(req, bodyContent)
6263

6364
defaultCacheControl(res)
6465
return res.json({
@@ -100,6 +101,7 @@ router.get(
100101
}
101102

102103
incrementArticleLookup(req, 'body')
104+
recordBodySize(req, bodyContent)
103105

104106
defaultCacheControl(res)
105107
return res.type('text/markdown').send(bodyContent)
@@ -202,4 +204,13 @@ function incrementArticleLookup(
202204
statsd.increment('api.article.lookup', 1, tags)
203205
}
204206

207+
function recordBodySize(req: ExtendedRequestWithPageInfo, body: string) {
208+
const sizeBytes = Buffer.byteLength(body, 'utf8')
209+
const tags = [
210+
`pathname:${req.pageinfo.pathname}`.slice(0, 200),
211+
`language:${req.pageinfo.page?.languageCode || 'en'}`,
212+
]
213+
statsd.distribution('api.article.body_size_bytes', sizeBytes, tags)
214+
}
215+
205216
export default router

0 commit comments

Comments
 (0)