Description
In what version(s) of Spring Integration are you seeing this issue?
id 'org.springframework.boot' version '3.1.1'
implementation("org.springframework.integration:spring-integration-ip")
Describe the bug
When using the ObservationPredicate
with Spring boot micrometer, I created some rules in order to observe certain contexts. But when using the context MessageRequestReplyReceiverContext
and using some of its data in order to create a predicate, the rest of the chain of the application just fails with the exception:
java.lang.ClassCastException: class io.micrometer.observation.Observation$Context cannot be cast to class org.springframework.integration.support.management.observation.MessageRequestReplyReceiverContext (io.micrometer.observation.Observation$Context and org.springframework.integration.support.management.observation.MessageRequestReplyReceiverContext are in unnamed module of loader 'app')
Our application flow is just a simple TCP nio inbound, with a broker outbound. But it seems to be going wrong before we receive it in the the TCP inbound.
observationRegistry.observationConfig()
.observationPredicate((name, context) -> shouldBeObserved(context));
Example of usage in observation predicate when using headers:
...
if (context instanceof MessageRequestReplyReceiverContext messageRequestReplyReceiverContext) {
return Optional.ofNullable(messageRequestReplyReceiverContext.getCarrier())
.map(Message::getHeaders)
.map(headers -> !headers.containsKey("SOMEKEY"))
.orElse(true);
}
...
Example of usage in observation predicate when using payload:
...
if (context instanceof MessageRequestReplyReceiverContext messageRequestReplyReceiverContext) {
return Optional.ofNullable(messageRequestReplyReceiverContext.getCarrier())
.map(Message::getPayload)
.map(payload -> new String((byte[]) payload, StandardCharsets.UTF_8))
.map(payload -> !payload.equals(SOMEDATA))
.orElse(true);
}
...
Expected behavior
Expected to not break the application when simply casting the payload or using the headers in the generic message.