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

Added an option to wrap current spring rabbit components #636

Merged

Conversation

marcingrzejszczak
Copy link
Contributor

without this change you can only explicitly create a RabbitTemplate or a SimpleRabbitListenerContainerFactory. In case of frameworks like Sleuth that want to wrap existing instances that's not possible.

with this change in a hacky (RabbitTemplate) and non-hacky (SRLCF) way we're allowing to instrument existing objects. For RT we're hacking into a field of before post processors and injecting there the traced instrumentation. For SRLCF we're adding the traced advice to an existing factory

without this change you can only explicitly create a RabbitTemplate or a SimpleRabbitListenerContainerFactory. In case of frameworks like Sleuth that want to wrap existing instances that's not possible.

with this change in a hacky (RabbitTemplate) and non-hacky (SRLCF) way we're allowing to instrument existing objects. For RT we're hacking into a field of before post processors and injecting there the traced instrumentation. For SRLCF we're adding the traced advice to an existing factory
@marcingrzejszczak marcingrzejszczak changed the title Added an option to wrap current spring rabbit compontents Added an option to wrap current spring rabbit components Mar 6, 2018
@@ -60,6 +68,36 @@ public RabbitTemplate newRabbitTemplate(ConnectionFactory connectionFactory) {
return rabbitTemplate;
}

/** Instruments an existing rabbit template. */
public RabbitTemplate fromRabbitTemplate(RabbitTemplate rabbitTemplate) {
Copy link
Member

Choose a reason for hiding this comment

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

nit: maybe decorateRabbitTemplate?

Collection<MessagePostProcessor> processors =
(Collection<MessagePostProcessor>) field.get(rabbitTemplate);
List<MessagePostProcessor> newProcessors = new ArrayList<>();
if (!processors.contains(tracingMessagePostProcessor)) {
Copy link
Member

Choose a reason for hiding this comment

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

not sure this will work as we don't do any deep equals etc. Maybe we should just look for an instance of?

if (!currentChain.contains(tracingRabbitListenerAdvice)) {
chainList.add(tracingRabbitListenerAdvice);
}
if (chain != null) {
Copy link
Member

Choose a reason for hiding this comment

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

if this were null would line 126 NPE?

if (chain != null) {
chainList.addAll(Arrays.asList(chain));
}
return chainList.toArray(new Advice[] {});
Copy link
Member

Choose a reason for hiding this comment

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

neat trick: new Advice[0]


private Advice[] chainListWithTracing(Advice[] chain) {
if (chain == null) {
return chain;
Copy link
Member

Choose a reason for hiding this comment

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

do you want this? or do you want to return a singleton array with the tracingRabbitListenerAdvice?

@codefromthecrypt
Copy link
Member

will buff this on the way in. Thanks @marcingrzejszczak!

@@ -52,8 +54,10 @@ public SimpleRabbitListenerContainerFactory rabbitListenerContainerFactory(
ConnectionFactory connectionFactory,
SpringRabbitTracing springRabbitTracing
) {
return springRabbitTracing.newSimpleMessageListenerContainerFactory(connectionFactory);
return springRabbitTracing.newSimpleRabbitListenerContainerFactory(connectionFactory);
Copy link
Member

Choose a reason for hiding this comment

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

@jonathan-lo heads up. fixing this typo in a patch on green

public RabbitTemplate decorateRabbitTemplate(RabbitTemplate rabbitTemplate) {
// Skip out if we can't read the field for the existing post processors
if (beforePublishPostProcessorsField == null) return rabbitTemplate;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

why not just set the value of the field with the processor?

Copy link
Member

Choose a reason for hiding this comment

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

if this is null, we had a reflection error which I'm not assuming will get better :)

@codefromthecrypt
Copy link
Member

circle ci is flaking unrelatedly

@codefromthecrypt codefromthecrypt merged commit dcdfa1c into openzipkin:master Mar 6, 2018
@codefromthecrypt
Copy link
Member

4.17.2 on the way

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.

2 participants