/// <summary> /// Configures the environment. /// </summary> /// <param name="app">The application being configured.</param> /// <param name="environment">Environment used for the adapter.</param> /// <param name="tracing">Service used for managing application traces.</param> /// <param name="databaseContext">Context used to interact with the database.</param> /// <param name="logger">Logger used to log info to some destination(s).</param> public void Configure( IApplicationBuilder app, IHostEnvironment environment, ITracingService tracing, DatabaseContext databaseContext, ILogger <Startup> logger ) { logger.LogInformation("Starting. Environment: {@environment}", environment.EnvironmentName); databaseContext.Database.OpenConnection(); if (environment.IsEnvironment(Environments.Local)) { using var trace = tracing.StartTrace(); databaseContext.Database.Migrate(); } app.UseForwardedHeaders(); app.UseStaticFiles(new StaticFileOptions { FileProvider = new PhysicalFileProvider("/app/wwwroot"), ServeUnknownFileTypes = true, }); app.UseAuthentication(); app.UseRouting(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapHealthChecks("/healthcheck"); endpoints.MapControllers(); }); }
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(); }
/// <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); } }