Skip to content

Commit

Permalink
adding signalr instrumentation for distributed tracing
Browse files Browse the repository at this point in the history
  • Loading branch information
macel94 committed Feb 5, 2024
1 parent 482e040 commit b4124ff
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="OpenTelemetry.Instrumentation.GrpcNetClient" Version="1.6.0-beta.3" />
<PackageReference Include="OpenTelemetry.Instrumentation.Process" Version="0.5.0-beta.4" />
<PackageReference Include="OpenTelemetry.Instrumentation.Runtime" Version="1.7.0" />
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.7.0" />
<PackageReference Include="OpenTelemetry.Instrumentation.Http" Version="1.7.0" />
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.7.0" />
<PackageReference Include="OpenTelemetry.Exporter.Console" Version="1.7.0" />
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.7.0" />
<PackageReference Include="AspNetCore.SignalR.OpenTelemetry" Version="1.1.0" />
<PackageReference Include="OpenTelemetry.Api" Version="1.7.0" />
</ItemGroup>

</Project>
15 changes: 7 additions & 8 deletions src/BlazorPong.Backend.Defaults/StartupExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Builder;
using AspNetCore.SignalR.OpenTelemetry;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Diagnostics.HealthChecks;
Expand Down Expand Up @@ -29,31 +30,29 @@ public static IHostApplicationBuilder ConfigureOpenTelemetry(this IHostApplicati
logging.SetResourceBuilder(ResourceBuilder.CreateDefault().AddService(builder.Environment.ApplicationName));
logging.IncludeFormattedMessage = true;
logging.IncludeScopes = true;
//logging.AddConsoleExporter();
});

builder.Services.AddOpenTelemetry()
.WithMetrics(metrics =>
{
metrics.SetResourceBuilder(ResourceBuilder.CreateDefault().AddService(builder.Environment.ApplicationName));
metrics.AddRuntimeInstrumentation()
.AddBuiltInMeters();
//metrics.AddConsoleExporter();
metrics.AddAspNetCoreInstrumentation()
.AddHttpClientInstrumentation()
.AddRuntimeInstrumentation()
.AddProcessInstrumentation();
})
.WithTracing(tracing =>
{
tracing.SetResourceBuilder(ResourceBuilder.CreateDefault().AddService(builder.Environment.ApplicationName));
if (builder.Environment.IsDevelopment())
{
// We want to view all traces in development
tracing.SetSampler(new AlwaysOnSampler());
}

tracing.AddAspNetCoreInstrumentation()
.AddSignalRInstrumentation()
.AddGrpcClientInstrumentation()
.AddHttpClientInstrumentation();

//tracing.AddConsoleExporter();
});

builder.AddOpenTelemetryExporters();
Expand Down
2 changes: 2 additions & 0 deletions src/BlazorPong.SignalR/BlazorPong.SignalR.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AspNetCore.SignalR.OpenTelemetry" Version="1.1.0" />
<PackageReference Include="OpenTelemetry.Api" Version="1.7.0" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.1">
Expand Down
4 changes: 3 additions & 1 deletion src/BlazorPong.SignalR/WebApplicationBuilderExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using BlazorPong.SignalR.Cache;
using AspNetCore.SignalR.OpenTelemetry;
using BlazorPong.SignalR.Cache;
using BlazorPong.SignalR.EFCore;
using BlazorPong.SignalR.Rooms;
using BlazorPong.SignalR.Rooms.Games;
Expand All @@ -15,6 +16,7 @@ public static void AddRedis(this WebApplicationBuilder builder)
{
var redisCs = builder.Configuration.GetConnectionString("Redis") ?? throw new Exception("Redis CS is missing");
builder.Services.AddSignalR()
.AddHubInstrumentation()
.AddStackExchangeRedis(redisCs,
options =>
{
Expand Down

0 comments on commit b4124ff

Please sign in to comment.