Skip to content

Commit 1b85f45

Browse files
authored
merge(#40): redesign OpenTelemetry tracing with Metalama AOP
2 parents 4023da7 + 852d91d commit 1b85f45

39 files changed

+485
-109
lines changed

CrowdParlay.Social.sln

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CrowdParlay.Social.Infrastr
1818
EndProject
1919
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CrowdParlay.Social.UnitTests", "tests\CrowdParlay.Social.UnitTests\CrowdParlay.Social.UnitTests.csproj", "{8F95AF80-A278-49DB-97EB-F8DB96F083D5}"
2020
EndProject
21+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CrowdParlay.Social.Aspects", "src\CrowdParlay.Social.Aspects\CrowdParlay.Social.Aspects.csproj", "{4DBC1701-9141-4AC2-80C1-CA9050FF7F0B}"
22+
EndProject
2123
Global
2224
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2325
Debug|Any CPU = Debug|Any CPU
@@ -52,6 +54,10 @@ Global
5254
{8F95AF80-A278-49DB-97EB-F8DB96F083D5}.Debug|Any CPU.Build.0 = Debug|Any CPU
5355
{8F95AF80-A278-49DB-97EB-F8DB96F083D5}.Release|Any CPU.ActiveCfg = Release|Any CPU
5456
{8F95AF80-A278-49DB-97EB-F8DB96F083D5}.Release|Any CPU.Build.0 = Release|Any CPU
57+
{4DBC1701-9141-4AC2-80C1-CA9050FF7F0B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
58+
{4DBC1701-9141-4AC2-80C1-CA9050FF7F0B}.Debug|Any CPU.Build.0 = Debug|Any CPU
59+
{4DBC1701-9141-4AC2-80C1-CA9050FF7F0B}.Release|Any CPU.ActiveCfg = Release|Any CPU
60+
{4DBC1701-9141-4AC2-80C1-CA9050FF7F0B}.Release|Any CPU.Build.0 = Release|Any CPU
5561
EndGlobalSection
5662
GlobalSection(NestedProjects) = preSolution
5763
{1C0DE505-4898-4FB4-A5AA-C01630770F79} = {340CE817-E3FB-4753-94AA-E5BFB13E6F6A}
@@ -61,5 +67,6 @@ Global
6167
{640B084C-59F5-448D-845A-7D6A8E1A7F99} = {340CE817-E3FB-4753-94AA-E5BFB13E6F6A}
6268
{47776236-58AD-449A-B3BF-6ED960C3D12C} = {340CE817-E3FB-4753-94AA-E5BFB13E6F6A}
6369
{8F95AF80-A278-49DB-97EB-F8DB96F083D5} = {00C5EC71-2662-4897-8C51-8C1355111519}
70+
{4DBC1701-9141-4AC2-80C1-CA9050FF7F0B} = {340CE817-E3FB-4753-94AA-E5BFB13E6F6A}
6471
EndGlobalSection
6572
EndGlobal

src/CrowdParlay.Social.Api/CrowdParlay.Social.Api.csproj

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,13 @@
1010
</PropertyGroup>
1111

1212
<ItemGroup>
13-
<PackageReference Include="Elastic.Apm.NetCoreAll" Version="1.32.2" />
1413
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="9.0.5" />
1514
<PackageReference Include="Microsoft.AspNetCore.DataProtection.StackExchangeRedis" Version="9.0.5" />
1615
<PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning.ApiExplorer" Version="5.1.0"/>
1716
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.5" />
1817
<PackageReference Include="Microsoft.AspNetCore.SignalR.Common" Version="9.0.5" />
19-
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.12.0" />
20-
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.12.0" />
21-
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.12.0" />
22-
<PackageReference Include="OpenTelemetry.Instrumentation.GrpcNetClient" Version="1.9.0-beta.1" />
2318
<PackageReference Include="Serilog.Enrichers.OpenTelemetry" Version="1.0.1" />
19+
<PackageReference Include="Serilog.Sinks.OpenTelemetry" Version="4.2.0" />
2420
<PackageReference Include="SignalRSwaggerGen" Version="4.8.0" />
2521
<PackageReference Include="Swashbuckle.AspNetCore" Version="8.1.2" />
2622
</ItemGroup>

src/CrowdParlay.Social.Api/Extensions/ConfigureAuthenticationExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77

88
namespace CrowdParlay.Social.Api.Extensions;
99

10-
public static class ConfigureAuthenticationExtensions
10+
partial class ServiceCollectionExtensions
1111
{
12-
public static IServiceCollection ConfigureAuthentication(this IServiceCollection services, IConfiguration configuration)
12+
private static IServiceCollection ConfigureAuthentication(this IServiceCollection services, IConfiguration configuration)
1313
{
1414
var dataProtectionRedisConnectionString = configuration["DATA_PROTECTION_REDIS_CONNECTION_STRING"]!;
1515
var dataProtectionRedisMultiplexer = ConnectionMultiplexer.Connect(dataProtectionRedisConnectionString);

src/CrowdParlay.Social.Api/Extensions/ConfigureCorsExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
namespace CrowdParlay.Social.Api.Extensions;
22

3-
public static class ConfigureCorsExtensions
3+
partial class ServiceCollectionExtensions
44
{
5-
public static IServiceCollection ConfigureCors(this IServiceCollection services, IConfiguration configuration)
5+
private static IServiceCollection ConfigureCors(this IServiceCollection services, IConfiguration configuration)
66
{
77
var corsOrigins =
88
configuration["CORS_ORIGINS"]?.Split(';')

src/CrowdParlay.Social.Api/Extensions/ConfigureEndpointsExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33

44
namespace CrowdParlay.Social.Api.Extensions;
55

6-
public static class ConfigureEndpointsExtensions
6+
partial class ServiceCollectionExtensions
77
{
8-
public static IServiceCollection ConfigureEndpoints(this IServiceCollection services)
8+
internal static IServiceCollection ConfigureEndpoints(this IServiceCollection services)
99
{
1010
var mvcBuilder = services.AddControllers(options =>
1111
{

src/CrowdParlay.Social.Api/Extensions/ConfigureServices.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace CrowdParlay.Social.Api.Extensions;
66

7-
public static class ConfigureApiExtensions
7+
public static partial class ServiceCollectionExtensions
88
{
99
public static IServiceCollection AddApi(this IServiceCollection services, IConfiguration configuration)
1010
{
@@ -13,7 +13,6 @@ public static IServiceCollection AddApi(this IServiceCollection services, IConfi
1313
.ConfigureAuthentication(configuration)
1414
.ConfigureCors(configuration)
1515
.ConfigureSignalR(configuration)
16-
.ConfigureTelemetry(configuration)
1716
.AddExceptionHandler<GlobalExceptionHandler>()
1817
.AddProblemDetails()
1918
.AddAuthorization();

src/CrowdParlay.Social.Api/Extensions/ConfigureSignalRExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
namespace CrowdParlay.Social.Api.Extensions;
22

3-
public static class ConfigureSignalRExtensions
3+
partial class ServiceCollectionExtensions
44
{
5-
public static IServiceCollection ConfigureSignalR(this IServiceCollection services, IConfiguration configuration)
5+
private static IServiceCollection ConfigureSignalR(this IServiceCollection services, IConfiguration configuration)
66
{
77
var redisConnectionString =
88
configuration["REDIS_CONNECTION_STRING"]

src/CrowdParlay.Social.Api/Extensions/ConfigureTelemetryExtensions.cs

Lines changed: 0 additions & 32 deletions
This file was deleted.

src/CrowdParlay.Social.Api/Program.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
using CrowdParlay.Social.Infrastructure.Communication;
12
using Serilog;
3+
using Serilog.Enrichers.OpenTelemetry;
4+
using Serilog.Sinks.OpenTelemetry;
25

36
namespace CrowdParlay.Social.Api;
47

@@ -8,5 +11,13 @@ public class Program
811

912
private static IHostBuilder CreateHostBuilder(string[] args) => Host.CreateDefaultBuilder(args)
1013
.ConfigureWebHostDefaults(builder => builder.UseStartup<Startup>())
11-
.UseSerilog();
14+
.UseSerilog((context, logger) => logger
15+
.ReadFrom.Configuration(context.Configuration)
16+
.Enrich.WithOpenTelemetrySpanId()
17+
.Enrich.WithOpenTelemetryTraceId()
18+
.WriteTo.OpenTelemetry(sink =>
19+
{
20+
sink.Endpoint = context.Configuration.GetRequiredSection("OpenTelemetry").Get<OpenTelemetrySettings>()?.OtlpEndpoint;
21+
sink.Protocol = OtlpProtocol.HttpProtobuf;
22+
}));
1223
}
Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,17 @@
11
using CrowdParlay.Social.Api.Extensions;
22
using CrowdParlay.Social.Api.Hubs;
3-
using CrowdParlay.Social.Application;
4-
using CrowdParlay.Social.Infrastructure.Communication;
5-
using CrowdParlay.Social.Infrastructure.Persistence;
6-
using Elastic.Apm.NetCoreAll;
3+
using CrowdParlay.Social.Application.Extensions;
4+
using CrowdParlay.Social.Infrastructure.Communication.Extensions;
5+
using CrowdParlay.Social.Infrastructure.Persistence.Extensions;
76
using Microsoft.AspNetCore.Http.Connections;
87
using Serilog;
9-
using Serilog.Enrichers.OpenTelemetry;
108

119
namespace CrowdParlay.Social.Api;
1210

1311
public class Startup(IConfiguration configuration)
1412
{
1513
public void Configure(IApplicationBuilder app, IWebHostEnvironment environment)
1614
{
17-
Log.Logger = new LoggerConfiguration()
18-
.ReadFrom.Configuration(configuration)
19-
.Enrich.WithOpenTelemetrySpanId()
20-
.Enrich.WithOpenTelemetryTraceId()
21-
.CreateLogger();
22-
23-
app.UseAllElasticApm(configuration);
2415
app.UseExceptionHandler();
2516
app.UseSerilogRequestLogging();
2617
app.UseHealthChecks("/healthz");
@@ -39,6 +30,6 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment environment)
3930
public void ConfigureServices(IServiceCollection services) => services
4031
.AddApi(configuration)
4132
.AddApplication()
42-
.AddPersistence(configuration)
33+
.AddPersistence()
4334
.AddCommunication(configuration);
4435
}

0 commit comments

Comments
 (0)