Skip to content

Commit

Permalink
Fix the upload compressed bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
dudikeleti committed Dec 12, 2024
1 parent 31ab184 commit bef9f0d
Showing 1 changed file with 11 additions and 24 deletions.
35 changes: 11 additions & 24 deletions tracer/src/Datadog.Trace/Debugger/Upload/SymbolUploadApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ ArraySegment<byte> GetEventMetadataAsArraySegment()

public override async Task<bool> SendBatchAsync(ArraySegment<byte> symbols)
{
if (symbols.Array == null)
if (symbols.Array == null || symbols.Count == 0)
{
return false;
}
Expand All @@ -82,40 +82,27 @@ public override async Task<bool> SendBatchAsync(ArraySegment<byte> symbols)
var retries = 0;
var sleepDuration = StartingSleepDuration;

MultipartFormItem[] items;
MultipartFormItem symbolsItem;

if (_enableCompression)
{
using (var memoryStream = new MemoryStream())
{
using var memoryStream = new MemoryStream();
#if NETFRAMEWORK
using (var gzipStream = new Vendors.ICSharpCode.SharpZipLib.GZip.GZipOutputStream(memoryStream))
{
gzipStream.Write(symbols.Array, 0, symbols.Array.Length);
}
using var gzipStream = new Vendors.ICSharpCode.SharpZipLib.GZip.GZipOutputStream(memoryStream);
await gzipStream.WriteAsync(symbols.Array, 0, symbols.Array.Length);
#else
using (var gzipStream = new GZipStream(memoryStream, CompressionMode.Compress))
{
gzipStream.Write(symbols.Array, 0, symbols.Array.Length);
}
await using var gzipStream = new GZipStream(memoryStream, CompressionMode.Compress);
await gzipStream.WriteAsync(symbols.Array, 0, symbols.Array.Length);
#endif
}

items =
[
new("file", "gzip", "file.gz", symbols),
new("event", MimeTypes.Json, "event.json", _eventMetadata)
];
symbolsItem = new MultipartFormItem("file", "gzip", "file.gz", new ArraySegment<byte>(memoryStream.ToArray()));
}
else
{
items =
[
new("file", MimeTypes.Json, "file.json", symbols),
new("event", MimeTypes.Json, "event.json", _eventMetadata)
];
symbolsItem = new MultipartFormItem("file", MimeTypes.Json, "file.json", symbols);
}

var items = new[] { symbolsItem, new MultipartFormItem("event", MimeTypes.Json, "event.json", _eventMetadata) };

while (retries < MaxRetries)
{
using var response = await request.PostAsync(items).ConfigureAwait(false);
Expand Down

0 comments on commit bef9f0d

Please sign in to comment.