Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions Madev.Utils.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
string[]? excludedOperations = null)
{
services.AddApplicationInsightsTelemetry();
services.AddApplicationInsightsTelemetry(conf => conf.ConnectionString = connectionString);
services.AddSingleton<ITelemetryInitializer>(new RoleNameTelemetryInitializer(roleName));

excludedOperations ??= [];
Expand Down
Original file line number Diff line number Diff line change
@@ -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<ITelemetryInitializer>(new RoleNameTelemetryInitializer(roleName));

excludedOperations ??= [];
if (excludedOperations.Any())
{
services.AddSingleton<ITelemetryProcessorFactory>(new TelemetryProcessorFactory(excludedOperations));
}

return services;
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Authors>Miroslav Adamec</Authors>
<Company>Madev</Company>
<Description>Application insghts telemetry setup</Description>
<PackageProjectUrl>https://github.com/madev/Madev.Utils</PackageProjectUrl>
<RepositoryUrl>https://github.com/madev/Madev.Utils</RepositoryUrl>
<PackageTags>mirecad madev telemetry application insights worker service tools utils extensions</PackageTags>
<PackageIconUrl>https://madevfiles.blob.core.windows.net/$web/Madev/madev-icon.png</PackageIconUrl>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.ApplicationInsights.WorkerService" Version="2.23.0" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
Loading