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
Original file line number Diff line number Diff line change
Expand Up @@ -251,29 +251,12 @@ The project is **pre-configured** for easy integration with popular logging prov

### How It Works

The OpenTelemetry configuration automatically exports to Application Insights if a connection string is provided:
1- The OpenTelemetry configuration automatically exports to Application Insights if a connection string is provided:

From [`src/Server/Boilerplate.Server.Shared/Extensions/WebApplicationBuilderExtensions.cs`](/src/Server/Boilerplate.Server.Shared/Extensions/WebApplicationBuilderExtensions.cs):

```csharp
private static TBuilder AddOpenTelemetryExporters<TBuilder>(this TBuilder builder)
where TBuilder : IHostApplicationBuilder
{
var appInsightsConnectionString = string.IsNullOrWhiteSpace(builder.Configuration["ApplicationInsights:ConnectionString"]) is false
? builder.Configuration["ApplicationInsights:ConnectionString"]
: null;
From [`src/Server/Boilerplate.Server.Shared/Extensions/IOpenTelemetryExtensions.cs`](/src/Server/Boilerplate.Server.Shared/Extensions/IOpenTelemetryExtensions.cs):

if (appInsightsConnectionString is not null)
{
builder.Services.AddOpenTelemetry().UseAzureMonitor(options =>
{
builder.Configuration.Bind("ApplicationInsights", options);
}).AddAzureMonitorProfiler();
}

return builder;
}
```
2- The Azure Application Insights JavaScript SDK added by `BlazorApplicationInsights` nuget in Client.Core project would collect JavaScript errors and more from
Browser and Blazor Hybrid's WebView

### OpenTelemetry Configuration

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ protected async Task Abort()
using var currentCts = cts;
cts = new();

await currentCts.CancelAsync();
await currentCts.TryCancel();
}

public async ValueTask DisposeAsync()
Expand All @@ -264,7 +264,7 @@ public async ValueTask DisposeAsync()
{
using var currentCts = cts;
cts = null;
await currentCts.CancelAsync();
await currentCts.TryCancel();
}

await DisposeAsync(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ private async Task SetCurrentUser(Task<AuthenticationState> task)

using var currentCts = getCurrentUserCts;
getCurrentUserCts = new();
await currentCts.CancelAsync();
await currentCts.TryCancel();

if (authUser.IsAuthenticated() is false)
{
Expand Down Expand Up @@ -196,7 +196,7 @@ public async ValueTask DisposeAsync()
{
if (getCurrentUserCts is not null)
{
await getCurrentUserCts.CancelAsync();
await getCurrentUserCts.TryCancel();
getCurrentUserCts.Dispose();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ private async Task HandleOnSelectRole(BitNavItem? item)
using var currentCts = loadRoleDataCts;
loadRoleDataCts = new();

await currentCts.CancelAsync();
await currentCts.TryCancel();
}

loadRoleDataCts = new();
Expand Down Expand Up @@ -398,7 +398,7 @@ protected override async ValueTask DisposeAsync(bool disposing)
{
if (loadRoleDataCts is not null)
{
await loadRoleDataCts.CancelAsync();
await loadRoleDataCts.TryCancel();
loadRoleDataCts.Dispose();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ private async Task HandleOnSelectUser(BitNavItem? item)
using var currentCts = loadRoleDataCts;
loadRoleDataCts = new();

await currentCts.CancelAsync();
await currentCts.TryCancel();
}

loadRoleDataCts = new();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">
<Project Sdk="Microsoft.NET.Sdk.Razor">

<PropertyGroup>
<TargetFrameworks>net10.0-android;net10.0-ios;net10.0-maccatalyst</TargetFrameworks>
Expand Down Expand Up @@ -167,12 +167,12 @@
<PackageReference Include="Microsoft.AspNetCore.Components.WebView.Maui" />
<PackageReference Include="Microsoft.Extensions.Logging.EventLog" />
<PackageReference Include="Microsoft.Extensions.Logging.EventSource" />
<!--/+:msbuild-conditional:noEmit -->
<PackageReference Condition="'$(module)' == 'Admin' OR '$(module)' == ''" Include="Newtonsoft.Json" />
<PackageReference Include="Oscore.Maui.AppStoreInfo" />
<PackageReference Include="Plugin.Maui.AppRating" />
<!--/+:msbuild-conditional:noEmit -->
<PackageReference Condition="'$(module)' == 'Admin' OR '$(module)' == ''" Include="Newtonsoft.Json" />
<PackageReference Condition=" '$(sentry)' == 'true' OR '$(sentry)' == '' " Include="Sentry.Maui" />
<PackageReference Condition=" '$(appInsights)' == 'true' OR '$(appInsights)' == '' " Include="Microsoft.Extensions.Logging.ApplicationInsights" />
<PackageReference Condition=" '$(appInsights)' == 'true' OR '$(appInsights)' == '' " Include="Azure.Monitor.OpenTelemetry.Exporter" />
<PackageReference Condition=" '$(notification)' == 'true' OR '$(notification)' == ''" Include="Plugin.LocalNotification" />
<!--/-:msbuild-conditional:noEmit -->
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
using Microsoft.Extensions.Logging;
//+:cnd:noEmit
using Microsoft.Extensions.Logging;
using Boilerplate.Client.Maui.Services;
//#if (appInsights == true)
using Azure.Monitor.OpenTelemetry.Exporter;
//#endif
using Boilerplate.Client.Core.Services.HttpMessageHandlers;

namespace Boilerplate.Client.Maui;
Expand Down Expand Up @@ -52,23 +56,26 @@ public static void ConfigureServices(this MauiAppBuilder builder)

builder.Logging.AddEventSourceLogger();

if (AppPlatform.IsWindows)
{
builder.Logging.AddEventLog(options => configuration.GetRequiredSection("Logging:EventLog").Bind(options));
}

//+:cnd:noEmit
//#if (appInsights == true)
if (string.IsNullOrEmpty(settings.ApplicationInsights?.ConnectionString) is false)
builder.Logging.AddOpenTelemetry(options =>
{
builder.Logging.AddApplicationInsights(config =>
options.IncludeFormattedMessage = true;
options.IncludeScopes = true;

if (string.IsNullOrEmpty(settings.ApplicationInsights?.ConnectionString) is false)
{
config.TelemetryInitializers.Add(new MauiAppInsightsTelemetryInitializer());
configuration.GetRequiredSection("ApplicationInsights").Bind(config);
}, options => configuration.GetRequiredSection("Logging:ApplicationInsights").Bind(options));
}
options.AddAzureMonitorLogExporter(o =>
{
o.ConnectionString = settings.ApplicationInsights.ConnectionString;
});
}
});
//#endif
//-:cnd:noEmit

if (AppPlatform.IsWindows)
{
builder.Logging.AddEventLog(options => configuration.GetRequiredSection("Logging:EventLog").Bind(options));
}

services.AddOptions<ClientMauiSettings>()
.Bind(configuration)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,16 @@

<PackageReference Include="EmbedIO" />
<PackageReference Include="Bit.BlazorES2019" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" />
<PackageReference Include="Microsoft.Extensions.Logging.EventLog" />
<PackageReference Include="Microsoft.Extensions.Logging.EventSource" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebView.WindowsForms" />
<PackageReference Include="Microsoft.Web.WebView2" />
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" />
<PackageReference Include="Velopack" />
<!--/+:msbuild-conditional:noEmit -->
<PackageReference Condition="'$(module)' == 'Admin' OR '$(module)' == ''" Include="Newtonsoft.Json" />
<PackageReference Condition=" '$(appInsights)' == 'true' OR '$(appInsights)' == '' " Include="Microsoft.Extensions.Logging.ApplicationInsights" />
<PackageReference Condition=" '$(appInsights)' == 'true' OR '$(appInsights)' == '' " Include="Azure.Monitor.OpenTelemetry.Exporter" />
<!--/-:msbuild-conditional:noEmit -->
<Content Include="..\Boilerplate.Client.Maui\wwwroot\index.html" Link="wwwroot\index.html">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
//+:cnd:noEmit
using OpenTelemetry.Logs;
using Microsoft.Extensions.Logging;
using Boilerplate.Client.Windows.Services;
//#if (appInsights == true)
using Azure.Monitor.OpenTelemetry.Exporter;
//#endif
using Boilerplate.Client.Core.Services.HttpMessageHandlers;

namespace Boilerplate.Client.Windows;
Expand Down Expand Up @@ -54,17 +58,29 @@ public static void AddClientWindowsProjectServices(this IServiceCollection servi
loggingBuilder.ConfigureLoggers(configuration);
loggingBuilder.AddEventSourceLogger();

loggingBuilder.AddEventLog(options => configuration.GetRequiredSection("Logging:EventLog").Bind(options));
//#if (appInsights == true)
if (string.IsNullOrEmpty(settings.ApplicationInsights?.ConnectionString) is false)
loggingBuilder.AddOpenTelemetry(options =>
{
loggingBuilder.AddApplicationInsights(config =>
options.IncludeFormattedMessage = true;
options.IncludeScopes = true;

//#if (appInsights == true)
if (string.IsNullOrEmpty(settings.ApplicationInsights?.ConnectionString) is false)
{
config.TelemetryInitializers.Add(new WindowsAppInsightsTelemetryInitializer());
configuration.GetRequiredSection("ApplicationInsights").Bind(config);
}, options => configuration.GetRequiredSection("Logging:ApplicationInsights").Bind(options));
}
//#endif
options.AddAzureMonitorLogExporter(o =>
{
o.ConnectionString = settings.ApplicationInsights.ConnectionString;
});
}
//#endif

var useOtlpExporter = string.IsNullOrWhiteSpace(configuration["OTEL_EXPORTER_OTLP_ENDPOINT"]) is false;
if (useOtlpExporter)
{
options.AddOtlpExporter();
}
});

loggingBuilder.AddEventLog(options => configuration.GetRequiredSection("Logging:EventLog").Bind(options));
});

services.AddOptions<ClientWindowsSettings>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ public static void Main(string[] args)

Application.SetColorMode(SystemColorMode.System);

var configuration = new ConfigurationBuilder().AddClientConfigurations(clientEntryAssemblyName: "Boilerplate.Client.Windows").Build();
var configuration = new ConfigurationBuilder()
.AddClientConfigurations(clientEntryAssemblyName: "Boilerplate.Client.Windows")
.AddEnvironmentVariables()
.Build();

var services = new ServiceCollection();
services.AddClientWindowsProjectServices(configuration);
Services = services.BuildServiceProvider();
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
<PackageVersion Include="AspNetCore.HealthChecks.Hangfire" Version="9.0.0" />
<PackageVersion Include="AspNetCore.HealthChecks.System" Version="9.0.0" />
<PackageVersion Include="AspNetCore.HealthChecks.UI.Client" Version="9.0.0" />
<PackageVersion Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="10.0.0" />
<PackageVersion Include="Microsoft.Extensions.Diagnostics.HealthChecks.EntityFrameworkCore" Version="10.0.0" />
<PackageVersion Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="10.0.0" />
<PackageVersion Include="Microsoft.Extensions.Options.DataAnnotations" Version="10.0.0" />
Expand Down Expand Up @@ -54,6 +55,7 @@
<PackageVersion Include="Microsoft.Extensions.Logging.EventSource" Version="10.0.0" />
<!--/+:msbuild-conditional:noEmit -->
<PackageVersion Condition="'$(signalR)' == 'true' OR '$(signalR)' == ''" Include="ModelContextProtocol.AspNetCore" Version="0.4.0-preview.3" />
<PackageVersion Condition=" '$(aspire)' == 'true' OR '$(aspire)' == '' " Include="Aspire.Hosting.Maui" Version="13.0.0-preview.1.25560.3" />
<PackageVersion Condition=" '$(aspire)' == 'true' OR '$(aspire)' == '' " Include="Aspire.Hosting.Testing" Version="13.0.0" />
<PackageVersion Condition=" '$(aspire)' == 'true' OR '$(aspire)' == '' " Include="CommunityToolkit.Aspire.Hosting.MailPit" Version="9.9.0" />
<PackageVersion Condition=" '$(aspire)' == 'true' OR '$(aspire)' == '' " Include="Aspire.Hosting.DevTunnels" Version="13.0.0-preview.1.25560.3" />
Expand All @@ -74,9 +76,9 @@
<PackageVersion Include="OpenTelemetry.Instrumentation.Runtime" Version="1.14.0" />
<PackageVersion Include="Hangfire.AspNetCore" Version="1.8.22" />
<PackageVersion Include="Hangfire.EntityFrameworkCore" Version="0.8.0" />
<PackageVersion Condition=" '$(sentry)' == 'true' OR '$(sentry)' == '' " Include="Sentry.AspNetCore" Version="6.0.0-preview.2-prerelease" />
<PackageVersion Condition=" '$(sentry)' == 'true' OR '$(sentry)' == '' " Include="Sentry.Extensions.Logging" Version="6.0.0-preview.2-prerelease" />
<PackageVersion Condition=" '$(sentry)' == 'true' OR '$(sentry)' == '' " Include="Sentry.Maui" Version="6.0.0-preview.2-prerelease" />
<PackageVersion Condition=" '$(sentry)' == 'true' OR '$(sentry)' == '' " Include="Sentry.AspNetCore" Version="6.0.0-rc.1-prerelease" />
<PackageVersion Condition=" '$(sentry)' == 'true' OR '$(sentry)' == '' " Include="Sentry.Extensions.Logging" Version="6.0.0-rc.1-prerelease" />
<PackageVersion Condition=" '$(sentry)' == 'true' OR '$(sentry)' == '' " Include="Sentry.Maui" Version="6.0.0-rc.1-prerelease" />
<PackageVersion Condition=" '$(notification)' == 'true' OR '$(notification)' == ''" Include="Xamarin.Firebase.Messaging" Version="125.0.1" />
<PackageVersion Condition=" '$(notification)' == 'true' OR '$(notification)' == ''" Include="Plugin.LocalNotification" Version="12.0.2" />
<PackageVersion Condition=" '$(notification)' == 'true' OR '$(notification)' == ''" Include="AdsPush" Version="2.0.0" />
Expand All @@ -91,7 +93,7 @@
<PackageVersion Condition=" ('$(signalR)' == 'true' OR '$(signalR)' == '') OR ('$(database)' == 'PostgreSQL' OR '$(database)' == '') OR ('$(database)' == 'SqlServer' OR '$(database)' == '') " Include="Microsoft.SemanticKernel.Core" Version="1.67.1" />
<PackageVersion Condition=" ('$(database)' == 'PostgreSQL' OR '$(database)' == '') " Include="Pgvector.EntityFrameworkCore" Version="0.2.2" />
<PackageVersion Condition="'$(module)' == 'Admin' OR '$(module)' == ''" Include="Newtonsoft.Json" Version="13.0.4" />
<PackageVersion Condition=" '$(appInsights)' == 'true' OR '$(appInsights)' == '' " Include="Microsoft.Extensions.Logging.ApplicationInsights" Version="2.23.0" />
<PackageVersion Condition=" '$(appInsights)' == 'true' OR '$(appInsights)' == '' " Include="Azure.Monitor.OpenTelemetry.Exporter" Version="1.5.0" />
<PackageVersion Condition=" '$(appInsights)' == 'true' OR '$(appInsights)' == '' " Include="BlazorApplicationInsights" Version="3.3.0" />
<PackageVersion Condition=" '$(database)' == 'SqlServer' OR '$(database)' == '' " Include="Microsoft.EntityFrameworkCore.SqlServer" Version="10.0.0" />
<PackageVersion Condition=" '$(database)' == 'PostgreSQL' OR '$(database)' == '' " Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="10.0.0-rc.2" />
Expand Down
Loading
Loading