Skip to content

Commit

Permalink
cleaning kernel
Browse files Browse the repository at this point in the history
  • Loading branch information
andracc committed Sep 26, 2024
1 parent 310f1cb commit 857d8a3
Showing 1 changed file with 11 additions and 53 deletions.
64 changes: 11 additions & 53 deletions Backend/Otel/OtelKernel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,14 @@
using BackendFramework.Interfaces;

Check failure on line 4 in Backend/Otel/OtelKernel.cs

View workflow job for this annotation

GitHub Actions / CodeQL_build

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 4 in Backend/Otel/OtelKernel.cs

View workflow job for this annotation

GitHub Actions / CodeQL_build

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 4 in Backend/Otel/OtelKernel.cs

View workflow job for this annotation

GitHub Actions / test_build (8.0.x)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

using System.Diagnostics.CodeAnalysis;
// using System.Diagnostics.Metrics;
// using System.Net.Http;
// using System.Net.Http.Json;
// using System.Security.Claims;
// using System.Threading.Tasks;
// using Microsoft.AspNetCore.Http;
// using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.DependencyInjection;
using OpenTelemetry;
using OpenTelemetry.Instrumentation.AspNetCore;
using OpenTelemetry.Instrumentation.Http;
using OpenTelemetry.Metrics;
using OpenTelemetry.Resources;
using OpenTelemetry.Trace;
// using System.Collections.Generic;
using System.Linq;
// using Microsoft.AspNetCore.Http;
// using Microsoft.AspNetCore.Http;

namespace BackendFramework.Otel
{
Expand All @@ -47,10 +37,6 @@ private static void AspNetCoreBuilder(AspNetCoreTraceInstrumentationOptions opti
activity.SetTag("inbound.http.request.body.size", "no content");
}

// if (request.Headers.ContainsKey("sessionId"))
// {
// activity.SetTag("ID EXISTS asp", "TRUE");
// }
string? sessionId = request.Headers.TryGetValue("sessionId", out var values) ? values.FirstOrDefault() : null;
if (sessionId != null)
{
Expand All @@ -60,11 +46,6 @@ private static void AspNetCoreBuilder(AspNetCoreTraceInstrumentationOptions opti
{
activity.SetTag("SESSIONID ASP REQUEST", "NULL");
}
// activity.EnrichWithUser(request.HttpContext);
// activity.SetTag("BEFORE", "inasp-request");
// var sessionContext = request.HttpContext;
// activity.SetTag("context", sessionContext);
// activity.SetTag("AFTER", "inasp-request");
};
options.EnrichWithHttpResponse = (activity, response) =>
{
Expand All @@ -86,12 +67,6 @@ private static void AspNetCoreBuilder(AspNetCoreTraceInstrumentationOptions opti
{
activity.SetTag("SESSIONID ASP RESPONSE", "NULL");
}
// // activity.EnrichWithUser(response.HttpContext);
// activity.SetTag("BEFORE", "inasp-response");
// // var sessionId = response.HttpContext;
// var sessionContext = response.HttpContext;
// activity.SetTag("context", sessionContext);
// activity.SetTag("AFTER", "inasp-response");
};
}

Expand Down Expand Up @@ -129,11 +104,6 @@ private static void HttpClientBuilder(HttpClientTraceInstrumentationOptions opti
{
activity.SetTag("SESSIONID HTTP REQUEST", "NULL");
}
// activity.SetTag("BEFORE", "inhttp-request");
// // var sessionId = response.HttpContext;
// var sessionContext = request.Headers.Connection;
// activity.SetTag("context", sessionContext);
// activity.SetTag("AFTER", "inhttp-request");
};
options.EnrichWithHttpResponseMessage = (activity, response) =>
{
Expand All @@ -142,11 +112,6 @@ private static void HttpClientBuilder(HttpClientTraceInstrumentationOptions opti
{
activity.SetTag("outbound.http.response.body.size", contentLength.Value);
}
// if (response.Headers.Contains("sessionId"))
// {
// activity.SetTag("ID EXISTS http", "TRUE");
// }
// IEnumerable<string> values;
string? sessionId = response.Headers.TryGetValues("sessionId", out var values) ? values.FirstOrDefault() : null;
if (sessionId != null)
{
Expand All @@ -156,11 +121,6 @@ private static void HttpClientBuilder(HttpClientTraceInstrumentationOptions opti
{
activity.SetTag("SESSIONID HTTP RESPONSE", "NULL");
}
// activity.SetTag("BEFORE", "inhttp-response");
// // var sessionId = response.HttpContext;
// var sessionContext = response.Headers.Connection;
// activity.SetTag("context", sessionContext);
// activity.SetTag("AFTER", "inhttp-response");
};
}

Expand All @@ -181,24 +141,22 @@ public static void AddOpenTelemetryInstrumentation(this IServiceCollection servi

}

// private static void EnrichWithUser(this Activity activity, HttpContext httpContext)
// private static void EnrichWithSession(this Activity activity, HttpContext httpContext)
// {
// var claimsPrincipal = httpContext.User;
// // var userId = claimsPrincipal?.FindFirstValue("sub");
// var userId = claimsPrincipal;
// if (userId != null)
// {
// activity.SetTag("app.user.id", userId);
// }
// var userRole = claimsPrincipal?.FindFirstValue("role");
// if (userRole != null)

// // in progress

// string? sessionId = httpContext.Headers.TryGetValues("sessionId", out var values) ? values.FirstOrDefault() : null;
// if (sessionId != null)
// {
// activity.SetTag("app.user.role", userRole);
// activity.SetTag("SESSIONID HTTP RESPONSE", sessionId);
// }
// if (httpContext.RequestAborted.IsCancellationRequested)
// else
// {
// activity.SetTag("http.abort", true);
// activity.SetTag("SESSIONID HTTP RESPONSE", "NULL");
// }


// }

private class LocationEnricher(LocationProvider locationProvider) : BaseProcessor<Activity>
Expand Down

0 comments on commit 857d8a3

Please sign in to comment.