/// <inheritdoc /> public async Task Handle(MessageCreateEvent @event, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); using var trace = tracingService.StartTrace(); using var scope = logger.BeginScope("{@Event} {@TraceId}", nameof(MessageCreateEvent), trace.Id); tracingService.AddAnnotation("event", "incoming-message"); tracingService.AddAnnotation("messageId", @event.Message.Id); _ = reporter.Report(default(MessageCreateEventMetric), cancellationToken); if (await userService.IsUserRegistered(@event.Message.Author, cancellationToken)) { await HandleMessageFromRegisteredUser(@event, trace, cancellationToken); return; } if (@event.Message.Mentions.Any(mention => mention.Id == gateway.BotId)) { await PerformWelcome(@event, cancellationToken); } }
private async Task Invoke(RequestMessage message, CancellationToken cancellationToken) { using var trace = tracing.StartTrace(message.RequestDetails.TraceHeader); tracing.AddAnnotation("event", "rest-call"); using var transaction = transactionFactory.CreateTransaction(); using var logScope = logger.BeginScope("{@requestId}", message.RequestDetails.Id); using var serviceScope = scopeFactory.CreateScope(); var invoker = serviceScope.GetService <IRequestInvoker>(); await invoker.Invoke(message, cancellationToken); transaction.Complete(); }