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

RabbitMQActivitySource.Deliver cannot be used by types that implement Consumer #1621

Closed
Tornhoof opened this issue Jun 28, 2024 · 8 comments · Fixed by #1633
Closed

RabbitMQActivitySource.Deliver cannot be used by types that implement Consumer #1621

Tornhoof opened this issue Jun 28, 2024 · 8 comments · Fixed by #1633
Assignees
Labels
Milestone

Comments

@Tornhoof
Copy link
Contributor

Tornhoof commented Jun 28, 2024

Describe the bug

Currently RabbitMQActivitySource.Deliver is only called in the derived types AsyncEventingBasicConsumer and EventingBasicConsumer and the method itself is marked as internal.

private async Task BasicDeliverWrapper(BasicDeliverEventArgs eventArgs)
{
using (Activity activity = RabbitMQActivitySource.Deliver(eventArgs))
{
await _receivedWrapper.InvokeAsync(this, eventArgs).ConfigureAwait(false);
}
}

This means, if a dev is deriving from the base types DefaultBasicConsumer or AsyncDefaultBasicConsumer or implements the appropriate interfaces, the Deliver method can't be invoked.

All the other relevant ActivitySource methods are called from within ChannelBase, so these should be fine.

I think the easiest way forward is to make a public RabbitMQActivitySource.Deliver method with the args from the eventArgs:

Current:

internal static Activity Deliver(BasicDeliverEventArgs deliverEventArgs)
{
if (!s_subscriberSource.HasListeners())
{
return null;
}
// Extract the PropagationContext of the upstream parent from the message headers.
Activity activity = s_subscriberSource.StartLinkedRabbitMQActivity(
UseRoutingKeyAsOperationName ? $"{deliverEventArgs.RoutingKey} deliver" : "deliver",
ActivityKind.Consumer, ContextExtractor(deliverEventArgs.BasicProperties));
if (activity != null && activity.IsAllDataRequested)
{
PopulateMessagingTags("deliver", deliverEventArgs.RoutingKey, deliverEventArgs.Exchange,
deliverEventArgs.DeliveryTag, deliverEventArgs.BasicProperties, deliverEventArgs.Body.Length,
activity);
}
return activity;
}

Proposed change:

        internal static Activity Deliver(BasicDeliverEventArgs deliverEventArgs)
        {
            return Deliver(deliverEventArgs.RoutingKey, deliverEventArgs.Exchange, deliverEventArgs.DeliveryTag,
                deliverEventArgs.BasicProperties, deliverEventArgs.Body.Length);
        }

        public static Activity Deliver(string routingKey, string exchange, ulong deliveryTag,
            in ReadOnlyBasicProperties readOnlyBasicProperties, int bodySize)
        {
            if (!s_subscriberSource.HasListeners())
            {
                return null;
            }

            // Extract the PropagationContext of the upstream parent from the message headers.
            Activity activity = s_subscriberSource.StartLinkedRabbitMQActivity(
                UseRoutingKeyAsOperationName ? $"{routingKey} deliver" : "deliver",
                ActivityKind.Consumer, ContextExtractor(readOnlyBasicProperties));
            if (activity != null && activity.IsAllDataRequested)
            {
                PopulateMessagingTags("deliver", routingKey, exchange,
                    deliveryTag, readOnlyBasicProperties, bodySize,
                    activity);
            }

            return activity;
        }

Then the dev can call it in their own implementation of HandleBasicDeliver. I don't see any easy way to do it automatically, like for the other methods, that would be preferable.

Reproduction steps

Expected behavior

Additional context

Maybe @stebet has a better idea, he wrote the original PR.

@Tornhoof Tornhoof added the bug label Jun 28, 2024
@lukebakken lukebakken added this to the 7.0.0 milestone Jun 28, 2024
@stebet
Copy link
Contributor

stebet commented Jun 30, 2024

I'll take a look :)

@lukebakken
Copy link
Contributor

@stebet thank you!!!

@bollhals
Copy link
Contributor

bollhals commented Jul 9, 2024

Wouldn't it be better to move it inside of the dispatcher rather than the BasicConsumer?

@bollhals
Copy link
Contributor

Yes exactly. I wondered whether it would make more sense to do it at that level than in the consumer themselves.

@lukebakken
Copy link
Contributor

@stebet @Tornhoof @bollhals -> #1633

Let me know what you think!

@bollhals
Copy link
Contributor

looks reasonable to me.

@Tornhoof
Copy link
Contributor Author

Yeah, I agree, this looks quite neat.

@michaelklishin michaelklishin changed the title RabbitMQActivitySource.Deliver not possible to be used by derived types of a Consumer RabbitMQActivitySource.Deliver cannot be used by types that implement Consumer Jul 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants