Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NR-199912: Background Instrumentation #192

Merged
merged 14 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions Agent.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,6 @@
02FF492024DC624400115469 /* NRMACrashReport_CodeType.m in Sources */ = {isa = PBXBuildFile; fileRef = 02FF490C24DC624400115469 /* NRMACrashReport_CodeType.m */; };
02FF492124DC624400115469 /* NRMACrashReport_AppInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = 02FF490D24DC624400115469 /* NRMACrashReport_AppInfo.h */; };
02FF493124DC625A00115469 /* HexUploadPublisher.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 02FF492324DC625A00115469 /* HexUploadPublisher.hpp */; };
02FF493224DC625A00115469 /* NRMAHexBackgroundUploader.h in Headers */ = {isa = PBXBuildFile; fileRef = 02FF492424DC625A00115469 /* NRMAHexBackgroundUploader.h */; };
02FF493324DC625A00115469 /* NRMAHexUploader.m in Sources */ = {isa = PBXBuildFile; fileRef = 02FF492524DC625A00115469 /* NRMAHexUploader.m */; };
02FF493424DC625A00115469 /* NRMARetryTracker.m in Sources */ = {isa = PBXBuildFile; fileRef = 02FF492624DC625A00115469 /* NRMARetryTracker.m */; };
02FF493524DC625A00115469 /* HexUploadPublisher.mm in Sources */ = {isa = PBXBuildFile; fileRef = 02FF492724DC625A00115469 /* HexUploadPublisher.mm */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; };
Expand All @@ -364,7 +363,6 @@
02FF493B24DC625A00115469 /* NRMARetryTracker.h in Headers */ = {isa = PBXBuildFile; fileRef = 02FF492D24DC625A00115469 /* NRMARetryTracker.h */; };
02FF493C24DC625A00115469 /* NRMASessionIdentifierManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 02FF492E24DC625A00115469 /* NRMASessionIdentifierManager.h */; };
02FF493D24DC625A00115469 /* NRMAHandledExceptions.mm in Sources */ = {isa = PBXBuildFile; fileRef = 02FF492F24DC625A00115469 /* NRMAHandledExceptions.mm */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; };
02FF493E24DC625A00115469 /* NRMAHexBackgroundUploader.mm in Sources */ = {isa = PBXBuildFile; fileRef = 02FF493024DC625A00115469 /* NRMAHexBackgroundUploader.mm */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; };
02FF494B24DC626E00115469 /* NRMAHarvestController.m in Sources */ = {isa = PBXBuildFile; fileRef = 02FF494024DC626E00115469 /* NRMAHarvestController.m */; };
02FF494C24DC626E00115469 /* NRMAHarvestTimer.h in Headers */ = {isa = PBXBuildFile; fileRef = 02FF494124DC626E00115469 /* NRMAHarvestTimer.h */; };
02FF494D24DC626E00115469 /* NRMAHarvesterConnection.m in Sources */ = {isa = PBXBuildFile; fileRef = 02FF494224DC626E00115469 /* NRMAHarvesterConnection.m */; };
Expand Down Expand Up @@ -682,7 +680,6 @@
02FF4BA024E3201400115469 /* NRMACrashDataWriter.h in Headers */ = {isa = PBXBuildFile; fileRef = 02FF48CD24DC622400115469 /* NRMACrashDataWriter.h */; };
02FF4BA124E3201400115469 /* NRMAHarvestableArray.h in Headers */ = {isa = PBXBuildFile; fileRef = 02FF49D724DC636100115469 /* NRMAHarvestableArray.h */; };
02FF4BA224E3201400115469 /* NRMABool.h in Headers */ = {isa = PBXBuildFile; fileRef = 02FF4A9224DC652D00115469 /* NRMABool.h */; };
02FF4BA324E3201400115469 /* NRMAHexBackgroundUploader.h in Headers */ = {isa = PBXBuildFile; fileRef = 02FF492424DC625A00115469 /* NRMAHexBackgroundUploader.h */; };
02FF4BA424E3201400115469 /* NRMAExceptionDataCollectionWrapper.h in Headers */ = {isa = PBXBuildFile; fileRef = 02FF48CF24DC622400115469 /* NRMAExceptionDataCollectionWrapper.h */; };
02FF4BA524E3201400115469 /* NRMAHarvestableAnalytics.h in Headers */ = {isa = PBXBuildFile; fileRef = 02FF498724DC62B500115469 /* NRMAHarvestableAnalytics.h */; };
02FF4BA724E3201400115469 /* NRMAExceptionHandlerStartupManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 02FF47FF24DB56B800115469 /* NRMAExceptionHandlerStartupManager.h */; };
Expand Down Expand Up @@ -862,7 +859,6 @@
02FF4C6824E3201400115469 /* NRMAActivityTraceMeasurementCreator.m in Sources */ = {isa = PBXBuildFile; fileRef = 02FF4A1724DC648600115469 /* NRMAActivityTraceMeasurementCreator.m */; };
02FF4C6924E3201400115469 /* NRMAMeasurement.m in Sources */ = {isa = PBXBuildFile; fileRef = 02FF4A3924DC64D400115469 /* NRMAMeasurement.m */; };
02FF4C6A24E3201400115469 /* NRMAMeasurementException.m in Sources */ = {isa = PBXBuildFile; fileRef = 02FF4A3F24DC64D500115469 /* NRMAMeasurementException.m */; };
02FF4C6C24E3201400115469 /* NRMAHexBackgroundUploader.mm in Sources */ = {isa = PBXBuildFile; fileRef = 02FF493024DC625A00115469 /* NRMAHexBackgroundUploader.mm */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; };
02FF4C6D24E3201400115469 /* NRMAHarvestableArray.m in Sources */ = {isa = PBXBuildFile; fileRef = 02FF49CF24DC636100115469 /* NRMAHarvestableArray.m */; };
02FF4C6E24E3201400115469 /* NewRelicInternalUtils.m in Sources */ = {isa = PBXBuildFile; fileRef = 02FF4A9024DC652D00115469 /* NewRelicInternalUtils.m */; };
02FF4C6F24E3201400115469 /* NRMANetworkResponseData.mm in Sources */ = {isa = PBXBuildFile; fileRef = 02FF485924DC615A00115469 /* NRMANetworkResponseData.mm */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; };
Expand Down Expand Up @@ -1682,7 +1678,6 @@
02FF490C24DC624400115469 /* NRMACrashReport_CodeType.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NRMACrashReport_CodeType.m; sourceTree = "<group>"; };
02FF490D24DC624400115469 /* NRMACrashReport_AppInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NRMACrashReport_AppInfo.h; sourceTree = "<group>"; };
02FF492324DC625A00115469 /* HexUploadPublisher.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = HexUploadPublisher.hpp; sourceTree = "<group>"; };
02FF492424DC625A00115469 /* NRMAHexBackgroundUploader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NRMAHexBackgroundUploader.h; sourceTree = "<group>"; };
02FF492524DC625A00115469 /* NRMAHexUploader.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NRMAHexUploader.m; sourceTree = "<group>"; };
02FF492624DC625A00115469 /* NRMARetryTracker.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NRMARetryTracker.m; sourceTree = "<group>"; };
02FF492724DC625A00115469 /* HexUploadPublisher.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = HexUploadPublisher.mm; sourceTree = "<group>"; };
Expand All @@ -1694,7 +1689,6 @@
02FF492D24DC625A00115469 /* NRMARetryTracker.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NRMARetryTracker.h; sourceTree = "<group>"; };
02FF492E24DC625A00115469 /* NRMASessionIdentifierManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NRMASessionIdentifierManager.h; sourceTree = "<group>"; };
02FF492F24DC625A00115469 /* NRMAHandledExceptions.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = NRMAHandledExceptions.mm; sourceTree = "<group>"; };
02FF493024DC625A00115469 /* NRMAHexBackgroundUploader.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = NRMAHexBackgroundUploader.mm; sourceTree = "<group>"; };
02FF494024DC626E00115469 /* NRMAHarvestController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NRMAHarvestController.m; sourceTree = "<group>"; };
02FF494124DC626E00115469 /* NRMAHarvestTimer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NRMAHarvestTimer.h; sourceTree = "<group>"; };
02FF494224DC626E00115469 /* NRMAHarvesterConnection.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NRMAHarvesterConnection.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2846,8 +2840,6 @@
02FF492A24DC625A00115469 /* NRMAExceptionReportAdaptor.mm */,
02FF492824DC625A00115469 /* NRMAHandledExceptions.h */,
02FF492F24DC625A00115469 /* NRMAHandledExceptions.mm */,
02FF492424DC625A00115469 /* NRMAHexBackgroundUploader.h */,
02FF493024DC625A00115469 /* NRMAHexBackgroundUploader.mm */,
02FF492B24DC625A00115469 /* NRMAHexUploader.h */,
02FF492524DC625A00115469 /* NRMAHexUploader.m */,
02FF492D24DC625A00115469 /* NRMARetryTracker.h */,
Expand Down Expand Up @@ -3504,7 +3496,6 @@
02FF48E224DC622700115469 /* NRMACrashDataWriter.h in Headers */,
02FF49E224DC636100115469 /* NRMAHarvestableArray.h in Headers */,
02FF4AAD24DC652E00115469 /* NRMABool.h in Headers */,
02FF493224DC625A00115469 /* NRMAHexBackgroundUploader.h in Headers */,
02FF48E424DC622700115469 /* NRMAExceptionDataCollectionWrapper.h in Headers */,
02FF49B524DC62B800115469 /* NRMAHarvestableAnalytics.h in Headers */,
02FF480124DB56B900115469 /* NRMAExceptionHandlerStartupManager.h in Headers */,
Expand Down Expand Up @@ -3720,7 +3711,6 @@
02FF4BA024E3201400115469 /* NRMACrashDataWriter.h in Headers */,
02FF4BA124E3201400115469 /* NRMAHarvestableArray.h in Headers */,
02FF4BA224E3201400115469 /* NRMABool.h in Headers */,
02FF4BA324E3201400115469 /* NRMAHexBackgroundUploader.h in Headers */,
02FF4BA424E3201400115469 /* NRMAExceptionDataCollectionWrapper.h in Headers */,
02FF4BA524E3201400115469 /* NRMAHarvestableAnalytics.h in Headers */,
02FF4BA724E3201400115469 /* NRMAExceptionHandlerStartupManager.h in Headers */,
Expand Down Expand Up @@ -4529,7 +4519,6 @@
02FF4A4824DC64D500115469 /* NRMAMeasurement.m in Sources */,
02FF4A4E24DC64D500115469 /* NRMAMeasurementException.m in Sources */,
02FF48AA24DC61E900115469 /* NRMAWKWebViewNavigationDelegate.m in Sources */,
02FF493E24DC625A00115469 /* NRMAHexBackgroundUploader.mm in Sources */,
02FF49DA24DC636100115469 /* NRMAHarvestableArray.m in Sources */,
02FF4AAB24DC652E00115469 /* NewRelicInternalUtils.m in Sources */,
02FF486424DC615A00115469 /* NRMANetworkResponseData.mm in Sources */,
Expand Down Expand Up @@ -4844,7 +4833,6 @@
02FF4C6824E3201400115469 /* NRMAActivityTraceMeasurementCreator.m in Sources */,
02FF4C6924E3201400115469 /* NRMAMeasurement.m in Sources */,
02FF4C6A24E3201400115469 /* NRMAMeasurementException.m in Sources */,
02FF4C6C24E3201400115469 /* NRMAHexBackgroundUploader.mm in Sources */,
02FF4C6D24E3201400115469 /* NRMAHarvestableArray.m in Sources */,
02FF4C6E24E3201400115469 /* NewRelicInternalUtils.m in Sources */,
02FF4C6F24E3201400115469 /* NRMANetworkResponseData.mm in Sources */,
Expand Down
1 change: 1 addition & 0 deletions Agent/Analytics/Constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ extern NSString *const kNRMA_Attrib_dtId;
extern NSString *const kNRMA_Attrib_dtTraceId;
extern NSString *const kNRMA_Attrib_name;
extern NSString *const kNRMA_Attrib_offline;
extern NSString *const kNRMA_Attrib_background;

extern NSString *const kNRMA_Val_errorType_HTTP;
extern NSString *const kNRMA_Val_errorType_Network;
Expand Down
1 change: 1 addition & 0 deletions Agent/Analytics/Constants.m
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
NSString * const kNRMA_Attrib_dtTraceId = @"trace.id";
NSString * const kNRMA_Attrib_name = @"name";
NSString * const kNRMA_Attrib_offline = @"offline";
NSString * const kNRMA_Attrib_background = @"background";

NSString * const kNRMA_Val_errorType_HTTP = @"HTTPError";
NSString * const kNRMA_Val_errorType_Network = @"NetworkFailure";
Expand Down
9 changes: 9 additions & 0 deletions Agent/Analytics/Events/NRMAMobileEvent.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@
// Copyright © 2023 New Relic. All rights reserved.
//

#import <UIKit/UIKit.h>

#import "NRMAMobileEvent.h"
#import "Constants.h"
#import "NRMAFlags.h"
#import "NewRelicInternalUtils.h"
#import "NewRelicAgentInternal.h"

static NSString* const kTimestampKey = @"Timestamp";
static NSString* const kSessionElapsedTimeKey = @"SessionElapsedTime";
Expand Down Expand Up @@ -38,6 +41,12 @@ - (nonnull instancetype) initWithTimestamp:(NSTimeInterval)timestamp
}
}
}
// Handle Background attribute addition.
if([NRMAFlags shouldEnableBackgroundReporting]) {
if ([NewRelicAgentInternal sharedInstance].currentApplicationState == UIApplicationStateBackground) {
[self addAttribute:kNRMA_Attrib_background value:@YES];
}
}
}

return self;
Expand Down
2 changes: 1 addition & 1 deletion Agent/Analytics/NRMAAnalytics.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
- (void) clearLastSessionsAnalytics;

- (BOOL) checkOfflineStatus;

- (BOOL) checkBackgroundStatus;
//this utilizes setSessionAttribute:value: which validates the user input 'name'.
- (BOOL) setLastInteraction:(NSString*)name;

Expand Down
15 changes: 11 additions & 4 deletions Agent/Analytics/NRMAAnalytics.mm
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ - (BOOL) addInteractionEvent:(NSString*)name

return [_eventManager addEvent:[event autorelease]];
} else {
return _analyticsController->addInteractionEvent([name UTF8String], duration_secs, [self checkOfflineStatus]);
return _analyticsController->addInteractionEvent([name UTF8String], duration_secs, [self checkOfflineStatus], [self checkBackgroundStatus]);
}
}

Expand Down Expand Up @@ -506,7 +506,7 @@ - (BOOL)addNetworkRequestEvent:(NRMANetworkRequestData *)requestData
if ([NRMAFlags shouldEnableNetworkRequestEvents]) {
NewRelic::NetworkRequestData* networkRequestData = [requestData getNetworkRequestData];
NewRelic::NetworkResponseData* networkResponseData = [responseData getNetworkResponseData];
return _analyticsController->addRequestEvent(*networkRequestData, *networkResponseData, std::move(payload), [self checkOfflineStatus]);
return _analyticsController->addRequestEvent(*networkRequestData, *networkResponseData, std::move(payload), [self checkOfflineStatus], [self checkBackgroundStatus]);
}
return NO;
}
Expand All @@ -518,7 +518,7 @@ - (BOOL)addNetworkErrorEvent:(NRMANetworkRequestData *)requestData
NewRelic::NetworkRequestData* networkRequestData = [requestData getNetworkRequestData];
NewRelic::NetworkResponseData* networkResponseData = [responseData getNetworkResponseData];

return _analyticsController->addNetworkErrorEvent(*networkRequestData, *networkResponseData,std::move(payload), [self checkOfflineStatus]);
return _analyticsController->addNetworkErrorEvent(*networkRequestData, *networkResponseData,std::move(payload), [self checkOfflineStatus], [self checkBackgroundStatus]);
}

return NO;
Expand All @@ -531,7 +531,7 @@ - (BOOL)addHTTPErrorEvent:(NRMANetworkRequestData *)requestData
NewRelic::NetworkRequestData* networkRequestData = [requestData getNetworkRequestData];
NewRelic::NetworkResponseData* networkResponseData = [responseData getNetworkResponseData];

return _analyticsController->addHTTPErrorEvent(*networkRequestData, *networkResponseData, std::move(payload), [self checkOfflineStatus]);
return _analyticsController->addHTTPErrorEvent(*networkRequestData, *networkResponseData, std::move(payload), [self checkOfflineStatus], [self checkBackgroundStatus]);
}
return NO;
}
Expand Down Expand Up @@ -915,6 +915,13 @@ - (BOOL) checkOfflineStatus {
return false;
}

- (BOOL) checkBackgroundStatus {
if([NRMAFlags shouldEnableBackgroundReporting]) {
return ([NewRelicAgentInternal sharedInstance].currentApplicationState == UIApplicationStateBackground);
}
return false;
}

- (BOOL)recordUserAction:(NRMAUserAction *)userAction {
if (userAction == nil) { return NO; };

Expand Down
2 changes: 2 additions & 0 deletions Agent/FeatureFlags/NRMAFlags.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@

+ (BOOL) shouldEnableNewEventSystem;

+ (BOOL) shouldEnableBackgroundReporting;

+ (NSArray<NSString*>*) namesForFlags:(NRMAFeatureFlags)flags;

// Private Setting
Expand Down
9 changes: 9 additions & 0 deletions Agent/FeatureFlags/NRMAFlags.m
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,11 @@ + (BOOL) shouldEnableLogReporting {
+ (BOOL) shouldEnableNewEventSystem {
return ([NRMAFlags featureFlags] & NRFeatureFlag_NewEventSystem) != 0;
}

+ (BOOL) shouldEnableBackgroundReporting {
return ([NRMAFlags featureFlags] & NRFeatureFlag_BackgroundReporting) != 0;
}

+ (NSArray<NSString*>*) namesForFlags:(NRMAFeatureFlags)flags {
NSMutableArray *retArray = [NSMutableArray array];
if ((flags & NRFeatureFlag_InteractionTracing) == NRFeatureFlag_InteractionTracing) {
Expand Down Expand Up @@ -234,6 +239,10 @@ + (BOOL) shouldEnableNewEventSystem {
if ((flags & NRFeatureFlag_NewEventSystem) == NRFeatureFlag_NewEventSystem) {
[retArray addObject:@"NewEventSystem"];
}
if ((flags & NRFeatureFlag_BackgroundReporting) == NRFeatureFlag_BackgroundReporting) {
[retArray addObject:@"BackgroundReporting"];
}

return retArray;
}

Expand Down
4 changes: 4 additions & 0 deletions Agent/General/NewRelicAgentInternal.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#import "NRMAUserActionFacade.h"
#import "NRMAURLTransformer.h"

#import <BackgroundTasks/BackgroundTasks.h>

// Keys used for harvester data request.
#define NEW_RELIC_APP_VERSION_HEADER_KEY @"X-NewRelic-App-Version"
#define NEW_RELIC_OS_NAME_HEADER_KEY @"X-NewRelic-OS-Name"
Expand Down Expand Up @@ -44,6 +46,8 @@

@property (nonatomic, assign) BOOL isShutdown;

@property (nonatomic, readonly, assign) UIApplicationState currentApplicationState;

+ (void)shutdown;

+ (void)startWithApplicationToken:(NSString*)appToken
Expand Down
Loading
Loading