import { Span } from '@opentelemetry/api' ; import { AmqplibInstrumentationConfig , PublishParams , EndOperation } from 'opentelemetry-instrumentation-amqplib' ; import { callHookOnlyOnRecordingSpan } from '../payload-collection/recording-span' ; import type amqp from 'amqplib' ; import { GeneralExtendedAttribute , MessagingExtendedAttribute } from '../enums' ; import { AutoInstrumentationOptions } from '../types' ; const amqplibPublishHook = ( span , publishParams ) => { if ( publishParams . content !== undefined ) { span . setAttribute ( MessagingExtendedAttribute . MESSAGING_PAYLOAD , publishParams . content . toString ( ) ) ; } } ; const amqplibConsumeHook = ( span , msg ) => { if ( msg ?. content !== undefined ) { span . setAttribute ( MessagingExtendedAttribute . MESSAGING_PAYLOAD , msg . content . toString ( ) ) ; } } ; const amqplibConsumeEndHook = ( span , _msg , _rejected , endOperation ) => { span . setAttribute ( MessagingExtendedAttribute . MESSAGING_RABBITMQ_CONSUME_END_OPERATION , endOperation ) ; } ; export const amqplibInstrumentationConfig = ( options ) : AmqplibInstrumentationConfig => ( { moduleVersionAttributeName : GeneralExtendedAttribute . INSTRUMENTED_LIBRARY_VERSION , publishHook : options . collectPayloads && callHookOnlyOnRecordingSpan ( amqplibPublishHook ) , consumeHook : options . collectPayloads && callHookOnlyOnRecordingSpan ( amqplibConsumeHook ) , consumeEndHook : options . collectPayloads && callHookOnlyOnRecordingSpan ( amqplibConsumeEndHook ) , } ) ;