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

Conversation

cdillard-NewRelic
Copy link
Member

@cdillard-NewRelic cdillard-NewRelic commented Dec 27, 2023

// NOTE: BackgroundReporting is only enabled for iOS 13+.

Accomplishes Acceptance Criteria of tickets:

https://new-relic.atlassian.net/browse/NR-238932
https://new-relic.atlassian.net/browse/NR-238931

Prerequisites in your iOS app project to use Background instrumentation

Add the key Permitted background task scheduler identifiers with an array including an item containing your apps bundle Id.

Enable Background Fetch and Background Processing in the “Background Modes” section of the Xcode project capabilities.

Run test harvest in background with:

e -l objc -- (void)[[BGTaskScheduler sharedScheduler] _simulateLaunchForTaskWithIdentifier:@"com.newrelic.NRTestApp.bitcode"]

replacing com.newrelic.NRTestApp.bitcode with your apps bundleId.

Or Await the periodically occurring harvest in the background.

The exact frequency at which your tasks will run is determined by the system based on factors like device usage, batt life, and workloads. Therefore while we can request periodic execution , the system ultimately is the one that decides when to execute tasks. The background task will be run once per 24hr period.

In order to add BackgroundTasks to app you must add this to your AppDelegate.

    // Background fetch handling.
    func application(_ application: UIApplication, performFetchWithCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {

        NewRelic.logVerbose("performFetchWithCompletionHandler called")
        completionHandler(.newData)
    }

Adds changes to NewRelicAgentInternal such that BackgroundTasks framework is interacted with and background task can be scheduled for harvest

Comments out following files as they are no longer used in our agent project.

Agent/HandledException/NRMAHexBackgroundUploader.h
Agent/HandledException/NRMASessionIdentifierManager.h
Tests/Unit-Tests/NewRelicAgentTests/Handled-Exception-Tests/TestSessionIdentifierManger.m

@cdillard-NewRelic
Copy link
Member Author

Using background tasks framework like my open Proof of Concept for iOS Background Instrumentation on iOS only guarantees that iOS will harvest in the background once per 24hr period. It’s kind of crappy but its the best guarantee we can get from iOS and background execution.

… NR-199912-background-instrumentation

# Conflicts:
#	Agent/Public/NewRelicFeatureFlags.h
@cdillard-NewRelic cdillard-NewRelic changed the title NR-199912: Background Instrumentation Proof of Concept NR-199912: Background Instrumentation Mar 5, 2024
@cdillard-NewRelic cdillard-NewRelic marked this pull request as ready for review March 28, 2024 17:04
mbruin-NR
mbruin-NR previously approved these changes Mar 28, 2024
@cdillard-NewRelic cdillard-NewRelic merged commit 9fbff5d into develop Apr 10, 2024
6 checks passed
@cdillard-NewRelic cdillard-NewRelic deleted the NR-199912-background-instrumentation branch April 10, 2024 20:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants