From 045c628853ad94d8914c3c438e149c116a98413f Mon Sep 17 00:00:00 2001 From: kuberto773 Date: Mon, 10 Nov 2025 09:23:03 +0100 Subject: [PATCH 1/4] chore: added conn string to app insights --- .../DependencyExtensions.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Madev.Utils.Infrastructure.ApplicationInsights.AspNetCore/DependencyExtensions.cs b/src/Madev.Utils.Infrastructure.ApplicationInsights.AspNetCore/DependencyExtensions.cs index d747911..64c4acb 100644 --- a/src/Madev.Utils.Infrastructure.ApplicationInsights.AspNetCore/DependencyExtensions.cs +++ b/src/Madev.Utils.Infrastructure.ApplicationInsights.AspNetCore/DependencyExtensions.cs @@ -6,11 +6,12 @@ namespace Madev.Utils.Infrastructure.ApplicationInsights.AspNetCore; public static class DependencyExtensions { - public static IServiceCollection AddMadevApplicationInsightsTelemetry(this IServiceCollection services, + public static IServiceCollection AddMadevApplicationInsightsTelemetry(this IServiceCollection services, + string connectionString, string roleName, string[] excludedOperations = null) { - services.AddApplicationInsightsTelemetry(); + services.AddApplicationInsightsTelemetry(conf => conf.ConnectionString = connectionString); services.AddSingleton(new RoleNameTelemetryInitializer(roleName)); excludedOperations ??= []; From 543abe6d396daa75129a3c3e060cca28a96da9ef Mon Sep 17 00:00:00 2001 From: kuberto773 Date: Mon, 10 Nov 2025 09:32:29 +0100 Subject: [PATCH 2/4] chore: insights worker service + conn string --- Madev.Utils.sln | 2 ++ .../DependencyExtensions.cs | 25 +++++++++++++++++++ .../ExcludeOperationsTelemetryProcessor.cs | 18 +++++++++++++ ...e.ApplicationInsights.WorkerService.csproj | 19 ++++++++++++++ .../RoleNameTelemetryInitializer.cs | 13 ++++++++++ .../TelemetryProcessorFactory.cs | 12 +++++++++ 6 files changed, 89 insertions(+) create mode 100644 src/Madev.Utils.Infrastructure.ApplicationInsights.WorkerService/DependencyExtensions.cs create mode 100644 src/Madev.Utils.Infrastructure.ApplicationInsights.WorkerService/ExcludeOperationsTelemetryProcessor.cs create mode 100644 src/Madev.Utils.Infrastructure.ApplicationInsights.WorkerService/Madev.Utils.Infrastructure.ApplicationInsights.WorkerService.csproj create mode 100644 src/Madev.Utils.Infrastructure.ApplicationInsights.WorkerService/RoleNameTelemetryInitializer.cs create mode 100644 src/Madev.Utils.Infrastructure.ApplicationInsights.WorkerService/TelemetryProcessorFactory.cs diff --git a/Madev.Utils.sln b/Madev.Utils.sln index 6b9ad4e..991e29a 100644 --- a/Madev.Utils.sln +++ b/Madev.Utils.sln @@ -15,6 +15,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Madev.Utils.Infrastructure. EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Madev.Utils.Infrastructure.ApplicationInsights.AspNetCore", "src\Madev.Utils.Infrastructure.ApplicationInsights.AspNetCore\Madev.Utils.Infrastructure.ApplicationInsights.AspNetCore.csproj", "{6E266322-CCCA-4774-892B-30F1690FD734}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Madev.Utils.Infrastructure.ApplicationInsights.WorkerService", "src\Madev.Utils.Infrastructure.ApplicationInsights.WorkerService\Madev.Utils.Infrastructure.ApplicationInsights.WorkerService.csproj", "{9C8C911F-6BCF-4027-A088-FBA9104B7F7E}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU diff --git a/src/Madev.Utils.Infrastructure.ApplicationInsights.WorkerService/DependencyExtensions.cs b/src/Madev.Utils.Infrastructure.ApplicationInsights.WorkerService/DependencyExtensions.cs new file mode 100644 index 0000000..4f883e9 --- /dev/null +++ b/src/Madev.Utils.Infrastructure.ApplicationInsights.WorkerService/DependencyExtensions.cs @@ -0,0 +1,25 @@ +using Microsoft.ApplicationInsights.Extensibility; +using Microsoft.ApplicationInsights.WorkerService; +using Microsoft.Extensions.DependencyInjection; + +namespace Madev.Utils.Infrastructure.ApplicationInsights.WorkerService; + +public static class DependencyExtensions +{ + public static IServiceCollection AddMadevApplicationInsightsWorkerServiceTelemetry(this IServiceCollection services, + string connectionString, + string roleName, + string[] excludedOperations = null) + { + services.AddApplicationInsightsTelemetryWorkerService(config => config.ConnectionString = connectionString); + services.AddSingleton(new RoleNameTelemetryInitializer(roleName)); + + excludedOperations ??= []; + if (excludedOperations.Any()) + { + services.AddSingleton(new TelemetryProcessorFactory(excludedOperations)); + } + + return services; + } +} \ No newline at end of file diff --git a/src/Madev.Utils.Infrastructure.ApplicationInsights.WorkerService/ExcludeOperationsTelemetryProcessor.cs b/src/Madev.Utils.Infrastructure.ApplicationInsights.WorkerService/ExcludeOperationsTelemetryProcessor.cs new file mode 100644 index 0000000..1c83e83 --- /dev/null +++ b/src/Madev.Utils.Infrastructure.ApplicationInsights.WorkerService/ExcludeOperationsTelemetryProcessor.cs @@ -0,0 +1,18 @@ +using Microsoft.ApplicationInsights.Channel; +using Microsoft.ApplicationInsights.Extensibility; + +namespace Madev.Utils.Infrastructure.ApplicationInsights.WorkerService; + +internal class ExcludeOperationsTelemetryProcessor(ITelemetryProcessor nextProcessor, string[] excludedOperations) + : ITelemetryProcessor +{ + public void Process(ITelemetry item) + { + if (excludedOperations.Contains(item.Context.Operation.Name)) + { + return; + } + + nextProcessor.Process(item); + } +} \ No newline at end of file diff --git a/src/Madev.Utils.Infrastructure.ApplicationInsights.WorkerService/Madev.Utils.Infrastructure.ApplicationInsights.WorkerService.csproj b/src/Madev.Utils.Infrastructure.ApplicationInsights.WorkerService/Madev.Utils.Infrastructure.ApplicationInsights.WorkerService.csproj new file mode 100644 index 0000000..8b6da31 --- /dev/null +++ b/src/Madev.Utils.Infrastructure.ApplicationInsights.WorkerService/Madev.Utils.Infrastructure.ApplicationInsights.WorkerService.csproj @@ -0,0 +1,19 @@ + + + + net9.0 + enable + enable + Miroslav Adamec + Madev + Application insghts telemetry setup + https://github.com/madev/Madev.Utils + https://github.com/madev/Madev.Utils + mirecad madev telemetry application insights worker service tools utils extensions + https://madevfiles.blob.core.windows.net/$web/Madev/madev-icon.png + + + + + + diff --git a/src/Madev.Utils.Infrastructure.ApplicationInsights.WorkerService/RoleNameTelemetryInitializer.cs b/src/Madev.Utils.Infrastructure.ApplicationInsights.WorkerService/RoleNameTelemetryInitializer.cs new file mode 100644 index 0000000..7d4726f --- /dev/null +++ b/src/Madev.Utils.Infrastructure.ApplicationInsights.WorkerService/RoleNameTelemetryInitializer.cs @@ -0,0 +1,13 @@ +using Microsoft.ApplicationInsights.Channel; +using Microsoft.ApplicationInsights.Extensibility; + +namespace Madev.Utils.Infrastructure.ApplicationInsights.WorkerService; + +internal class RoleNameTelemetryInitializer(string roleName) + : ITelemetryInitializer +{ + public void Initialize(ITelemetry telemetry) + { + telemetry.Context.Cloud.RoleName = roleName; + } +} \ No newline at end of file diff --git a/src/Madev.Utils.Infrastructure.ApplicationInsights.WorkerService/TelemetryProcessorFactory.cs b/src/Madev.Utils.Infrastructure.ApplicationInsights.WorkerService/TelemetryProcessorFactory.cs new file mode 100644 index 0000000..bd6982c --- /dev/null +++ b/src/Madev.Utils.Infrastructure.ApplicationInsights.WorkerService/TelemetryProcessorFactory.cs @@ -0,0 +1,12 @@ +using Microsoft.ApplicationInsights.Extensibility; +using Microsoft.ApplicationInsights.WorkerService; + +namespace Madev.Utils.Infrastructure.ApplicationInsights.WorkerService; + +internal class TelemetryProcessorFactory(string[] excludedOperations) : ITelemetryProcessorFactory +{ + public ITelemetryProcessor Create(ITelemetryProcessor nextProcessor) + { + return new ExcludeOperationsTelemetryProcessor(nextProcessor, excludedOperations); + } +} \ No newline at end of file From 1475a91f008cfe32c5354a98af9c4a12ccdd4739 Mon Sep 17 00:00:00 2001 From: kuberto773 Date: Mon, 10 Nov 2025 09:33:48 +0100 Subject: [PATCH 3/4] build: added worker service project to CI --- .github/workflows/dotnet.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index a2625c5..d6c94a1 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -13,6 +13,7 @@ jobs: strategy: matrix: project: + - src/Madev.Utils.Infrastructure.ApplicationInsights.WorkerService/Madev.Utils.Infrastructure.ApplicationInsights.WorkerService.csproj - src/Madev.Utils.Infrastructure.ApplicationInsights.AspNetCore/Madev.Utils.Infrastructure.ApplicationInsights.AspNetCore.csproj - src/Madev.Utils.Infrastructure.Http/Madev.Utils.Infrastructure.Http.csproj - src/Madev.Utils.Infrastructure.Services.Mailing/Madev.Utils.Infrastructure.Services.Mailing.csproj From 3f552bfca7bbe2cc5df5d7f861eb5748b6c61104 Mon Sep 17 00:00:00 2001 From: kuberto773 Date: Mon, 10 Nov 2025 10:24:24 +0100 Subject: [PATCH 4/4] chore: declared nullable params --- .../DependencyExtensions.cs | 2 +- .../DependencyExtensions.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Madev.Utils.Infrastructure.ApplicationInsights.AspNetCore/DependencyExtensions.cs b/src/Madev.Utils.Infrastructure.ApplicationInsights.AspNetCore/DependencyExtensions.cs index 64c4acb..086bee6 100644 --- a/src/Madev.Utils.Infrastructure.ApplicationInsights.AspNetCore/DependencyExtensions.cs +++ b/src/Madev.Utils.Infrastructure.ApplicationInsights.AspNetCore/DependencyExtensions.cs @@ -9,7 +9,7 @@ public static class DependencyExtensions public static IServiceCollection AddMadevApplicationInsightsTelemetry(this IServiceCollection services, string connectionString, string roleName, - string[] excludedOperations = null) + string[]? excludedOperations = null) { services.AddApplicationInsightsTelemetry(conf => conf.ConnectionString = connectionString); services.AddSingleton(new RoleNameTelemetryInitializer(roleName)); diff --git a/src/Madev.Utils.Infrastructure.ApplicationInsights.WorkerService/DependencyExtensions.cs b/src/Madev.Utils.Infrastructure.ApplicationInsights.WorkerService/DependencyExtensions.cs index 4f883e9..7522192 100644 --- a/src/Madev.Utils.Infrastructure.ApplicationInsights.WorkerService/DependencyExtensions.cs +++ b/src/Madev.Utils.Infrastructure.ApplicationInsights.WorkerService/DependencyExtensions.cs @@ -9,7 +9,7 @@ public static class DependencyExtensions public static IServiceCollection AddMadevApplicationInsightsWorkerServiceTelemetry(this IServiceCollection services, string connectionString, string roleName, - string[] excludedOperations = null) + string[]? excludedOperations = null) { services.AddApplicationInsightsTelemetryWorkerService(config => config.ConnectionString = connectionString); services.AddSingleton(new RoleNameTelemetryInitializer(roleName));