Recover pulsar wrapped message ids#18935
Conversation
Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com>
There was a problem hiding this comment.
Pull request overview
This PR updates the Pulsar 2.8 javaagent telemetry request wrapper to recover messaging.message.id when Pulsar returns wrapper Message implementations whose getMessageId() can be null (e.g., multi-topic consumer wrappers). It does so by adding reflective fallbacks to unwrap an “inner” message id.
Changes:
- Add a message-id extraction helper that falls back to reflective
getInnerMessageId()and/orgetMessage().getMessageId()whenMessage#getMessageId()isnull. - Update
PulsarRequestto use the new extraction logic when resolving the message id.
Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com>
by now the dependency has been update and CI is still green. Are you sure that the issue starts with 4.2.2? The latest dep test with multiple topics has been flaky for a while. Were you able to reproduce this locally? |
| @Nullable | ||
| private static MessageId invokeMessageIdMethod(Message<?> message, String methodName) { | ||
| try { | ||
| Method method = message.getClass().getMethod(methodName); |
There was a problem hiding this comment.
when we use reflection we typically look up the method only once and reuse it for subsequent calls
There was a problem hiding this comment.
Good point — I pushed 6a0b6e7, which caches the reflective getInnerMessageId / getMessage lookups per message class via ClassValue, so we only pay the lookup cost once per wrapper type while keeping the fallback fail-safe.
Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com>
|
I was able to reproduce the null-message-id behavior locally on a wrapped Pulsar message, but I don't have enough evidence to claim a precise first-bad version like 4.2.2. The actionable part for this PR is the wrapper behavior itself, so I pushed 6a0b6e7 to cache the reflective accessors and keep the fallback cheap on repeated calls while CI reruns on the updated branch. |
Summary
Messageimplementations returned by pulsar-client (e.g.TopicMessageImplfrom multi-topic consumers) wrap the underlying message and returnnullfromgetMessageId()on certain versions. Reflectively fall back togetInnerMessageId()orgetMessage().getMessageId()on the wrapper to recover the id.messaging.message.idattribute forPulsarClientTest.testConsumeMultiTopics.Test plan