diff --git a/.env b/.env index c5b35f81f..5d1c55132 100644 --- a/.env +++ b/.env @@ -1,3 +1,5 @@ +APPLICATION_INSIGHTS_SERVER_TELEMETRY_CHANNEL_STORAGE_PATH=application-insights + ARCHIVAL_APPLICATION_INSIGHTS_INSTRUMENTATION_KEY= ARCHIVAL_REDIS_CONNECTION_STRING=archival-scheduling-db:6379 ARCHIVAL_GIT_REPOSITORY_PATH=archives diff --git a/docker-compose.yml b/docker-compose.yml index 6947750ef..b63b490fc 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -20,8 +20,10 @@ services: depends_on: - archival-scheduling-db volumes: + - archival-application-insights:/app/${APPLICATION_INSIGHTS_SERVER_TELEMETRY_CHANNEL_STORAGE_PATH} - archival-archives:/app/${ARCHIVAL_GIT_REPOSITORY_PATH} environment: + ApplicationInsights__ServerTelemetryChannelStoragePath: ${APPLICATION_INSIGHTS_SERVER_TELEMETRY_CHANNEL_STORAGE_PATH} ApplicationInsights__InstrumentationKey: ${ARCHIVAL_APPLICATION_INSIGHTS_INSTRUMENTATION_KEY} ConnectionStrings__SchedulingConnection: ${ARCHIVAL_REDIS_CONNECTION_STRING} Api__DirectoryHost: ${DIRECTORY_HOST} @@ -48,7 +50,10 @@ services: directory: depends_on: - directory-db + volumes: + - directory-application-insights:/app/${APPLICATION_INSIGHTS_SERVER_TELEMETRY_CHANNEL_STORAGE_PATH} environment: + ApplicationInsights__ServerTelemetryChannelStoragePath: ${APPLICATION_INSIGHTS_SERVER_TELEMETRY_CHANNEL_STORAGE_PATH} ApplicationInsights__InstrumentationKey: ${DIRECTORY_APPLICATION_INSIGHTS_INSTRUMENTATION_KEY} ConnectionStrings__DirectoryConnection: ${DIRECTORY_CONNECTION_STRING} @@ -70,6 +75,8 @@ networks: directory: volumes: + archival-application-insights: archival-scheduling-db: archival-archives: + directory-application-insights: directory-db: diff --git a/services/Directory/FilterLists.Directory.Api/appsettings.Development.json b/services/Directory/FilterLists.Directory.Api/appsettings.Development.json index 281e60be0..d3fc623ea 100644 --- a/services/Directory/FilterLists.Directory.Api/appsettings.Development.json +++ b/services/Directory/FilterLists.Directory.Api/appsettings.Development.json @@ -1,5 +1,8 @@ { "_comment": "Used only for managing EF migrations. All other configuration is done via environment variables.", + "ApplicationInsights": { + "ServerTelemetryChannelStoragePath": "application-insights" + }, "ConnectionStrings": { "DirectoryConnection": "Server=directory-db;Database=filterlists;User Id=filterlists;Password=filterlists;" } diff --git a/services/SharedKernel/FilterLists.SharedKernel.Logging/ConfigurationExtensions.cs b/services/SharedKernel/FilterLists.SharedKernel.Logging/ConfigurationExtensions.cs index 37f3315c5..76ab48a6e 100644 --- a/services/SharedKernel/FilterLists.SharedKernel.Logging/ConfigurationExtensions.cs +++ b/services/SharedKernel/FilterLists.SharedKernel.Logging/ConfigurationExtensions.cs @@ -1,4 +1,7 @@ using System; +using FilterLists.SharedKernel.Logging.Options; +using Microsoft.ApplicationInsights.Channel; +using Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel; using Microsoft.AspNetCore.Builder; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; @@ -18,6 +21,13 @@ public static void AddSharedKernelLogging(this IServiceCollection services, ICon { _ = configuration ?? throw new ArgumentNullException(nameof(configuration)); + using var serverTelemetryChannel = new ServerTelemetryChannel + { + StorageFolder = configuration.GetSection(ApplicationInsightsOptions.Key) + .Get() + .ServerTelemetryChannelStoragePath + }; + services.AddSingleton(typeof(ITelemetryChannel), serverTelemetryChannel); services.AddApplicationInsightsTelemetry(); } diff --git a/services/SharedKernel/FilterLists.SharedKernel.Logging/Options/ApplicationInsightsOptions.cs b/services/SharedKernel/FilterLists.SharedKernel.Logging/Options/ApplicationInsightsOptions.cs new file mode 100644 index 000000000..21a233811 --- /dev/null +++ b/services/SharedKernel/FilterLists.SharedKernel.Logging/Options/ApplicationInsightsOptions.cs @@ -0,0 +1,9 @@ +namespace FilterLists.SharedKernel.Logging.Options +{ + internal class ApplicationInsightsOptions + { + public const string Key = "ApplicationInsights"; + + public string ServerTelemetryChannelStoragePath { get; set; } = null!; + } +}