const redactableKeys = [ "authorization" , "x-authorization" , "password" , "token" ] ; const maxDepth = 10 ; export function tagObject ( currentSpan , key , obj , depth = 0 ) { if ( depth >= maxDepth ) { return ; } else { depth += 1 ; } if ( obj === null ) { return currentSpan . setTag ( key , obj ) ; } if ( typeof obj === "string" ) { let parsed ; try { parsed = JSON . parse ( obj ) ; } catch ( e ) { const redacted = redactVal ( key , obj . substring ( 0 , 5000 ) ) ; return currentSpan . setTag ( key , redacted ) ; } return tagObject ( currentSpan , key , parsed , depth ) ; } if ( typeof obj === "number" ) { return currentSpan . setTag ( key , obj ) ; } if ( typeof obj === "object" ) { for ( const [ k , v ] of Object . entries ( obj ) ) { tagObject ( currentSpan , `${ key }.${ k }` , v , depth ) ; } return ; } } function redactVal ( k , v ) { const splitKey = k . split ( "." ) . pop ( ) || k ; if ( redactableKeys . includes ( splitKey ) ) { return "redacted" ; } return v ; }