import { maskNationalId } from '@island.is/shared/pii' ; import tracer from 'dd-trace' ; import { isPerson } from 'kennitala' ; import { Span } from 'opentracing' ; const PII_MASKING_ALWAYS_ON = process . env . DD_PII_MASKING_DISABLED_ON_FAILURE !== 'true' ; export const shouldMask = ( statusCode ? ) : boolean => PII_MASKING_ALWAYS_ON || ! statusCode || statusCode < 400 ; export const maskSpan = ( span , url , statusCode ? ) : void => { if ( shouldMask ( statusCode ) ) { span ?. setTag ( 'http.url' , maskNationalId ( url ) ) ; } } ; if ( process . env . NODE_ENV !== 'development' ) { tracer . init ( { logInjection : true } ) ; tracer . use ( 'express' , { blacklist : [ '/liveness' , '/readiness' , '/metrics' ] , hooks : { request : ( span , req , res ) => { span && req ?. url && maskSpan ( span , req . url , res ?. statusCode || req ?. statusCode ) ; } , } , } ) ; tracer . use ( 'http' , { client : { hooks : { request : ( span , req , res ) => { const url = res ?. url || `${ req ?. protocol }//${ req ?. getHeader ( 'host' ) }${ req ?. path }` ; span && maskSpan ( span , url , res ?. statusCode ) ; } , } , } , } ) ; } export default tracer ;