From ab2bedb494bef1fbc3b5781029745389876d607c Mon Sep 17 00:00:00 2001 From: Are Almaas Date: Tue, 10 Dec 2024 15:41:12 +0100 Subject: [PATCH] yayyay --- .../AspNetUtilitiesExtensions.cs | 17 ++++++++--------- .../AspNetUtilitiesSettings.cs | 1 + 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Digdir.Library.Utils.AspNet/AspNetUtilitiesExtensions.cs b/src/Digdir.Library.Utils.AspNet/AspNetUtilitiesExtensions.cs index 1b5bdde14..394fe7e43 100644 --- a/src/Digdir.Library.Utils.AspNet/AspNetUtilitiesExtensions.cs +++ b/src/Digdir.Library.Utils.AspNet/AspNetUtilitiesExtensions.cs @@ -73,16 +73,15 @@ public static WebApplicationBuilder ConfigureTelemetry( { try { - var attributes = System.Web.HttpUtility.ParseQueryString( - resourceAttributes.Replace(',', '&') - ); - foreach (string key in attributes.Keys) + var attributes = resourceAttributes + .Split(',', StringSplitOptions.RemoveEmptyEntries) + .Select(pair => pair.Split('=', 2)) + .Where(parts => parts.Length == 2 && !string.IsNullOrEmpty(parts[0])) + .Select(parts => new KeyValuePair(parts[0].Trim(), parts[1].Trim())); + + foreach (var attribute in attributes) { - if (!string.IsNullOrEmpty(key)) - { - Console.WriteLine($"[OpenTelemetry] Resource attribute: {key}={attributes[key]}"); - resourceBuilder.AddAttributes(new[] { new KeyValuePair(key, attributes[key] ?? string.Empty) }); - } + resourceBuilder.AddAttributes(new[] { attribute }); } } catch (Exception ex) diff --git a/src/Digdir.Library.Utils.AspNet/AspNetUtilitiesSettings.cs b/src/Digdir.Library.Utils.AspNet/AspNetUtilitiesSettings.cs index e6b10c2e1..7cb14248c 100644 --- a/src/Digdir.Library.Utils.AspNet/AspNetUtilitiesSettings.cs +++ b/src/Digdir.Library.Utils.AspNet/AspNetUtilitiesSettings.cs @@ -19,6 +19,7 @@ public sealed class TelemetrySettings public string? Endpoint { get; set; } public string? Protocol { get; set; } public string? AppInsightsConnectionString { get; set; } + // Expected format: key1=value1,key2=value2 public string? ResourceAttributes { get; set; } public HashSet TraceSources { get; set; } = new() {