Skip to content

Commit

Permalink
NR-233726: gzip logs
Browse files Browse the repository at this point in the history
  • Loading branch information
cdillard-NewRelic committed Jan 6, 2025
1 parent 5a50928 commit 344c192
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions Agent/Utilities/NRLogger.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#import "NRMASupportMetricHelper.h"
#import "NRMAFlags.h"
#import "NRAutoLogCollector.h"
#import "NRMAHarvesterConnection+GZip.h"

NRLogger *_nr_logger = nil;

Expand Down Expand Up @@ -558,8 +559,9 @@ - (void)enqueueLogUpload {
// Old version of the line
// NSString* logMessagesJson = [NSString stringWithFormat:@"[ %@ ]", [[NSString alloc] initWithData:logData encoding:NSUTF8StringEncoding]];

NSData* formattedData = [logMessagesJson dataUsingEncoding:NSUTF8StringEncoding];

// Here we add gzip compression to the log data.
NSData* formattedData = [NRMAHarvesterConnection gzipData:[logMessagesJson dataUsingEncoding:NSUTF8StringEncoding]];

// We clear the log when we save the existing logs to uploadQueue.
[self clearLog];

Expand Down Expand Up @@ -608,6 +610,10 @@ - (void) processNextUploadTask {
[req setValue:self->logIngestKey forHTTPHeaderField:@"X-App-License-Key"];
[req setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];

//NSString* contentEncoding = message.length <= 512 ? kNRMAIdentityHeader : kNRMAGZipHeader;

[req setValue:kNRMAGZipHeader forHTTPHeaderField:kNRMAContentEncodingHeader];

req.HTTPMethod = @"POST";

NSURLSessionUploadTask *uploadTask = [session uploadTaskWithRequest:req fromData:formattedData completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
Expand Down

0 comments on commit 344c192

Please sign in to comment.