Skip to content

Commit

Permalink
back to original OnEnd (still whitespace err)
Browse files Browse the repository at this point in the history
  • Loading branch information
andracc committed Oct 10, 2024
1 parent c04bbb5 commit 9190110
Showing 1 changed file with 31 additions and 13 deletions.
44 changes: 31 additions & 13 deletions Backend/Otel/OtelKernel.cs
Original file line number Diff line number Diff line change
@@ -1,26 +1,17 @@
// using System.Diagnostics;
// using BackendFramework.Interfaces;
using System.Diagnostics;
using BackendFramework.Interfaces;
using System.Diagnostics.CodeAnalysis;
using Microsoft.Extensions.DependencyInjection;
// using OpenTelemetry;
using OpenTelemetry;
using OpenTelemetry.Instrumentation.AspNetCore;
using OpenTelemetry.Instrumentation.Http;
using OpenTelemetry.Metrics;
using OpenTelemetry.Resources;
using OpenTelemetry.Trace;
using System.Linq;
using OpenTelemetry;
using System.Diagnostics;
// using BackendFramework.Otel;
namespace BackendFramework.Otel
{

internal class UserEnricher() : BaseProcessor<Activity>
{
public override void OnStart(Activity data)
{
}
}
public static class OtelKernel
{
public const string SourceName = "Backend-Otel";
Expand Down Expand Up @@ -138,13 +129,40 @@ public static void AddOpenTelemetryInstrumentation(this IServiceCollection servi
services.AddOpenTelemetry().WithTracing(tracerProviderBuilder => tracerProviderBuilder
.SetResourceBuilder(appResourceBuilder)
.AddSource(SourceName)
// .AddProcessor<LocationEnricher>()
.AddProcessor<LocationEnricher>()
.AddAspNetCoreInstrumentation(AspNetCoreBuilder)
.AddHttpClientInstrumentation(HttpClientBuilder)
.AddConsoleExporter()
.AddOtlpExporter()
);
}
}
internal class LocationEnricher(ILocationProvider locationProvider) : BaseProcessor<Activity>
{
public override async void OnEnd(Activity data)
{
string? uriPath = (string?)data.GetTagItem("url.full");
string locationUri = LocationProvider.locationGetterUri;
if (uriPath == null || !uriPath.Contains(locationUri))
{
LocationApi? response = await locationProvider.GetLocation();
var location = new
{
Country = response?.country,
Region = response?.regionName,
City = response?.city,
};
data?.AddTag("country", location.Country);
data?.AddTag("region", location.Region);
data?.AddTag("city", location.City);
}
data?.SetTag("SESSIONID BAGGAGE", data?.GetBaggageItem("sessionId"));
if (uriPath != null && uriPath.Contains(locationUri))
{
data?.SetTag("url.full", "");
data?.SetTag("url.redacted.ip", LocationProvider.locationGetterUri);
}
}
}
}

0 comments on commit 9190110

Please sign in to comment.