Skip to content

Commit 21013cc

Browse files
Merge pull request #19 from MarimerLLC/feature/otel-alloy-integration
Hook up OpenTelemetry to Grafana Alloy collector in k8s
2 parents 97f60e6 + 42f2a7d commit 21013cc

3 files changed

Lines changed: 16 additions & 2 deletions

File tree

k8s/configmap.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ data:
1010
ASPNETCORE_ENVIRONMENT: Production
1111
ASPNETCORE_URLS: http://+:8080
1212
MCPAGGREGATOR__DATADIRECTORY: /data
13+
OTEL_EXPORTER_OTLP_ENDPOINT: http://alloy.loki.svc.cluster.local:4317

src/McpAggregator.HttpServer/McpAggregator.HttpServer.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
<PackageReference Include="Scalar.AspNetCore" Version="2.*" />
2121
<PackageReference Include="Serilog.AspNetCore" Version="9.*" />
2222
<PackageReference Include="Serilog.Sinks.OpenTelemetry" Version="4.*" />
23+
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.*" />
2324
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.*" />
2425
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.*" />
2526
</ItemGroup>

src/McpAggregator.HttpServer/ServeCommand.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using Microsoft.Extensions.AI;
77
using Microsoft.Extensions.Options;
88
using OpenTelemetry.Metrics;
9+
using OpenTelemetry.Resources;
910
using OpenTelemetry.Trace;
1011
using Scalar.AspNetCore;
1112
using Serilog;
@@ -69,8 +70,19 @@ public override async Task<int> ExecuteAsync(CommandContext context, ServeSettin
6970

7071
// OpenTelemetry tracing & metrics
7172
builder.Services.AddOpenTelemetry()
72-
.WithTracing(t => t.AddAspNetCoreInstrumentation())
73-
.WithMetrics(m => m.AddAspNetCoreInstrumentation());
73+
.ConfigureResource(r => r.AddService("mcp-aggregator"))
74+
.WithTracing(t =>
75+
{
76+
t.AddAspNetCoreInstrumentation();
77+
if (!string.IsNullOrEmpty(otlpEndpoint))
78+
t.AddOtlpExporter(o => o.Endpoint = new Uri(otlpEndpoint));
79+
})
80+
.WithMetrics(m =>
81+
{
82+
m.AddAspNetCoreInstrumentation();
83+
if (!string.IsNullOrEmpty(otlpEndpoint))
84+
m.AddOtlpExporter(o => o.Endpoint = new Uri(otlpEndpoint));
85+
});
7486

7587
// Core services
7688
builder.Services.AddAggregatorCore(builder.Configuration);

0 commit comments

Comments
 (0)