Skip to content

Commit 344c192

Browse files
NR-233726: gzip logs
1 parent 5a50928 commit 344c192

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

Agent/Utilities/NRLogger.m

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#import "NRMASupportMetricHelper.h"
1616
#import "NRMAFlags.h"
1717
#import "NRAutoLogCollector.h"
18+
#import "NRMAHarvesterConnection+GZip.h"
1819

1920
NRLogger *_nr_logger = nil;
2021

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

561-
NSData* formattedData = [logMessagesJson dataUsingEncoding:NSUTF8StringEncoding];
562-
562+
// Here we add gzip compression to the log data.
563+
NSData* formattedData = [NRMAHarvesterConnection gzipData:[logMessagesJson dataUsingEncoding:NSUTF8StringEncoding]];
564+
563565
// We clear the log when we save the existing logs to uploadQueue.
564566
[self clearLog];
565567

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

613+
//NSString* contentEncoding = message.length <= 512 ? kNRMAIdentityHeader : kNRMAGZipHeader;
614+
615+
[req setValue:kNRMAGZipHeader forHTTPHeaderField:kNRMAContentEncodingHeader];
616+
611617
req.HTTPMethod = @"POST";
612618

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

0 commit comments

Comments
 (0)