Source:
<code>public Message<?> preSend(Message<?> message, MessageChannel channel) { if (log.isDebugEnabled()) { log.debug("Processing message before sending it to the channel"); } Message<?> retrievedMessage = getMessage(message); MessageBuilder<?> messageBuilder = MessageBuilder.fromMessage(retrievedMessage); Span parentSpan = getTracer().isTracing() ? getTracer().getCurrentSpan() : buildSpan(new MessagingTextMap(messageBuilder)); if (log.isDebugEnabled()) { log.debug("Parent span is " + parentSpan); } String name = getMessageChannelName(channel); if (log.isDebugEnabled()) { log.debug("Name of the span will be [" + name + "]"); } Span span = startSpan(parentSpan, name, message); if (message.getHeaders().containsKey(TraceMessageHeaders.MESSAGE_SENT_FROM_CLIENT)) { if (log.isDebugEnabled()) { log.debug("Marking span with server received"); } span.logEvent(Span.SERVER_RECV); } else { if (log.isDebugEnabled()) { log.debug("Marking span with client send"); } span.logEvent(Span.CLIENT_SEND); messageBuilder.setHeader(TraceMessageHeaders.MESSAGE_SENT_FROM_CLIENT, true); } getSpanInjector().inject(span, new MessagingTextMap(messageBuilder)); MessageHeaderAccessor headers = MessageHeaderAccessor.getMutableAccessor(message); if (message.getPayload() instanceof MessagingException) { headers.copyHeaders(sleuthHeaders(messageBuilder.build().getHeaders())); <START> return new ErrorMessage((MessagingException) message.getPayload(), headers.getMessageHeaders()); <END> } headers.copyHeaders(messageBuilder.build().getHeaders()); return new GenericMessage<>(message.getPayload(), headers.getMessageHeaders()); }</code><technical_language>Strictly speaking, is for a GenericMessage a MessagingException payload (not framework, in user code). I need treat (header-wise), I return Message<?> type original. Of course, implementation some other user-defined Message<?> I guess choice in case build a GenericMessage<?> for that</technical_language>

Target:
public Message<?> preSend(Message<?> message, MessageChannel channel) { if (log.isDebugEnabled()) { log.debug("Processing message before sending it to the channel"); } Message<?> retrievedMessage = getMessage(message); MessageBuilder<?> messageBuilder = MessageBuilder.fromMessage(retrievedMessage); Span parentSpan = getTracer().isTracing() ? getTracer().getCurrentSpan() : buildSpan(new MessagingTextMap(messageBuilder)); if (log.isDebugEnabled()) { log.debug("Parent span is " + parentSpan); } String name = getMessageChannelName(channel); if (log.isDebugEnabled()) { log.debug("Name of the span will be [" + name + "]"); } Span span = startSpan(parentSpan, name, message); if (message.getHeaders().containsKey(TraceMessageHeaders.MESSAGE_SENT_FROM_CLIENT)) { if (log.isDebugEnabled()) { log.debug("Marking span with server received"); } span.logEvent(Span.SERVER_RECV); } else { if (log.isDebugEnabled()) { log.debug("Marking span with client send"); } span.logEvent(Span.CLIENT_SEND); messageBuilder.setHeader(TraceMessageHeaders.MESSAGE_SENT_FROM_CLIENT, true); } getSpanInjector().inject(span, new MessagingTextMap(messageBuilder)); MessageHeaderAccessor headers = MessageHeaderAccessor.getMutableAccessor(message); if (message instanceof ErrorMessage) { headers.copyHeaders(sleuthHeaders(messageBuilder.build().getHeaders())); return new ErrorMessage((Throwable) message.getPayload(), headers.getMessageHeaders()); } headers.copyHeaders(messageBuilder.build().getHeaders()); return new GenericMessage<>(message.getPayload(), headers.getMessageHeaders()); }