using System; using System.Collections.Generic; using Unity.Services.Core.Internal; namespace Unity.Services.Core.Telemetry.Internal { class Diagnostics : IDiagnostics { internal const int MaxDiagnosticMessageLength = 10000; internal const string DiagnosticMessageTruncateSuffix = "[truncated]"; internal DiagnosticsHandler Handler { get; } internal IDictionary PackageTags { get; } public Diagnostics(DiagnosticsHandler handler, IDictionary packageTags) { Handler = handler; PackageTags = packageTags; } public void SendDiagnostic(string name, string message, IDictionary tags = null) { var diagnostic = new Diagnostic { Content = tags is null ? new Dictionary(PackageTags) : new Dictionary(tags) .MergeAllowOverride(PackageTags), }; diagnostic.Content.Add(TagKeys.DiagnosticName, name); if (message != null && message.Length > MaxDiagnosticMessageLength) { message = $"{message.Substring(0, MaxDiagnosticMessageLength)}{Environment.NewLine}{DiagnosticMessageTruncateSuffix}"; } diagnostic.Content.Add(TagKeys.DiagnosticMessage, message); Handler.Register(diagnostic); } } }