diff --git a/src/Agoda.DevFeedback.AspNetStartup/TimedStartupPublisher.cs b/src/Agoda.DevFeedback.AspNetStartup/TimedStartupPublisher.cs index afa951b..2bae00b 100644 --- a/src/Agoda.DevFeedback.AspNetStartup/TimedStartupPublisher.cs +++ b/src/Agoda.DevFeedback.AspNetStartup/TimedStartupPublisher.cs @@ -1,5 +1,8 @@ using Agoda.DevFeedback.Common; using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; using System.Reflection; namespace Agoda.DevFeedback.AspNetStartup @@ -8,14 +11,28 @@ internal static class TimedStartupPublisher { public static void Publish(string type, TimeSpan timeTaken) { + const string TagPrefix = "DEVFEEDBACK_TAG_"; + var gitContext = GitContextReader.GetGitContext(); + // Use LINQ and dictionary comprehension for cleaner tag collection + var tags = Environment.GetEnvironmentVariables() + .Cast() + .Select(entry => (Key: entry.Key.ToString()!, Value: entry.Value?.ToString())) + .Where(entry => entry.Key.StartsWith(TagPrefix, StringComparison.OrdinalIgnoreCase) + && !string.IsNullOrEmpty(entry.Value)) + .ToDictionary( + entry => entry.Key[TagPrefix.Length..].ToLowerInvariant(), + entry => entry.Value! + ); + var result = new DevFeedbackData( metricsVersion: Assembly.GetExecutingAssembly().GetName().Version?.ToString(), type: type, projectName: Assembly.GetEntryAssembly()?.GetName().Name, timeTaken: timeTaken.TotalMilliseconds.ToString(), - gitContext: gitContext + gitContext: gitContext, + tags: tags ); DevFeedbackPublisher.Publish(apiEndpoint: null, result, DevLocalDataType.Build); diff --git a/src/Agoda.DevFeedback.Common/DevFeedbackData.cs b/src/Agoda.DevFeedback.Common/DevFeedbackData.cs index e59efa5..fb27863 100644 --- a/src/Agoda.DevFeedback.Common/DevFeedbackData.cs +++ b/src/Agoda.DevFeedback.Common/DevFeedbackData.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using Newtonsoft.Json; namespace Agoda.DevFeedback.Common @@ -47,13 +48,16 @@ public class DevFeedbackData [JsonProperty("date")] public DateTime Date { get; set; } + [JsonProperty("tags")] + public Dictionary Tags { get; set; } + public DevFeedbackData( string metricsVersion, string type, string projectName, string timeTaken, - GitContext gitContext - ) + GitContext gitContext, + Dictionary tags = null) { Id = Guid.NewGuid(); Type = type; @@ -69,6 +73,7 @@ GitContext gitContext RepositoryName = gitContext.RepositoryName; Branch = gitContext.BranchName; Date = DateTime.UtcNow; + Tags = tags; } } }