Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pulsar Traces are not always propagated #2519

Closed
michalcukierman opened this issue Mar 9, 2024 · 1 comment
Closed

Pulsar Traces are not always propagated #2519

michalcukierman opened this issue Mar 9, 2024 · 1 comment

Comments

@michalcukierman
Copy link
Contributor

This is a regression introduced by #2456.
Tracing properties from incoming Pulsar messages are not propagated to outgoing Pulsar messages.

The change is in PulsarTrace.java:

before:

        public Builder withProperties(Map<String, String> properties) {
            this.properties = properties;
            return this;
        }

after:

        public Builder withProperties(Map<String, String> properties) {
            if (properties != null) {
                this.properties = new HashMap<>(properties);
            }
            return this;
        }

It was introduced to ensure that the map is modifiable because it's required during producing outgoing traces.

Unfortunately, it introduced a regression in PulsarOutgoingChannel. We expect that the changes in properties will be propagated into the state of the trace:

            if (tracingEnabled) {
                Map<String, String> properties = new HashMap<>(); // Single instance has to be used in Trace and MessageBuilder
                TracingUtils.traceOutgoing(instrumenter, message, new PulsarTrace.Builder()
                        .withProperties(properties) // REGRESSION HERE, we create a new instance of a HashMap
                        .withTopic(producer.getTopic())
                        .build());
                messageBuilder.properties(properties);
            }

I think that the correct solution could look like:

            if (tracingEnabled) {
                PulsarTrace trace = new PulsarTrace.Builder() // Builder initializes properties with new HashMap
                        .withTopic(producer.getTopic())
                        .build();
                TracingUtils.traceOutgoing(instrumenter, message, trace);
                messageBuilder.properties(trace.getProperties()); // Reuse the same instance of the HashMap
            }

This happens only when PulsarOutgoingMessageMetadata is not used.

michalcukierman added a commit to streamx-dev/smallrye-reactive-messaging that referenced this issue Mar 9, 2024
michalcukierman added a commit to streamx-dev/smallrye-reactive-messaging that referenced this issue Mar 9, 2024
@michalcukierman
Copy link
Contributor Author

michalcukierman commented Mar 9, 2024

During the tests, I discovered that more changes are required. Pushed the second commit. In the second case it's also about re-using the same instance of a map between the PulsarTrace and the MessageBuilder.

Please feel free to reject this PR and propose other solutions that would work.

ozangunalp added a commit to ozangunalp/smallrye-reactive-messaging that referenced this issue Mar 13, 2024
michalcukierman added a commit to streamx-dev/smallrye-reactive-messaging that referenced this issue Mar 13, 2024
michalcukierman added a commit to streamx-dev/smallrye-reactive-messaging that referenced this issue Mar 13, 2024
ozangunalp added a commit that referenced this issue Mar 13, 2024
#2519 Fix: PulsarOutgoingChannel tracing properties propagation
ozangunalp pushed a commit that referenced this issue Jul 25, 2024
ozangunalp pushed a commit that referenced this issue Jul 25, 2024
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

No branches or pull requests

2 participants