Skip to content

Commit

Permalink
NR-348708: session attributes are added to log common block
Browse files Browse the repository at this point in the history
  • Loading branch information
cdillard-NewRelic committed Jan 28, 2025
1 parent 6b814a2 commit f496c28
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions Agent/Utilities/NRLogger.m
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,24 @@ - (NSMutableDictionary*) commonBlockDict {
if (nativePlatform) [commonAttributes setObject:nativePlatform forKey:NRLogMessageInstrumentationCollectorKey];
if (nrAppId) [commonAttributes setObject:nrAppId forKey:NRLogMessageAppIdKey];


NSString* sessionAttributes = [[NewRelicAgentInternal sharedInstance].analyticsController sessionAttributeJSONString];
if (sessionAttributes != nil && [sessionAttributes length] > 0) {
NSDictionary* dictionary = [NSJSONSerialization JSONObjectWithData:[sessionAttributes dataUsingEncoding:NSUTF8StringEncoding]
options:0
error:nil];
for (NSString *key in dictionary) {
id value = [dictionary objectForKey:key];


if (value) {
[commonAttributes setObject:value forKey:key];
}
}
}



return commonAttributes;
}

Expand Down Expand Up @@ -598,7 +616,6 @@ - (void) processNextUploadTask {
NSData *formattedData = [self->uploadQueue firstObject];

if (self->debugLogs) {
//NSString* logMessagesJson = [NSString stringWithFormat:@"[ %@ ]", [[NSString alloc] initWithData:formattedData encoding:NSUTF8StringEncoding]];
NSArray* decode = [NSJSONSerialization JSONObjectWithData:formattedData
options:0
error:nil];
Expand All @@ -609,9 +626,6 @@ - (void) processNextUploadTask {
NSMutableURLRequest* req = [NSMutableURLRequest requestWithURL:[NSURL URLWithString: self->logURL]];
[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";
Expand Down

0 comments on commit f496c28

Please sign in to comment.