Skip to content

Commit

Permalink
yayyay
Browse files Browse the repository at this point in the history
  • Loading branch information
arealmaas committed Dec 10, 2024
1 parent df8825f commit ab2bedb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
17 changes: 8 additions & 9 deletions src/Digdir.Library.Utils.AspNet/AspNetUtilitiesExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, object>(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<string, object>(key, attributes[key] ?? string.Empty) });
}
resourceBuilder.AddAttributes(new[] { attribute });
}
}
catch (Exception ex)
Expand Down
1 change: 1 addition & 0 deletions src/Digdir.Library.Utils.AspNet/AspNetUtilitiesSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> TraceSources { get; set; } = new()
{
Expand Down

0 comments on commit ab2bedb

Please sign in to comment.