From 36cb7cb014cb50a7002b98521d24efd49dc957a3 Mon Sep 17 00:00:00 2001 From: Dmitry Novik Date: Thu, 7 Jan 2021 12:06:10 +1100 Subject: [PATCH 1/9] feat: Creating the DataDogConfiguration MaxRetries configuration property --- .../ApplyMicrosoftExtensionsConfiguration.cs | 3 ++- .../Sinks/Datadog/DatadogConfiguration.cs | 13 ++++++++----- .../Sinks/Datadog/DatadogHttpClient.cs | 7 +------ .../Sinks/Datadog/DatadogTcpClient.cs | 7 +------ 4 files changed, 12 insertions(+), 18 deletions(-) diff --git a/src/Serilog.Sinks.Datadog.Logs/Configuration/Implementations/Microsoft.Extensions.Configuration/ApplyMicrosoftExtensionsConfiguration.cs b/src/Serilog.Sinks.Datadog.Logs/Configuration/Implementations/Microsoft.Extensions.Configuration/ApplyMicrosoftExtensionsConfiguration.cs index 66ebc94..5e1be81 100644 --- a/src/Serilog.Sinks.Datadog.Logs/Configuration/Implementations/Microsoft.Extensions.Configuration/ApplyMicrosoftExtensionsConfiguration.cs +++ b/src/Serilog.Sinks.Datadog.Logs/Configuration/Implementations/Microsoft.Extensions.Configuration/ApplyMicrosoftExtensionsConfiguration.cs @@ -29,7 +29,8 @@ internal static DatadogConfiguration ConfigureDatadogConfiguration(DatadogConfig url: datadogConfiguration?.Url ?? section.Url, port: datadogConfiguration?.Port ?? section.Port, useSSL: datadogConfiguration?.UseSSL ?? section.UseSSL, - useTCP: datadogConfiguration?.UseTCP ?? section.UseTCP + useTCP: datadogConfiguration?.UseTCP ?? section.UseTCP, + maxRetries:datadogConfiguration?.MaxRetries ?? section.MaxRetries ); } } diff --git a/src/Serilog.Sinks.Datadog.Logs/Sinks/Datadog/DatadogConfiguration.cs b/src/Serilog.Sinks.Datadog.Logs/Sinks/Datadog/DatadogConfiguration.cs index eee0f32..eb364b2 100644 --- a/src/Serilog.Sinks.Datadog.Logs/Sinks/Datadog/DatadogConfiguration.cs +++ b/src/Serilog.Sinks.Datadog.Logs/Sinks/Datadog/DatadogConfiguration.cs @@ -45,20 +45,23 @@ public class DatadogConfiguration /// public bool UseTCP { get; set; } + /// + /// Number of retries before the client gives up logging. + /// + public int MaxRetries { get; set; } + public DatadogConfiguration() : this(DDUrl, DDPort, true, false) { } - public DatadogConfiguration(string url = DDUrl, int port = DDPort, bool useSSL = true, bool useTCP = false) + public DatadogConfiguration(string url = DDUrl, int port = DDPort, bool useSSL = true, bool useTCP = false, int maxRetries = 10) { Url = url; Port = port; UseSSL = useSSL; UseTCP = useTCP; + MaxRetries = maxRetries; } - public override string ToString() - { - return string.Format("{{ Url: {0}, Port: {1}, UseSSL: {2}, UseTCP: {3} }}", Url, Port, UseSSL, UseTCP); - } + public override string ToString() => $"{{ Url: {Url}, Port: {Port}, UseSSL: {UseSSL}, UseTCP: {UseTCP} }}"; } } diff --git a/src/Serilog.Sinks.Datadog.Logs/Sinks/Datadog/DatadogHttpClient.cs b/src/Serilog.Sinks.Datadog.Logs/Sinks/Datadog/DatadogHttpClient.cs index 6206225..9ac8a1f 100644 --- a/src/Serilog.Sinks.Datadog.Logs/Sinks/Datadog/DatadogHttpClient.cs +++ b/src/Serilog.Sinks.Datadog.Logs/Sinks/Datadog/DatadogHttpClient.cs @@ -24,11 +24,6 @@ public class DatadogHttpClient : IDatadogClient private readonly LogFormatter _formatter; private readonly HttpClient _client; - /// - /// Max number of retries when sending failed. - /// - private const int MaxRetries = 10; - /// /// Max backoff used when sending failed. /// @@ -115,7 +110,7 @@ private async Task Post(LogEventChunk logEventChunk) { var payload = logEventChunk.Payload; var content = new StringContent(payload, Encoding.UTF8, _content); - for (int retry = 0; retry < MaxRetries; retry++) + for (int retry = 0; retry < _config.MaxRetries; retry++) { int backoff = (int)Math.Min(Math.Pow(2, retry), MaxBackoff); if (retry > 0) diff --git a/src/Serilog.Sinks.Datadog.Logs/Sinks/Datadog/DatadogTcpClient.cs b/src/Serilog.Sinks.Datadog.Logs/Sinks/Datadog/DatadogTcpClient.cs index 6b95f2d..dde9d14 100644 --- a/src/Serilog.Sinks.Datadog.Logs/Sinks/Datadog/DatadogTcpClient.cs +++ b/src/Serilog.Sinks.Datadog.Logs/Sinks/Datadog/DatadogTcpClient.cs @@ -36,11 +36,6 @@ public class DatadogTcpClient : IDatadogClient /// private const string MessageDelimiter = "\n"; - /// - /// Max number of retries when sending failed. - /// - private const int MaxRetries = 5; - /// /// Max backoff used when sending failed. /// @@ -89,7 +84,7 @@ public async Task WriteAsync(IEnumerable events) } string payload = payloadBuilder.ToString(); - for (int retry = 0; retry < MaxRetries; retry++) + for (int retry = 0; retry < _config.MaxRetries; retry++) { int backoff = (int)Math.Min(Math.Pow(retry, 2), MaxBackoff); if (retry > 0) From d4f7260bf3a5c4fb6c1e014b9c8b1814ff5892dd Mon Sep 17 00:00:00 2001 From: Dmitry Novik Date: Thu, 7 Jan 2021 12:15:37 +1100 Subject: [PATCH 2/9] refactor: preventing multiple enumeration of IEnumerable and optimizing code by invoking collection count --- .../Sinks/Datadog/DatadogHttpClient.cs | 8 ++++---- .../Sinks/Datadog/DatadogSink.cs | 5 +++-- .../Sinks/Datadog/DatadogTcpClient.cs | 2 +- .../Sinks/Datadog/IDatadogClient.cs | 2 +- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/Serilog.Sinks.Datadog.Logs/Sinks/Datadog/DatadogHttpClient.cs b/src/Serilog.Sinks.Datadog.Logs/Sinks/Datadog/DatadogHttpClient.cs index 9ac8a1f..d171664 100644 --- a/src/Serilog.Sinks.Datadog.Logs/Sinks/Datadog/DatadogHttpClient.cs +++ b/src/Serilog.Sinks.Datadog.Logs/Sinks/Datadog/DatadogHttpClient.cs @@ -42,7 +42,7 @@ public DatadogHttpClient(DatadogConfiguration config, LogFormatter formatter, st _formatter = formatter; } - public Task WriteAsync(IEnumerable events) + public Task WriteAsync(IReadOnlyCollection events) { var serializedEvents = SerializeEvents(events); var tasks = serializedEvents.LogEventChunks.Select(Post); @@ -60,13 +60,13 @@ public Task WriteAsync(IEnumerable events) return Task.WhenAll(tasks); } - private SerializedEvents SerializeEvents(IEnumerable events) + private SerializedEvents SerializeEvents(IReadOnlyCollection events) { var serializedEvents = new SerializedEvents(); int currentSize = 0; - var chunkBuffer = new List(events.Count()); - var logEvents = new List(events.Count()); + var chunkBuffer = new List(events.Count); + var logEvents = new List(events.Count); foreach (var logEvent in events) { var formattedLog = _formatter.formatMessage(logEvent); diff --git a/src/Serilog.Sinks.Datadog.Logs/Sinks/Datadog/DatadogSink.cs b/src/Serilog.Sinks.Datadog.Logs/Sinks/Datadog/DatadogSink.cs index 49a4bcf..8389f1d 100755 --- a/src/Serilog.Sinks.Datadog.Logs/Sinks/Datadog/DatadogSink.cs +++ b/src/Serilog.Sinks.Datadog.Logs/Sinks/Datadog/DatadogSink.cs @@ -58,12 +58,13 @@ protected override async Task EmitBatchAsync(IEnumerable events) { try { - if (!events.Any()) + var batch = events.ToArray(); + if (!batch.Any()) { return; } - var task = _client.WriteAsync(events); + var task = _client.WriteAsync(batch); await RunTask(task); } catch (Exception e) diff --git a/src/Serilog.Sinks.Datadog.Logs/Sinks/Datadog/DatadogTcpClient.cs b/src/Serilog.Sinks.Datadog.Logs/Sinks/Datadog/DatadogTcpClient.cs index dde9d14..3f21f5d 100644 --- a/src/Serilog.Sinks.Datadog.Logs/Sinks/Datadog/DatadogTcpClient.cs +++ b/src/Serilog.Sinks.Datadog.Logs/Sinks/Datadog/DatadogTcpClient.cs @@ -73,7 +73,7 @@ private async Task ConnectAsync() } } - public async Task WriteAsync(IEnumerable events) + public async Task WriteAsync(IReadOnlyCollection events) { var payloadBuilder = new StringBuilder(); foreach (var logEvent in events) diff --git a/src/Serilog.Sinks.Datadog.Logs/Sinks/Datadog/IDatadogClient.cs b/src/Serilog.Sinks.Datadog.Logs/Sinks/Datadog/IDatadogClient.cs index a1f643b..ab60655 100644 --- a/src/Serilog.Sinks.Datadog.Logs/Sinks/Datadog/IDatadogClient.cs +++ b/src/Serilog.Sinks.Datadog.Logs/Sinks/Datadog/IDatadogClient.cs @@ -16,7 +16,7 @@ public interface IDatadogClient /// Send payload to Datadog logs-backend. /// /// Serilog events to send. - Task WriteAsync(IEnumerable events); + Task WriteAsync(IReadOnlyCollection events); /// /// Cleanup existing resources. From 459d7bba38749cfbe15dcfcc929e0499261eac09 Mon Sep 17 00:00:00 2001 From: Dmitry Novik Date: Thu, 7 Jan 2021 12:20:42 +1100 Subject: [PATCH 3/9] refactor: removing dead code --- .../Sinks/Datadog/DatadogHttpClient.cs | 1 - src/Serilog.Sinks.Datadog.Logs/Sinks/Datadog/DatadogSink.cs | 6 ++---- .../Sinks/Datadog/IDatadogClient.cs | 1 - .../Sinks/Datadog/LogFormatter.cs | 1 + 4 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/Serilog.Sinks.Datadog.Logs/Sinks/Datadog/DatadogHttpClient.cs b/src/Serilog.Sinks.Datadog.Logs/Sinks/Datadog/DatadogHttpClient.cs index d171664..05d62d1 100644 --- a/src/Serilog.Sinks.Datadog.Logs/Sinks/Datadog/DatadogHttpClient.cs +++ b/src/Serilog.Sinks.Datadog.Logs/Sinks/Datadog/DatadogHttpClient.cs @@ -128,7 +128,6 @@ private async Task Post(LogEventChunk logEventChunk) } catch (Exception) { - continue; } } diff --git a/src/Serilog.Sinks.Datadog.Logs/Sinks/Datadog/DatadogSink.cs b/src/Serilog.Sinks.Datadog.Logs/Sinks/Datadog/DatadogSink.cs index 8389f1d..7aa2a92 100755 --- a/src/Serilog.Sinks.Datadog.Logs/Sinks/Datadog/DatadogSink.cs +++ b/src/Serilog.Sinks.Datadog.Logs/Sinks/Datadog/DatadogSink.cs @@ -91,10 +91,8 @@ private static IDatadogClient CreateDatadogClient(string apiKey, string source, { return new DatadogTcpClient(configuration, logFormatter, apiKey); } - else - { - return new DatadogHttpClient(configuration, logFormatter, apiKey); - } + + return new DatadogHttpClient(configuration, logFormatter, apiKey); } private async Task RunTask(Task task) diff --git a/src/Serilog.Sinks.Datadog.Logs/Sinks/Datadog/IDatadogClient.cs b/src/Serilog.Sinks.Datadog.Logs/Sinks/Datadog/IDatadogClient.cs index ab60655..e2edc5e 100644 --- a/src/Serilog.Sinks.Datadog.Logs/Sinks/Datadog/IDatadogClient.cs +++ b/src/Serilog.Sinks.Datadog.Logs/Sinks/Datadog/IDatadogClient.cs @@ -3,7 +3,6 @@ // This product includes software developed at Datadog (https://www.datadoghq.com/). // Copyright 2019 Datadog, Inc. -using System; using System.Collections.Generic; using System.Threading.Tasks; using Serilog.Events; diff --git a/src/Serilog.Sinks.Datadog.Logs/Sinks/Datadog/LogFormatter.cs b/src/Serilog.Sinks.Datadog.Logs/Sinks/Datadog/LogFormatter.cs index 1382b82..11c3a90 100644 --- a/src/Serilog.Sinks.Datadog.Logs/Sinks/Datadog/LogFormatter.cs +++ b/src/Serilog.Sinks.Datadog.Logs/Sinks/Datadog/LogFormatter.cs @@ -9,6 +9,7 @@ using Serilog.Events; using Serilog.Formatting.Json; using Newtonsoft.Json; + namespace Serilog.Sinks.Datadog.Logs { public class LogFormatter From df0249edba4e14e56fe8b0cddf67d46eb6a324bf Mon Sep 17 00:00:00 2001 From: Dmitry Novik Date: Thu, 7 Jan 2021 12:22:14 +1100 Subject: [PATCH 4/9] fix: renamed missing to --- .../ApplyMicrosoftExtensionsConfiguration.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Serilog.Sinks.Datadog.Logs/Configuration/Implementations/Microsoft.Extensions.Configuration/ApplyMicrosoftExtensionsConfiguration.cs b/src/Serilog.Sinks.Datadog.Logs/Configuration/Implementations/Microsoft.Extensions.Configuration/ApplyMicrosoftExtensionsConfiguration.cs index 5e1be81..b1a0535 100644 --- a/src/Serilog.Sinks.Datadog.Logs/Configuration/Implementations/Microsoft.Extensions.Configuration/ApplyMicrosoftExtensionsConfiguration.cs +++ b/src/Serilog.Sinks.Datadog.Logs/Configuration/Implementations/Microsoft.Extensions.Configuration/ApplyMicrosoftExtensionsConfiguration.cs @@ -17,13 +17,13 @@ internal static class ApplyMicrosoftExtensionsConfiguration /// Create the DatadogConfiguration object or apply any configuration changes to it. /// /// An optional externally-created DatadogConfiguration object to be updated with additional configuration values. - /// A configuration section typically named "configurationSection". + /// A configuration section typically named "configurationSection". /// The "merged" DatadogConfiguration object. - internal static DatadogConfiguration ConfigureDatadogConfiguration(DatadogConfiguration datadogConfiguration, IConfigurationSection configurationOption) + internal static DatadogConfiguration ConfigureDatadogConfiguration(DatadogConfiguration datadogConfiguration, IConfigurationSection configurationSection) { - if (configurationOption == null || !configurationOption.GetChildren().Any()) return datadogConfiguration ?? new DatadogConfiguration(); + if (configurationSection == null || !configurationSection.GetChildren().Any()) return datadogConfiguration ?? new DatadogConfiguration(); - var section = configurationOption.Get(); + var section = configurationSection.Get(); return new DatadogConfiguration( url: datadogConfiguration?.Url ?? section.Url, From 118fa2272ac9573299d2b221b4da87e9d109215c Mon Sep 17 00:00:00 2001 From: Dmitry Novik Date: Thu, 7 Jan 2021 12:24:27 +1100 Subject: [PATCH 5/9] refctor: removing unused string interpolation --- .../Sinks/Datadog/Exceptions/TooBigLogEventException.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Serilog.Sinks.Datadog.Logs/Sinks/Datadog/Exceptions/TooBigLogEventException.cs b/src/Serilog.Sinks.Datadog.Logs/Sinks/Datadog/Exceptions/TooBigLogEventException.cs index 8da3bfb..92d6442 100644 --- a/src/Serilog.Sinks.Datadog.Logs/Sinks/Datadog/Exceptions/TooBigLogEventException.cs +++ b/src/Serilog.Sinks.Datadog.Logs/Sinks/Datadog/Exceptions/TooBigLogEventException.cs @@ -11,7 +11,7 @@ namespace Serilog.Sinks.Datadog.Logs public class TooBigLogEventException : LogEventException { public TooBigLogEventException(IEnumerable logEvents) - : base($"The LogEvent instances are too big to be sent.", logEvents) + : base("The LogEvent instances are too big to be sent.", logEvents) { } } From f0cf14a1a22278b9336cc7170196b34a74d1691e Mon Sep 17 00:00:00 2001 From: Dmitry Novik Date: Thu, 7 Jan 2021 12:25:32 +1100 Subject: [PATCH 6/9] fix: naming formatMessage -> FormatMessage --- .../Sinks/Datadog/DatadogHttpClient.cs | 2 +- .../Sinks/Datadog/DatadogTcpClient.cs | 2 +- src/Serilog.Sinks.Datadog.Logs/Sinks/Datadog/LogFormatter.cs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Serilog.Sinks.Datadog.Logs/Sinks/Datadog/DatadogHttpClient.cs b/src/Serilog.Sinks.Datadog.Logs/Sinks/Datadog/DatadogHttpClient.cs index 05d62d1..0b4c9da 100644 --- a/src/Serilog.Sinks.Datadog.Logs/Sinks/Datadog/DatadogHttpClient.cs +++ b/src/Serilog.Sinks.Datadog.Logs/Sinks/Datadog/DatadogHttpClient.cs @@ -69,7 +69,7 @@ private SerializedEvents SerializeEvents(IReadOnlyCollection events) var logEvents = new List(events.Count); foreach (var logEvent in events) { - var formattedLog = _formatter.formatMessage(logEvent); + var formattedLog = _formatter.FormatMessage(logEvent); var logSize = Encoding.UTF8.GetByteCount(formattedLog); if (logSize > _maxMessageSize) { diff --git a/src/Serilog.Sinks.Datadog.Logs/Sinks/Datadog/DatadogTcpClient.cs b/src/Serilog.Sinks.Datadog.Logs/Sinks/Datadog/DatadogTcpClient.cs index 3f21f5d..ad9086f 100644 --- a/src/Serilog.Sinks.Datadog.Logs/Sinks/Datadog/DatadogTcpClient.cs +++ b/src/Serilog.Sinks.Datadog.Logs/Sinks/Datadog/DatadogTcpClient.cs @@ -79,7 +79,7 @@ public async Task WriteAsync(IReadOnlyCollection events) foreach (var logEvent in events) { payloadBuilder.Append(_apiKey + WhiteSpace); - payloadBuilder.Append(_formatter.formatMessage(logEvent)); + payloadBuilder.Append(_formatter.FormatMessage(logEvent)); payloadBuilder.Append(MessageDelimiter); } string payload = payloadBuilder.ToString(); diff --git a/src/Serilog.Sinks.Datadog.Logs/Sinks/Datadog/LogFormatter.cs b/src/Serilog.Sinks.Datadog.Logs/Sinks/Datadog/LogFormatter.cs index 11c3a90..05ef438 100644 --- a/src/Serilog.Sinks.Datadog.Logs/Sinks/Datadog/LogFormatter.cs +++ b/src/Serilog.Sinks.Datadog.Logs/Sinks/Datadog/LogFormatter.cs @@ -45,7 +45,7 @@ public LogFormatter(string source, string service, string host, string[] tags) /// /// formatMessage enrich the log event with DataDog metadata such as source, service, host and tags. /// - public string formatMessage(LogEvent logEvent) + public string FormatMessage(LogEvent logEvent) { var payload = new StringBuilder(); var writer = new StringWriter(payload); From fa038ea60799f46866329be6143feb93a682c5b8 Mon Sep 17 00:00:00 2001 From: Dmitry Novik Date: Thu, 7 Jan 2021 12:25:54 +1100 Subject: [PATCH 7/9] fix: typo: dictionnary -> dictionary --- src/Serilog.Sinks.Datadog.Logs/Sinks/Datadog/LogFormatter.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Serilog.Sinks.Datadog.Logs/Sinks/Datadog/LogFormatter.cs b/src/Serilog.Sinks.Datadog.Logs/Sinks/Datadog/LogFormatter.cs index 05ef438..f156c46 100644 --- a/src/Serilog.Sinks.Datadog.Logs/Sinks/Datadog/LogFormatter.cs +++ b/src/Serilog.Sinks.Datadog.Logs/Sinks/Datadog/LogFormatter.cs @@ -54,7 +54,7 @@ public string FormatMessage(LogEvent logEvent) // internal structure of the logEvent to give a nicely formatted JSON formatter.Format(logEvent, writer); - // Convert the JSON to a dictionnary and add the DataDog properties + // Convert the JSON to a dictionary and add the DataDog properties var logEventAsDict = JsonConvert.DeserializeObject>(payload.ToString()); if (_source != null) { logEventAsDict.Add("ddsource", _source); } if (_service != null) { logEventAsDict.Add("service",_service); } From ea051a33f843f8e9c42ed0825593c857beeafc51 Mon Sep 17 00:00:00 2001 From: Jesse Szwedko Date: Wed, 8 May 2024 15:47:31 -0400 Subject: [PATCH 8/9] Match parameter name with field name Signed-off-by: Jesse Szwedko --- .../Sinks/Datadog/DatadogHttpClient.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Serilog.Sinks.Datadog.Logs/Sinks/Datadog/DatadogHttpClient.cs b/src/Serilog.Sinks.Datadog.Logs/Sinks/Datadog/DatadogHttpClient.cs index 1906e28..04f21fb 100644 --- a/src/Serilog.Sinks.Datadog.Logs/Sinks/Datadog/DatadogHttpClient.cs +++ b/src/Serilog.Sinks.Datadog.Logs/Sinks/Datadog/DatadogHttpClient.cs @@ -29,12 +29,12 @@ public class DatadogHttpClient : IDatadogClient /// private const int MaxBackoff = 30; - public DatadogHttpClient(string url, DatadogLogRenderer renderer, HttpClient client, int retries) + public DatadogHttpClient(string url, DatadogLogRenderer renderer, HttpClient client, int maxRetries) { _url = url; _renderer = renderer; _client = client; - _maxRetries = retries; + _maxRetries = maxRetries; } public Task WriteAsync(IReadOnlyCollection events) From aebb5435c998b530035de1a657ac099102d45604 Mon Sep 17 00:00:00 2001 From: Jesse Szwedko Date: Thu, 9 May 2024 09:34:41 -0400 Subject: [PATCH 9/9] Remove unrelated changes to retries Signed-off-by: Jesse Szwedko --- .../Sinks/Datadog/DatadogHttpClient.cs | 6 ++---- src/Serilog.Sinks.Datadog.Logs/Sinks/Datadog/DatadogSink.cs | 5 ++--- .../Sinks/Datadog/DatadogTcpClient.cs | 2 +- .../Sinks/Datadog/IDatadogClient.cs | 2 +- tests/Serilog.Sinks.Datadog.Logs.Tests/NoopClient.cs | 2 +- 5 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/Serilog.Sinks.Datadog.Logs/Sinks/Datadog/DatadogHttpClient.cs b/src/Serilog.Sinks.Datadog.Logs/Sinks/Datadog/DatadogHttpClient.cs index 04f21fb..b544263 100644 --- a/src/Serilog.Sinks.Datadog.Logs/Sinks/Datadog/DatadogHttpClient.cs +++ b/src/Serilog.Sinks.Datadog.Logs/Sinks/Datadog/DatadogHttpClient.cs @@ -37,20 +37,18 @@ public DatadogHttpClient(string url, DatadogLogRenderer renderer, HttpClient cli _maxRetries = maxRetries; } - public Task WriteAsync(IReadOnlyCollection events) + public Task WriteAsync(IEnumerable events) { var builtEvents = BuildEvents(events); var tasks = builtEvents.Select(post => Post(post)); return Task.WhenAll(tasks); } - private List BuildEvents(IReadOnlyCollection events) + private List BuildEvents(IEnumerable events) { var builders = new List(); var builder = new JsonPayloadBuilder(); - var chunkBuffer = new List(events.Count()); - var logEvents = new List(events.Count()); foreach (var logEvent in events) { var payloads = _renderer.RenderDatadogEvents(logEvent); diff --git a/src/Serilog.Sinks.Datadog.Logs/Sinks/Datadog/DatadogSink.cs b/src/Serilog.Sinks.Datadog.Logs/Sinks/Datadog/DatadogSink.cs index af412ff..271d100 100755 --- a/src/Serilog.Sinks.Datadog.Logs/Sinks/Datadog/DatadogSink.cs +++ b/src/Serilog.Sinks.Datadog.Logs/Sinks/Datadog/DatadogSink.cs @@ -100,13 +100,12 @@ public async Task EmitBatchAsync(IEnumerable events) { try { - var batch = events.ToArray(); - if (!batch.Any()) + if (!events.Any()) { return; } - var task = _client.WriteAsync(batch); + var task = _client.WriteAsync(events); await RunTask(task); } catch (Exception e) diff --git a/src/Serilog.Sinks.Datadog.Logs/Sinks/Datadog/DatadogTcpClient.cs b/src/Serilog.Sinks.Datadog.Logs/Sinks/Datadog/DatadogTcpClient.cs index 336ee96..25f405c 100644 --- a/src/Serilog.Sinks.Datadog.Logs/Sinks/Datadog/DatadogTcpClient.cs +++ b/src/Serilog.Sinks.Datadog.Logs/Sinks/Datadog/DatadogTcpClient.cs @@ -82,7 +82,7 @@ private async Task ConnectAsync() } } - public async Task WriteAsync(IReadOnlyCollection events) + public async Task WriteAsync(IEnumerable events) { var payloadBuilder = new StringBuilder(); foreach (var logEvent in events) diff --git a/src/Serilog.Sinks.Datadog.Logs/Sinks/Datadog/IDatadogClient.cs b/src/Serilog.Sinks.Datadog.Logs/Sinks/Datadog/IDatadogClient.cs index e2edc5e..b336b16 100644 --- a/src/Serilog.Sinks.Datadog.Logs/Sinks/Datadog/IDatadogClient.cs +++ b/src/Serilog.Sinks.Datadog.Logs/Sinks/Datadog/IDatadogClient.cs @@ -15,7 +15,7 @@ public interface IDatadogClient /// Send payload to Datadog logs-backend. /// /// Serilog events to send. - Task WriteAsync(IReadOnlyCollection events); + Task WriteAsync(IEnumerable events); /// /// Cleanup existing resources. diff --git a/tests/Serilog.Sinks.Datadog.Logs.Tests/NoopClient.cs b/tests/Serilog.Sinks.Datadog.Logs.Tests/NoopClient.cs index d7bbbcc..fe14bae 100644 --- a/tests/Serilog.Sinks.Datadog.Logs.Tests/NoopClient.cs +++ b/tests/Serilog.Sinks.Datadog.Logs.Tests/NoopClient.cs @@ -22,7 +22,7 @@ public NoopClient(string apiKey, DatadogLogRenderer formatter) _formatter = formatter; } - public Task WriteAsync(IReadOnlyCollection events) + public Task WriteAsync(IEnumerable events) { foreach (var logEvent in events)