@@ -7,6 +7,7 @@ import catchMiddlewareError from '@/observability/middleware/catch-middleware-er
77import { ExtendedRequestWithPageInfo } from '../types'
88import { pageValidationMiddleware , pathValidationMiddleware } from './validation'
99import contextualize from '#src/frame/middleware/context/context.js'
10+ import statsd from '#src/observability/lib/statsd.js'
1011
1112/** START helper functions */
1213
@@ -59,6 +60,23 @@ async function getArticleBody(req: ExtendedRequestWithPageInfo) {
5960 return await page . render ( renderingReq . context )
6061}
6162
63+ function incrementArticleLookup (
64+ pathname : string ,
65+ language : string ,
66+ type : 'full' | 'body' | 'meta' ,
67+ ) {
68+ const tags = [
69+ // According to https://docs.datadoghq.com/getting_started/tagging/#define-tags
70+ // the max length of a tag is 200 characters. Most of ours are less than
71+ // that but we truncate just to be safe.
72+ `pathname:${ pathname } ` . slice ( 0 , 200 ) ,
73+ `language:${ language } ` ,
74+ `type:${ type } ` ,
75+ ]
76+
77+ statsd . increment ( 'api.article.lookup' , 1 , tags )
78+ }
79+
6280/** END helper functions */
6381
6482/** START routes */
@@ -82,6 +100,8 @@ router.get(
82100 return res . status ( 403 ) . json ( { error : ( error as Error ) . message } )
83101 }
84102
103+ incrementArticleLookup ( req . pageinfo . pathname , req . pageinfo . page . languageCode , 'full' )
104+
85105 defaultCacheControl ( res )
86106 return res . json ( {
87107 meta : metaData ,
@@ -101,6 +121,9 @@ router.get(
101121 } catch ( error ) {
102122 return res . status ( 403 ) . json ( { error : ( error as Error ) . message } )
103123 }
124+
125+ incrementArticleLookup ( req . pageinfo . pathname , req . pageinfo . page . languageCode , 'body' )
126+
104127 defaultCacheControl ( res )
105128 return res . type ( 'text/markdown' ) . send ( bodyContent )
106129 } ) ,
@@ -112,6 +135,9 @@ router.get(
112135 pageValidationMiddleware as RequestHandler ,
113136 catchMiddlewareError ( async function ( req : ExtendedRequestWithPageInfo , res : Response ) {
114137 const metaData = await getArticleMetadata ( req )
138+
139+ incrementArticleLookup ( req . pageinfo . pathname , req . pageinfo . page . languageCode , 'meta' )
140+
115141 defaultCacheControl ( res )
116142 return res . json ( metaData )
117143 } ) ,
0 commit comments