diff --git a/tracer/src/Datadog.Trace/LibDatadog/TraceExporter.cs b/tracer/src/Datadog.Trace/LibDatadog/TraceExporter.cs index b392701deeb6..e42b5e9a1365 100644 --- a/tracer/src/Datadog.Trace/LibDatadog/TraceExporter.cs +++ b/tracer/src/Datadog.Trace/LibDatadog/TraceExporter.cs @@ -6,6 +6,7 @@ #nullable enable using System; +using System.Globalization; using System.Runtime.InteropServices; using System.Threading.Tasks; using Datadog.Trace.Agent; @@ -47,12 +48,21 @@ public Task SendTracesAsync(ArraySegment traces, int numberOfTraces, }; var responsePtr = IntPtr.Zero; - using var error = NativeInterop.Exporter.Send(this, tracesSlice, (UIntPtr)numberOfTraces, ref responsePtr); - if (!error.IsInvalid) + try { - var ex = error.ToException(); - _log.Error(ex, "An error occurred while sending data to the agent. Error Code: {ErrorCode}, message: {Message}", ex.ErrorCode, ex.Message); - throw ex; + using var error = NativeInterop.Exporter.Send(this, tracesSlice, (UIntPtr)numberOfTraces, ref responsePtr); + if (!error.IsInvalid) + { + var ex = error.ToException(); +#pragma warning disable DDLOG004 + _log.Error(ex, "An error occurred while sending data to the agent. Error Code: " + ex.ErrorCode + ", message: {Message}", ex.Message); +#pragma warning restore DDLOG004 + throw ex; + } + } + catch (Exception ex) when (ex is not TraceExporterException) + { + _log.Error(ex, "An error occurred while sending data to the agent."); } } } diff --git a/tracer/src/Datadog.Trace/TracerManagerFactory.cs b/tracer/src/Datadog.Trace/TracerManagerFactory.cs index e1e64cc9bbb7..af36880c0660 100644 --- a/tracer/src/Datadog.Trace/TracerManagerFactory.cs +++ b/tracer/src/Datadog.Trace/TracerManagerFactory.cs @@ -363,43 +363,50 @@ private IApi GetApi(TracerSettings settings, IDogStatsd statsd, Action