Skip to content

Commit cf6c82e

Browse files
committed
add reqiored open telemetry usages to bit Boilerplate (#11265)
1 parent 89ceab9 commit cf6c82e

File tree

7 files changed

+55
-17
lines changed

7 files changed

+55
-17
lines changed

src/Templates/Boilerplate/Bit.Boilerplate/src/Directory.Packages.props

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
<PackageVersion Include="Microsoft.Maui.Controls" Version="9.0.90" />
2828
<PackageVersion Include="Microsoft.AspNetCore.Components.WebView.Maui" Version="9.0.90" />
2929
<PackageVersion Include="Microsoft.AspNetCore.Components.WebView.WindowsForms" Version="9.0.90" />
30-
<PackageVersion Include="Microsoft.Web.WebView2" Version="1.0.3351.48" />
30+
<PackageVersion Include="Microsoft.Web.WebView2" Version="1.0.3405.78" />
3131
<PackageVersion Include="NWebsec.AspNetCore.Middleware" Version="3.0.0" />
3232
<PackageVersion Include="OpenTelemetry.Instrumentation.EntityFrameworkCore" Version="1.12.0-beta.2" />
3333
<PackageVersion Include="OpenTelemetry.Instrumentation.Hangfire" Version="1.12.0-beta.1" />
@@ -46,21 +46,21 @@
4646
<PackageVersion Include="Microsoft.Extensions.Logging.EventLog" Version="9.0.8" />
4747
<PackageVersion Include="Microsoft.Extensions.Logging.EventSource" Version="9.0.8" />
4848
<!--/+:msbuild-conditional:noEmit -->
49-
<PackageVersion Condition=" '$(aspire)' == 'true' OR '$(aspire)' == '' " Include="Aspire.Hosting.AppHost" Version="9.4.0" />
50-
<PackageVersion Condition=" ('$(aspire)' == 'true' OR '$(aspire)' == '') AND ('$(database)' == 'SqlServer' OR '$(database)' == '') " Include="Aspire.Hosting.SqlServer" Version="9.4.0" />
49+
<PackageVersion Condition=" '$(aspire)' == 'true' OR '$(aspire)' == '' " Include="Aspire.Hosting.AppHost" Version="9.4.1" />
50+
<PackageVersion Condition=" ('$(aspire)' == 'true' OR '$(aspire)' == '') AND ('$(database)' == 'SqlServer' OR '$(database)' == '') " Include="Aspire.Hosting.SqlServer" Version="9.4.1" />
5151
<PackageVersion Condition=" ('$(aspire)' == 'true' OR '$(aspire)' == '') AND ('$(database)' == 'SqlServer' OR '$(database)' == '') " Include="CommunityToolkit.Aspire.Hosting.SqlServer.Extensions" Version="9.7.0" />
52-
<PackageVersion Condition=" ('$(aspire)' == 'true' OR '$(aspire)' == '') AND ('$(database)' == 'PostgreSQL' OR '$(database)' == '') " Include="Aspire.Hosting.PostgreSQL" Version="9.4.0" />
53-
<PackageVersion Condition=" ('$(aspire)' == 'true' OR '$(aspire)' == '') AND ('$(database)' == 'MySql' OR '$(database)' == '') " Include="Aspire.Hosting.MySql" Version="9.4.0" />
54-
<PackageVersion Condition=" ('$(aspire)' == 'true' OR '$(aspire)' == '') AND ('$(filesStorage)' == 'AzureBlobStorage' OR '$(filesStorage)' == '') " Include="Aspire.Hosting.Azure.Storage" Version="9.4.0" />
52+
<PackageVersion Condition=" ('$(aspire)' == 'true' OR '$(aspire)' == '') AND ('$(database)' == 'PostgreSQL' OR '$(database)' == '') " Include="Aspire.Hosting.PostgreSQL" Version="9.4.1" />
53+
<PackageVersion Condition=" ('$(aspire)' == 'true' OR '$(aspire)' == '') AND ('$(database)' == 'MySql' OR '$(database)' == '') " Include="Aspire.Hosting.MySql" Version="9.4.1" />
54+
<PackageVersion Condition=" ('$(aspire)' == 'true' OR '$(aspire)' == '') AND ('$(filesStorage)' == 'AzureBlobStorage' OR '$(filesStorage)' == '') " Include="Aspire.Hosting.Azure.Storage" Version="9.4.1" />
5555
<PackageVersion Condition=" ('$(aspire)' == 'true' OR '$(aspire)' == '') AND ('$(filesStorage)' == 'S3' OR '$(filesStorage)' == '') " Include="CommunityToolkit.Aspire.Hosting.Minio" Version="9.7.0" />
56-
<PackageVersion Include="Microsoft.Extensions.Http.Resilience" Version="9.7.0" />
57-
<PackageVersion Include="Microsoft.Extensions.ServiceDiscovery" Version="9.4.0" />
56+
<PackageVersion Include="Microsoft.Extensions.Http.Resilience" Version="9.8.0" />
57+
<PackageVersion Include="Microsoft.Extensions.ServiceDiscovery" Version="9.4.1" />
5858
<PackageVersion Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.12.0" />
5959
<PackageVersion Include="OpenTelemetry.Extensions.Hosting" Version="1.12.0" />
6060
<PackageVersion Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.12.0" />
6161
<PackageVersion Include="OpenTelemetry.Instrumentation.Http" Version="1.12.0" />
6262
<PackageVersion Include="OpenTelemetry.Instrumentation.Runtime" Version="1.12.0" />
63-
<PackageVersion Include="Hangfire.AspNetCore" Version="1.8.20" />
63+
<PackageVersion Include="Hangfire.AspNetCore" Version="1.8.21" />
6464
<PackageVersion Include="Hangfire.EntityFrameworkCore" Version="0.7.0" />
6565
<PackageVersion Condition=" '$(sentry)' == 'true' OR '$(sentry)' == '' " Include="Sentry.AspNetCore" Version="5.13.0" />
6666
<PackageVersion Condition=" '$(sentry)' == 'true' OR '$(sentry)' == '' " Include="Sentry.Extensions.Logging" Version="5.13.0" />
@@ -73,7 +73,7 @@
7373
<PackageVersion Condition=" '$(offlineDb)' == 'true' OR '$(offlineDb)' == ''" Include="Bit.Besql" Version="9.11.3" />
7474
<PackageVersion Condition=" '$(signalR)' == 'true' OR '$(signalR)' == ''" Include="Microsoft.AspNetCore.SignalR.Client" Version="9.0.8" />
7575
<PackageVersion Condition=" '$(signalR)' == 'true' OR '$(signalR)' == ''" Include="Microsoft.Azure.SignalR" Version="1.31.0" />
76-
<PackageVersion Condition=" ('$(signalR)' == 'true' OR '$(signalR)' == '') OR ('$(database)' == 'PostgreSQL' OR '$(database)' == '') OR ('$(database)' == 'SqlServer' OR '$(database)' == '') " Include="Microsoft.Extensions.AI" Version="9.7.1" />
76+
<PackageVersion Condition=" ('$(signalR)' == 'true' OR '$(signalR)' == '') OR ('$(database)' == 'PostgreSQL' OR '$(database)' == '') OR ('$(database)' == 'SqlServer' OR '$(database)' == '') " Include="Microsoft.Extensions.AI" Version="9.8.0" />
7777
<PackageVersion Condition=" ('$(signalR)' == 'true' OR '$(signalR)' == '') OR ('$(database)' == 'PostgreSQL' OR '$(database)' == '') OR ('$(database)' == 'SqlServer' OR '$(database)' == '') " Include="Microsoft.Extensions.AI.OpenAI" Version="9.7.1-preview.1.25365.4" />
7878
<PackageVersion Condition=" ('$(signalR)' == 'true' OR '$(signalR)' == '') OR ('$(database)' == 'PostgreSQL' OR '$(database)' == '') OR ('$(database)' == 'SqlServer' OR '$(database)' == '') " Include="Microsoft.Extensions.AI.AzureAIInference" Version="9.7.1-preview.1.25365.4" />
7979
<PackageVersion Condition=" ('$(database)' == 'PostgreSQL' OR '$(database)' == '') " Include="Pgvector.EntityFrameworkCore" Version="0.2.2" />
@@ -103,7 +103,7 @@
103103
<PackageVersion Include="Microsoft.EntityFrameworkCore.Tools" Version="9.0.8" />
104104
<PackageVersion Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.8" />
105105
<PackageVersion Include="Swashbuckle.AspNetCore" Version="9.0.3" />
106-
<PackageVersion Include="Microsoft.Identity.Web" Version="3.12.0" />
106+
<PackageVersion Include="Microsoft.Identity.Web" Version="3.13.0" />
107107
<PackageVersion Include="Microsoft.AspNetCore.Authentication.Google" Version="9.0.8" />
108108
<PackageVersion Include="Microsoft.AspNetCore.Authentication.Twitter" Version="9.0.8" />
109109
<PackageVersion Include="Microsoft.AspNetCore.Authentication.Facebook" Version="9.0.8" />
@@ -122,7 +122,7 @@
122122
<PackageVersion Include="FakeItEasy" Version="8.3.0" />
123123
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
124124
<PackageVersion Include="Microsoft.Playwright.MSTest" Version="1.54.0" />
125-
<PackageVersion Include="MSTest.TestAdapter" Version="3.10.0" />
126-
<PackageVersion Include="MSTest.TestFramework" Version="3.10.0" />
125+
<PackageVersion Include="MSTest.TestAdapter" Version="3.10.2" />
126+
<PackageVersion Include="MSTest.TestFramework" Version="3.10.2" />
127127
</ItemGroup>
128128
</Project>

src/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Api/Controllers/AttachmentController.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ private async Task<IActionResult> UploadAttachment(Guid attachmentId, Attachment
185185

186186
if (imageResizeContext.NeedsResize)
187187
{
188+
Stopwatch stopwatch = Stopwatch.StartNew();
188189
using MagickImage sourceImage = new(file.OpenReadStream());
189190

190191
if (sourceImage.Width < imageResizeContext.Width || sourceImage.Height < imageResizeContext.Height)
@@ -193,6 +194,9 @@ private async Task<IActionResult> UploadAttachment(Guid attachmentId, Attachment
193194
sourceImage.Resize(new MagickGeometry(imageResizeContext.Width, imageResizeContext.Height));
194195

195196
await blobStorage.WriteAsync(attachment.Path, imageBytes = sourceImage.ToByteArray(MagickFormat.WebP), cancellationToken: cancellationToken);
197+
198+
AppActivitySource.CurrentMeter.CreateHistogram<double>("attachment.upload_resize_duration")
199+
.Record(stopwatch.Elapsed.TotalMilliseconds, new KeyValuePair<string, object?>("kind", kind.ToString()));
196200
}
197201
else
198202
{

src/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Api/SignalR/AppHub.Chatbot.cs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ async Task ReadIncomingMessages()
7171
finally
7272
{
7373
messageSpecificCancellationTokenSrc?.Dispose();
74+
channel.Writer.Complete();
7475
}
7576

7677
async Task HandleIncomingMessage(string incomingMessage, CancellationToken messageSpecificCancellationToken)
@@ -85,11 +86,16 @@ async Task HandleIncomingMessage(string incomingMessage, CancellationToken messa
8586
Tools = [
8687
AIFunctionFactory.Create(async (string emailAddress, string conversationHistory) =>
8788
{
89+
if (messageSpecificCancellationToken.IsCancellationRequested)
90+
return;
91+
8892
await using var scope = serviceProvider.CreateAsyncScope();
93+
8994
// Ideally, store these in a CRM or app database,
9095
// but for now, we'll log them!
9196
scope.ServiceProvider.GetRequiredService<ILogger<IChatClient>>()
9297
.LogError("Chat reported issue: User email: {emailAddress}, Conversation history: {conversationHistory}", emailAddress, conversationHistory);
98+
9399
}, name: "SaveUserEmailAndConversationHistory", description: "Saves the user's email address and the conversation history for future reference. Use this tool when the user provides their email address during the conversation. Parameters: emailAddress (string), conversationHistory (string)"),
94100
//#if (module == "Sales")
95101
AIFunctionFactory.Create(async ([Description("Concise summary of these user requirements")] string userNeeds,
@@ -159,9 +165,20 @@ async Task HandleIncomingMessage(string incomingMessage, CancellationToken messa
159165

160166
_ = ReadIncomingMessages();
161167

162-
await foreach (var str in channel.Reader.ReadAllAsync(cancellationToken).WithCancellation(cancellationToken))
168+
var ongoingConversationsCount = AppActivitySource.CurrentMeter.CreateUpDownCounter<long>("appHub.ongoing_conversations_count", "Number of ongoing conversations in the chatbot hub.");
169+
170+
try
171+
{
172+
ongoingConversationsCount.Add(1);
173+
174+
await foreach (var str in channel.Reader.ReadAllAsync(cancellationToken).WithCancellation(cancellationToken))
175+
{
176+
yield return str;
177+
}
178+
}
179+
finally
163180
{
164-
yield return str;
181+
ongoingConversationsCount.Add(-1);
165182
}
166183
}
167184

src/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.AppHost/.config/dotnet-tools.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"isRoot": true,
44
"tools": {
55
"aspire.cli": {
6-
"version": "9.4.0",
6+
"version": "9.4.1",
77
"commands": [
88
"aspire"
99
]

src/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.AppHost/Extensions/IDistributedApplicationBuilderExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public static void AddAspireDashboard(this IDistributedApplicationBuilder builde
1414
if (builder.ExecutionContext.IsPublishMode)
1515
{
1616
// The name aspire-dashboard is special cased and excluded from the default
17-
var dashboard = builder.AddContainer("dashboard", "mcr.microsoft.com/dotnet/aspire-dashboard:9.3")
17+
var dashboard = builder.AddContainer("dashboard", "mcr.microsoft.com/dotnet/aspire-dashboard:9.4")
1818
.WithHttpEndpoint(targetPort: 18888)
1919
.WithHttpEndpoint(name: "otlp", targetPort: 18889);
2020

src/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Shared/Extensions/WebApplicationBuilderExtensions.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ private static TBuilder ConfigureOpenTelemetry<TBuilder>(this TBuilder builder)
124124
metrics.AddAspNetCoreInstrumentation()
125125
.AddHttpClientInstrumentation()
126126
.AddRuntimeInstrumentation();
127+
128+
metrics.AddMeter(AppActivitySource.CurrentMeter.Name);
127129
})
128130
.WithTracing(tracing =>
129131
{
@@ -144,6 +146,8 @@ private static TBuilder ConfigureOpenTelemetry<TBuilder>(this TBuilder builder)
144146
.AddHttpClientInstrumentation()
145147
.AddEntityFrameworkCoreInstrumentation(options => options.Filter = (providerName, command) => command?.CommandText?.Contains("Hangfire") is false /* Ignore Hangfire */)
146148
.AddHangfireInstrumentation();
149+
150+
tracing.AddSource(AppActivitySource.CurrentActivity.Name);
147151
})
148152
.ConfigureResource(resource =>
149153
{
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System.Diagnostics.Metrics;
2+
3+
namespace Boilerplate.Shared.Services;
4+
5+
/// <summary>
6+
/// Open telemetry activity source for the application.
7+
/// </summary>
8+
public class AppActivitySource
9+
{
10+
public static ActivitySource CurrentActivity = new("Boilerplate", typeof(AppActivitySource).Assembly.GetName().Version!.ToString());
11+
12+
public static Meter CurrentMeter = new("Boilerplate", typeof(AppActivitySource).Assembly.GetName().Version!.ToString());
13+
}

0 commit comments

Comments
 (0)