@@ -232,14 +232,14 @@ export function shouldMaskHeader(
232232}
233233
234234/**
235- * Mask matching fields inside a JSON-shaped request/response body. When the
236- * body cannot be parsed as JSON the original string is returned unchanged.
237- * Field paths support dotted notation (e.g. `creditCard.number`).
235+ * Mask matching fields inside a JSON-shaped request/response body. Matched
236+ * values are replaced with `DEFAULT_MASK_PLACEHOLDER`. When the body cannot
237+ * be parsed as JSON the original string is returned unchanged. Field paths
238+ * support dotted notation (e.g. `creditCard.number`).
238239 */
239240export function maskBody (
240241 body : unknown ,
241242 fieldsToMask : string [ ] | undefined ,
242- placeholder : string = DEFAULT_MASK_PLACEHOLDER ,
243243) : string {
244244 const original = typeof body === 'string' ? body : jsonToString ( body ) ;
245245
@@ -256,7 +256,7 @@ export function maskBody(
256256 return original ;
257257 }
258258
259- const masked = maskJsonValue ( parsed , fieldsToMask , placeholder ) ;
259+ const masked = maskJsonValue ( parsed , fieldsToMask ) ;
260260
261261 try {
262262 return JSON . stringify ( masked ) ;
@@ -267,18 +267,17 @@ export function maskBody(
267267
268268/**
269269 * Recursively walk a parsed JSON value and replace any property whose path
270- * matches one of `fieldsToMask` with `placeholder `. Path comparison uses
271- * dotted notation rooted at the top-level value.
270+ * matches one of `fieldsToMask` with `DEFAULT_MASK_PLACEHOLDER `. Path
271+ * comparison uses dotted notation rooted at the top-level value.
272272 */
273273function maskJsonValue (
274274 value : unknown ,
275275 fieldsToMask : string [ ] ,
276- placeholder : string ,
277276 currentPath = '' ,
278277) : unknown {
279278 if ( Array . isArray ( value ) ) {
280279 return value . map ( ( item ) =>
281- maskJsonValue ( item , fieldsToMask , placeholder , currentPath ) ,
280+ maskJsonValue ( item , fieldsToMask , currentPath ) ,
282281 ) ;
283282 }
284283
@@ -287,12 +286,11 @@ function maskJsonValue(
287286 for ( const key of Object . keys ( value as Record < string , unknown > ) ) {
288287 const nextPath = currentPath ? `${ currentPath } .${ key } ` : key ;
289288 if ( matchesField ( key , nextPath , fieldsToMask ) ) {
290- result [ key ] = placeholder ;
289+ result [ key ] = DEFAULT_MASK_PLACEHOLDER ;
291290 } else {
292291 result [ key ] = maskJsonValue (
293292 ( value as Record < string , unknown > ) [ key ] ,
294293 fieldsToMask ,
295- placeholder ,
296294 nextPath ,
297295 ) ;
298296 }
@@ -323,12 +321,11 @@ function matchesField(
323321export function headerCapture (
324322 type : 'request' | 'response' ,
325323 headers : string [ ] ,
326- options : { maskFields ?: string [ ] ; maskPlaceholder ?: string } = { } ,
324+ options : { maskFields ?: string [ ] } = { } ,
327325) {
328326 const normalizedHeaders = new Map (
329327 headers . map ( ( header ) => [ header , header . toLowerCase ( ) . replace ( / - / g, '_' ) ] ) ,
330328 ) ;
331- const placeholder = options . maskPlaceholder ?? DEFAULT_MASK_PLACEHOLDER ;
332329
333330 return (
334331 span : Span ,
@@ -347,9 +344,9 @@ export function headerCapture(
347344 let value : string | string [ ] | number = rawValue ;
348345 if ( masked ) {
349346 if ( Array . isArray ( rawValue ) ) {
350- value = rawValue . map ( ( ) => placeholder ) ;
347+ value = rawValue . map ( ( ) => DEFAULT_MASK_PLACEHOLDER ) ;
351348 } else {
352- value = placeholder ;
349+ value = DEFAULT_MASK_PLACEHOLDER ;
353350 }
354351 }
355352
0 commit comments