Skip to content

Commit 6c75591

Browse files
committed
📊feat: add distributed tracing with OpenTelemetry & Jaeger
- Added OpenTelemetry tracing to the API with automatic instrumentation for ASP.NET Core, HttpClient and Entity Framework Core. - Configured OTLP exporter to send traces to a Jaeger container via gRPC, enabling end-to-end visibility of request flow and database performance.
1 parent 9d3cef2 commit 6c75591

3 files changed

Lines changed: 35 additions & 4 deletions

File tree

EventFlow.Presentation/EventFlow.Presentation.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@
2626
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
2727
</PackageReference>
2828
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.21.0" />
29+
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.14.0" />
30+
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.14.0" />
31+
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.14.0" />
32+
<PackageReference Include="OpenTelemetry.Instrumentation.EntityFrameworkCore" Version="1.14.0-beta.2" />
33+
<PackageReference Include="OpenTelemetry.Instrumentation.Http" Version="1.14.0" />
2934
<PackageReference Include="Serilog.AspNetCore" Version="10.0.0" />
3035
<PackageReference Include="Serilog.Sinks.Console" Version="6.1.1" />
3136
<PackageReference Include="Serilog.Sinks.Seq" Version="9.0.0" />

EventFlow.Presentation/Program.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
using EventFlow.Infrastructure.Data;
33
using Microsoft.IdentityModel.Tokens;
44
using Serilog;
5+
using OpenTelemetry.Resources;
6+
using OpenTelemetry.Trace;
7+
using OpenTelemetry.Exporter;
58

69
var builder = WebApplication.CreateBuilder(args);
710

@@ -14,6 +17,20 @@
1417
builder.Services.AddEndpointsApiExplorer();
1518
builder.Services.AddSwaggerGen();
1619
builder.Services.AddDbContextConfig(builder.Configuration, builder.Environment.IsDevelopment());
20+
21+
builder.Services.AddOpenTelemetry()
22+
.ConfigureResource(resource => resource
23+
.AddService("EventFlow.API"))
24+
.WithTracing(tracing => tracing
25+
.AddAspNetCoreInstrumentation()
26+
.AddHttpClientInstrumentation()
27+
.AddEntityFrameworkCoreInstrumentation()
28+
.AddOtlpExporter(options =>
29+
{
30+
options.Endpoint = new Uri("http://eventflow-jaeger:4317");
31+
options.Protocol = OtlpExportProtocol.Grpc;
32+
}));
33+
1734
builder.Services.AddDependencyInjectionConfig();
1835

1936
builder.Services

docker-compose.yml

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
version: '3.8'
2-
3-
services:
1+
services:
42
eventflow-api:
53
container_name: eventflow-api
64
image: eventflowapi:latest
@@ -35,7 +33,7 @@ services:
3533
- ACCEPT_EULA=Y
3634
- SA_PASSWORD=MyStrongPassword123!
3735
ports:
38-
- "1433:1433"
36+
- "1434:1434"
3937
volumes:
4038
- eventflow_sql_data:/var/opt/mssql
4139
healthcheck:
@@ -58,6 +56,17 @@ services:
5856
networks:
5957
- eventflow-network
6058

59+
eventflow-jaeger:
60+
image: jaegertracing/all-in-one:latest
61+
container_name: eventflow-jaeger
62+
environment:
63+
- COLLECTOR_OTLP_ENABLED=true
64+
ports:
65+
- "16686:16686"
66+
- "4317:4317"
67+
networks:
68+
- eventflow-network
69+
6170
volumes:
6271
eventflow_sql_data:
6372
eventflow_keys:

0 commit comments

Comments
 (0)