/// <summary>
    /// Allows to convey the message handling failure that occurred in a specific handler
    /// </summary>
    /// <param name="context">Message context</param>
    /// <param name="handlerType">Handler type identifier</param>
    /// <param name="exception">Optional: handler exception</param>
    public static void Nack(this IBaseConsumeContext context, string handlerType, Exception?exception)
    {
        context.HandlingResults.Add(EventHandlingResult.Failed(handlerType, exception));
        if (exception is not TaskCanceledException)
        {
            Log.MessageHandlingFailed(handlerType, context, exception);
        }

        if (Activity.Current != null && Activity.Current.Status != ActivityStatusCode.Error)
        {
            Activity.Current.SetActivityStatus(
                ActivityStatus.Error(exception, $"Error handling {context.MessageType}")
                );
        }
    }
示例#2
0
    public override async ValueTask Send(
        IMessageConsumeContext context,
        Func <IMessageConsumeContext, ValueTask>?next
        )
    {
        if (context.Message == null || next == null)
        {
            return;
        }

        using var activity = Activity.Current?.Context != context.ParentContext
            ? SubscriptionActivity.Start(
                  $"{Constants.Components.Consumer}.{context.SubscriptionId}/{context.MessageType}",
                  ActivityKind.Consumer,
                  context,
                  _defaultTags
                  )
            : Activity.Current;

        if (activity?.IsAllDataRequested == true && context is DelayedAckConsumeContext delayedAckContext)
        {
            activity.SetContextTags(context)?.SetTag(TelemetryTags.Eventuous.Partition, delayedAckContext.PartitionId);
        }

        try {
            await next(context).NoContext();

            if (activity != null)
            {
                if (context.WasIgnored())
                {
                    activity.ActivityTraceFlags = ActivityTraceFlags.None;
                }

                activity.SetActivityStatus(ActivityStatus.Ok());
            }
        }
        catch (Exception e) {
            activity?.SetActivityStatus(ActivityStatus.Error(e, $"Error handling {context.MessageType}"));
            throw;
        }
    }
示例#3
0
    public override async ValueTask Consume(IMessageConsumeContext context)
    {
        if (context.Message == null)
        {
            return;
        }

        using var activity = Activity.Current?.Context != context.ParentContext
            ? SubscriptionActivity.Start(context, _defaultTags) : Activity.Current;

        activity?.SetContextTags(context)?.Start();

        try {
            await _inner.Consume(context).NoContext();
        }
        catch (Exception e) {
            activity?.SetStatus(ActivityStatus.Error(e, $"Error handling {context.MessageType}"));
            throw;
        }
    }