Skip to content

Recover pulsar wrapped message ids#18935

Open
zeitlinger wants to merge 3 commits into
open-telemetry:mainfrom
zeitlinger:gregor/pulsar-wrapped-message-ids
Open

Recover pulsar wrapped message ids#18935
zeitlinger wants to merge 3 commits into
open-telemetry:mainfrom
zeitlinger:gregor/pulsar-wrapped-message-ids

Conversation

@zeitlinger

@zeitlinger zeitlinger commented Jun 8, 2026

Copy link
Copy Markdown
Member

Summary

  • Some Message implementations returned by pulsar-client (e.g. TopicMessageImpl from multi-topic consumers) wrap the underlying message and return null from getMessageId() on certain versions. Reflectively fall back to getInnerMessageId() or getMessage().getMessageId() on the wrapper to recover the id.
  • Restores messaging.message.id attribute for PulsarClientTest.testConsumeMultiTopics.
  • Main CI stays green because pinned pulsar-client 4.2.1 still returns a non-null id from the wrapper; the bug only surfaces on newer (unpinned) pulsar-client versions.

Test plan

  • CI green on pulsar-2.8 javaagent tests

Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com>
@zeitlinger zeitlinger marked this pull request as ready for review June 9, 2026 08:24
@zeitlinger zeitlinger requested a review from a team as a code owner June 9, 2026 08:24
Copilot AI review requested due to automatic review settings June 9, 2026 08:24

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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/or getMessage().getMessageId() when Message#getMessageId() is null.
  • Update PulsarRequest to use the new extraction logic when resolving the message id.

Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com>
@laurit

laurit commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Main CI stays green because pinned pulsar-client 4.2.1 still returns a non-null id from the wrapper; the bug only surfaces on newer (unpinned) pulsar-client versions.

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);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when we use reflection we typically look up the method only once and reuse it for subsequent calls

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>

Copy link
Copy Markdown
Member Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants