File tree Expand file tree Collapse file tree
src/article-api/middleware Expand file tree Collapse file tree Original file line number Diff line number Diff 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+
205216export default router
You can’t perform that action at this time.
0 commit comments