public async ValueTask <EventHandlingStatus> HandleEvent(IMessageConsumeContext context) { using var activity = SubscriptionActivity .Create( $"{Constants.Components.EventHandler}.{DiagnosticName}/{context.MessageType}", ActivityKind.Internal, tags: _defaultTags ) ?.SetContextTags(context) ?.Start(); try { var status = await _innerHandler.HandleEvent(context).NoContext(); if (activity != null && status == EventHandlingStatus.Ignored) { activity.ActivityTraceFlags = ActivityTraceFlags.None; } activity?.SetActivityStatus(ActivityStatus.Ok()); return(status); } catch (Exception e) { activity?.SetActivityStatus(ActivityStatus.Error(e, $"Error handling {context.MessageType}")); throw; } }
public async ValueTask <SubscriptionGap> GetSubscriptionGap(CancellationToken cancellationToken) { using var activity = EventuousDiagnostics.ActivitySource .StartActivity(ActivityKind.Internal) ?.SetTag("stream", "$all"); try { var read = _eventStoreClient.ReadAllAsync( Direction.Backwards, Position.End, 1, cancellationToken: cancellationToken ); var events = await read.ToArrayAsync(cancellationToken).NoContext(); var last = _getLast(); activity?.SetActivityStatus(ActivityStatus.Ok()); return(new SubscriptionGap( _subscriptionId, events[0].Event.Position.CommitPosition - last?.Position ?? 0, DateTime.UtcNow - events[0].Event.Created )); } catch (Exception e) { activity?.SetActivityStatus(ActivityStatus.Error(e)); throw; } }
public async Task <Result> Handle(object command, CancellationToken cancellationToken) { using var activity = AppServiceActivity.StartActivity(_appServiceTypeName, command); try { var result = await InnerService.Handle(command, cancellationToken).NoContext(); if (activity != null) { if (result is ErrorResult error) { activity.SetActivityStatus(ActivityStatus.Error(error.Exception)); } else { activity.SetActivityStatus(ActivityStatus.Ok()); } } return(result); } catch (Exception e) { activity?.SetActivityStatus(ActivityStatus.Error(e)); throw; } }