import { SpanAttributeValue , Span } from '@opentelemetry/api' ; import { callHookOnlyOnRecordingSpan } from '../payload-collection/recording-span' ; import { IORedisInstrumentationConfig } from '@opentelemetry/instrumentation-ioredis' ; import { DbExtendedAttribute , GeneralExtendedAttribute } from '../enums' ; import { getModuleVersion } from './module-version' ; import { AutoInstrumentationOptions } from '../types' ; const ioredisCustomAttributesOnResponse = ( options ) => ( span , _cmdName , _cmdArgs , response ) : void => { if ( options . collectPayloads ) { let responsePayload ; if ( typeof response === 'string' || typeof response === 'number' ) { responsePayload = response ; } else if ( response instanceof Buffer ) { responsePayload = response . toString ( ) ; } else if ( typeof response === 'object' ) { responsePayload = JSON . stringify ( response ) ; } if ( responsePayload !== undefined ) { span . setAttribute ( DbExtendedAttribute . DB_RESPONSE , responsePayload ) ; } } const version = getModuleVersion ( 'ioredis' ) ; if ( version ) { span . setAttribute ( GeneralExtendedAttribute . INSTRUMENTED_LIBRARY_VERSION , version ) ; } } ; export const ioredisInstrumentationConfig = ( options ) : IORedisInstrumentationConfig => ( { responseHook : callHookOnlyOnRecordingSpan ( ioredisCustomAttributesOnResponse ( options ) ) , } ) ;