Skip to content

Commit

Permalink
Merge pull request #65 from argon-chat/feature/sentry-orleans
Browse files Browse the repository at this point in the history
add sentry filter for orleans, add sentry open telemetry
  • Loading branch information
urumo authored Nov 24, 2024
2 parents 2a02289 + 0a7006d commit 65015b7
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 11 deletions.
30 changes: 21 additions & 9 deletions src/Argon.Api/Features/Orleanse/OrleansExtension.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
namespace Argon.Api.Features;

using ActualLab.Serialization;
using Argon.Api.Features.Sentry;
using Contracts;
using Env;
using Extensions;
Expand All @@ -17,27 +18,38 @@ public static class OrleansExtension
public static WebApplicationBuilder AddOrleans(this WebApplicationBuilder builder)
{
builder.Services.AddSerializer(x => x.AddMessagePackSerializer(null, null, MessagePackByteSerializer.Default.Options));
builder.Host.UseOrleans(siloBuilder => {
siloBuilder.Configure<ClusterOptions>(builder.Configuration.GetSection("Orleans")).AddStreaming().UseDashboard(o => o.Port = 22832)
.AddActivityPropagation().AddAdoNetGrainStorage("PubSubStore", options =>
builder.Host.UseOrleans(siloBuilder =>
{
siloBuilder.Configure<ClusterOptions>(builder.Configuration.GetSection("Orleans"))
.AddStreaming()
.UseDashboard(o => o.Port = 22832)
.AddActivityPropagation()
.AddIncomingGrainCallFilter<SentryGrainCallFilter>()
.AddAdoNetGrainStorage("PubSubStore", options =>
{
options.Invariant = "Npgsql";
options.ConnectionString = builder.Configuration.GetConnectionString("DefaultConnection");
options.Invariant = "Npgsql";
options.ConnectionString = builder.Configuration.GetConnectionString("DefaultConnection");
}).AddAdoNetGrainStorage("OrleansStorage", options =>
{
options.Invariant = "Npgsql";
options.ConnectionString = builder.Configuration.GetConnectionString("DefaultConnection");
options.Invariant = "Npgsql";
options.ConnectionString = builder.Configuration.GetConnectionString("DefaultConnection");
});

if (builder.Environment.IsKube())
{
siloBuilder.UseKubeMembership().AddActivationRepartitioner<BalanceRule>().AddRedisStorage(IFusionSessionGrain.StorageId, 2)
siloBuilder
.UseKubeMembership()
.AddActivationRepartitioner<BalanceRule>()
.AddRedisStorage(IFusionSessionGrain.StorageId, 2)
.AddPersistentStreams("default", NatsAdapterFactory.Create, options => { })
.AddPersistentStreams(IArgonEvent.ProviderId, NatsAdapterFactory.Create, options => { });
}
else
{
siloBuilder.UseLocalhostClustering().AddMemoryStreams("default").AddMemoryStreams(IArgonEvent.ProviderId)
siloBuilder
.UseLocalhostClustering()
.AddMemoryStreams("default")
.AddMemoryStreams(IArgonEvent.ProviderId)
.AddMemoryGrainStorage(IFusionSessionGrain.StorageId);
}
});
Expand Down
32 changes: 32 additions & 0 deletions src/Argon.Api/Features/Sentry/SentryOrleansFilter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
namespace Argon.Api.Features.Sentry;

public class SentryGrainCallFilter : IIncomingGrainCallFilter
{
public async Task Invoke(IIncomingGrainCallContext context)
{
try
{
await context.Invoke();
}
catch (Exception ex)
{
SentrySdk.ConfigureScope(scope =>
{
var grainId = context.TargetId.ToString();
var calleGrain = context.SourceId?.ToString();
var grainType = context.Grain.GetType().FullName;

var methodName = context.ImplementationMethod.Name;

if (!string.IsNullOrEmpty(calleGrain))
scope.SetTag("ActivatorGrainId", calleGrain);
scope.SetTag("GrainId", grainId);
scope.SetTag("GrainType", grainType ?? "unk");
scope.SetTag("MethodName", methodName);
});

SentrySdk.CaptureException(ex);
throw;
}
}
}
7 changes: 6 additions & 1 deletion src/ServiceDefaults/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ namespace Microsoft.Extensions.Hosting;
using OpenTelemetry;
using OpenTelemetry.Metrics;
using OpenTelemetry.Trace;
using Sentry.Extensibility;
using Sentry.Infrastructure;
using Sentry.OpenTelemetry;

// Adds common .NET Aspire services: service discovery, resilience, health checks, and OpenTelemetry.
// This project should be referenced by each service project in your solution.
Expand Down Expand Up @@ -58,6 +60,7 @@ public static IHostApplicationBuilder AddSentry(this WebApplicationBuilder build
{
EnableCodeLocations = true
};
o.UseOpenTelemetry();
});

return builder;
Expand All @@ -71,6 +74,7 @@ public static IHostApplicationBuilder ConfigureOpenTelemetry(this IHostApplicati
logging.IncludeFormattedMessage = true;
logging.IncludeScopes = true;
});
builder.Logging.AddSentry();

builder.Services.AddOpenTelemetry().WithMetrics(metrics =>
{
Expand All @@ -80,7 +84,8 @@ public static IHostApplicationBuilder ConfigureOpenTelemetry(this IHostApplicati
tracing.AddAspNetCoreInstrumentation()
// Uncomment the following line to enable gRPC instrumentation (requires the OpenTelemetry.Instrumentation.GrpcNetClient package)
//.AddGrpcClientInstrumentation()
.AddHttpClientInstrumentation();
.AddHttpClientInstrumentation()
.AddSentry();
});

builder.AddOpenTelemetryExporters();
Expand Down
3 changes: 2 additions & 1 deletion src/ServiceDefaults/ServiceDefaults.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<PackageReference Include="OpenTelemetry.Instrumentation.Http" Version="1.9.0"/>
<PackageReference Include="OpenTelemetry.Instrumentation.Runtime" Version="1.9.0"/>
<PackageReference Include="Sentry.AspNetCore" Version="4.13.0"/>
<PackageReference Include="Sentry.OpenTelemetry" Version="4.13.0"/>
</ItemGroup>

</Project>
</Project>

0 comments on commit 65015b7

Please sign in to comment.