TestsTested | ✗ |
LangLanguage | Obj-CObjective C |
License | MIT |
ReleasedLast Release | Jul 2016 |
Maintained by Lukas Spieß, Andreas Linde, Microsoft.
This is the repository of the Mac SDK for Application Insights. Application Insights is a service that allows developers to keep their applications available, performing, and succeeding. The SDK enables you to send telemetry of various kinds (events, traces, page views, etc.) to the Application Insights service where your data can be visualized in the Azure Portal.
You can use the Application Insights for Mac tool to integrate the Application Insights Mac SDK into your existing apps. The SDK runs on devices with with OS X 10.8 or higher. You'll need a subscription to Microsoft Azure. (It's free until you want to send quite a lot of telemetry.)
The SDK runs on devices with OS X 10.8 or higher.
Version 1.0-beta.2 of the Application Insights for Mac comes with two major changes:
Crash Reporting and the API to send handled exceptions have been removed from the SDK. In addition, the Application Insights for Mac SDK is now deprecated.
The reason for this is that HockeyApp is now our major offering for mobile and cross-plattform crash reporting, beta distribution and user feedback. We are focusing all our efforts on enhancing the HockeySDK and adding telemetry features to make HockeyApp the best platform to build awesome apps. We've launched HockeyApp Preseason so you can try all the new bits yourself, including User Metrics.
We apologize for any inconvenience and please feel free to contact us at any time.
NSTimeInterval
parameter with the duration in seconds.See here for the release notes of previous versions.
The SDK runs on devices with OS X 10.8 or higher.
We recommend integration of our binary into your Xcode project to setup Application Insights for your OS X app. For other ways to setup the SDK, see Advanced Setup. Also make sure that you code-sign your app as the SDK is writing data into the keychain. Non-sandboxed or non-code-signed apps will result in keychain dialogs to appear on startup of your app!
You can use the Application Insights for Mac tool to integrate the SDK, which provides you with a step-by-step wizard for this process. If you want to integrate the SDK manually, you can do that by following this steps:
To view your telemetry, you'll need an Application Insights resource in the Microsoft Azure Portal. You can either:
Open your resource and open the Essentials drop-down. Shortly, you'll need to copy the Instrumentation Key.
ApplicationInsights
.From our experience, 3rd-party libraries usually reside inside a subdirectory (let's call our subdirectory Vendor
), so if you don't have your project organized with a subdirectory for libraries, now would be a great start for it. To continue our example, create a folder called "Vendor" inside your project directory and move the unzipped ApplicationInsights
-folder into it.
Vendor
.Project Navigator
is visible (⌘+1)ApplicationInsights.framework
from your window in the Finder
into your project in Xcode and move it to the desired location in the Project Navigator
(e.g. into the group called Vendor
)Create groups for any added folders
and set the checkmark for your target. Then click Finish
.Project Navigator
(⌘+1).Build Phases
.
+
button at the top and choose Add Copy Files
.Frameworks
from the Destination list.ApplicationInsights.framework
from the Project Navigator
to the list in the new Copy Files phase.Info.plist
of your app target and add a new field of type String. Name it MSAIInstrumentationKey
and set your Application Insights instrumentation key as its value.Objective-C
AppDelegate.m
file.Add the following line at the top of the file below your own import
statements:
#import <ApplicationInsightsOSX/ApplicationInsights.h>
application:didFinishLaunchingWithOptions:
Add the following lines to setup and start the Application Insights SDK:
// Setup Application Insights SDK
[[MSAIApplicationInsights sharedInstance] setup];
// Do some additional configuration if needed here
...
[[MSAIApplicationInsights sharedInstance] start];
You can also use the following shortcuts:
[MSAIApplicationInsights setup];
[MSAIApplicationInsights start];
Swift
AppDelegate.swift
file.Add the following line at the top of the file below your own import statements:
import ApplicationInsightsOSX
Search for the method
func applicationDidFinishLaunching(_ aNotification: NSNotification)
Add the following lines to setup and start the Application Insights SDK:
MSAIApplicationInsights.sharedInstance().setup()
MSAIApplicationInsights.sharedInstance().start()
You can also use the following shortcuts:
MSAIApplicationInsights.setup()
MSAIApplicationInsights.start()
Congratulation, now you're all set to use Application Insights! See Basic Usage on how to use Application Insights.
It is also possible to set the instrumentation key of your app in code. This will override the one you might have set in your Info.plist
. To set it in code, MSAIApplicationInsights provides an overloaded constructor:
[MSAIApplicationInsights setupWithInstrumentationKey:@"{YOUR-INSTRUMENTATIONKEY}"];
//Do additional configuration
[MSAIApplicationInsights start];
The following points need to be considered to use the Application Insights SDK with OS X Extensions:
CFBundleShortVersionString
) and build number (CFBundleVersion
) as the main app uses. (This is required only if you are using the same MSAIInstrumentationKey
for your app and extensions).applicationDidFinishLaunching:
equivalent and viewDidLoad
can run multiple times, you need to use a setup like the following example:@interface TodayViewController () <NCWidgetProviding>
@property (nonatomic, assign) BOOL didSetupApplicationInsightsSDK;
@end
@implementation TodayViewController
- (void)viewDidLoad {
[super viewDidLoad];
if (!self.didSetupApplicationInsightsSDK) {
[MSAIApplicationInsights setup];
[MSAIApplicationInsights start];
self.didSetupApplicationInsightsSDK = YES;
}
}
The developer mode is enabled automatically in case the debugger is attached or if the app is running in the simulator. This will decrease the number of telemetry items sent in a batch (5 items) as well as the interval items when telemetry will be sent (3 seconds).
We're all big fans of a clean debugging output without 3rd-party-SDKs messages piling up in the debugging view, right?! That's why Application Insights keeps log messages to a minimum (like critical errors) unless the developer specifically enables debug logging before starting the SDK:
[MSAIApplicationInsights setup]; //setup the SDK
[[MSAIApplicationInsights sharedInstance] setDebugLogEnabled:YES]; //enable debug logging
[MSAIApplicationInsights start]; //start using the SDK
This setting is ignored if the app is running in an app store environment, so the user's console won't be littered with our log messages.
[NOTE] The SDK is optimized to defer everything possible to a later time while making sure e.g. crashes on startup can also be caught and each module executes other code with a delay of some seconds. This ensures that applicationDidFinishLaunching:
will process as fast as possible and the SDK will not block the startup sequence resulting in a possible kill by the watchdog process.
After you have set up the SDK as described above, the MSAITelemetryManager
-instance is the central interface to track events, traces, metrics, or page views.
For an overview of how to use the API and view the results in the Application Insights resource, see API Overview. The examples are in Java, but the principles are the same.
// Send an event with custom properties and measurements data
[MSAITelemetryManager trackEventWithName:@"Hello World event!"
properties:@{@"Test property 1":@"Some value",
@"Test property 2":@"Some other value"}
measurements:@{@"Test measurement 1":@(4.8),
@"Test measurement 2":@(15.16),
@"Test measurement 3":@(23.42)}];
// Send a message
[MSAITelemetryManager trackTraceWithMessage:@"Test message"];
// Manually send page views (duration 200 ms)
[MSAITelemetryManager trackPageView:@"MyViewController"
duration:0.2
properties:@{@"Test measurement 1":@(4.8)}];
// Send custom metrics
[MSAITelemetryManager trackMetricWithName:@"Test metric" value:42.2];
// Send an event with custom properties and measuremnts data
MSAITelemetryManager.trackEventWithName("Hello World event!",
properties:["Test property 1":"Some value",
"Test property 2":"Some other value"],
measurements:["Test measurement 1":4.8,
"Test measurement 2":15.16,
"Test measurement 3":23.42])
// Send a message
MSAITelemetryManager.trackTraceWithMessage("Test message")
// Manually send pageviews (duration 200 ms)
MSAITelemetryManager.trackPageView("MyViewController",
duration:0.2,
properties:["Test measurement 1":4.8])
// Send a message
MSAITelemetryManager.trackMetricWithName("Test metric", value:42.2)
In the Azure portal, open the application resource that you created to get your instrumentation key. You'll see charts showing counts of page views and sessions. To see more:
The SDK also allows for some more advanced usages.
It is also possible to set so-called "common properties" that will then be automatically attached to all telemetry data items.
[MSAITelemetryManager setCommonProperties:@{@"custom info":@"some value"}];
MSAITelemetryManager.setCommonProperties(["custom info":"some value"])
Use the properties to segment and filter metric charts and filter searches.
Automatic collection of lifecycle events is enabled by default. This means that Application Insights automatically manages sessions for you.
By default, the Application Insights for Mac starts a new session when the containing app is restarted (this means a 'cold start', i.e. when the app has not already been in memory prior to being launched) or when it has been in the background for more than 20 seconds.
You can either change this timeframe:
[MSAIApplicationInsights setAppBackgroundTimeBeforeSessionExpires:60];
Turn of automatic session management completely:
[MSAIApplicationInsights setAutoSessionManagementDisabled:YES];
This then requires you to manage sessions manually:
[MSAIApplicationInsights renewSessionWithId:@"4815162342"];
Normally, a random anonymous ID is automatically generated for every user of your app by the SDK. Alternatively you can set your own user ID or other user attributes, which will then be attached to all telemetry events:
[[MSAIApplicationInsights sharedInstance] setUserWithConfigurationBlock:^(MSAIUser *user) {
user.userId = @"your_user_id";
user.accountId = @"[email protected]";
}];
You can also configure a different server endpoint for the SDK if needed using a full URL
[MSAIApplicationInsights setup]; //setup the SDK
[[MSAIApplicationInsights sharedInstance] setServerURL:@"https://YOURDOMAIN/path/subpath"];
[MSAIApplicationInsights start]; //start using the SDK
Our documentation can be found on CocoaDocs.
We're looking forward to your contributions via pull requests.
Development environment
If you have further questions or are running into trouble that cannot be resolved by any of the steps here, feel free to open a GitHub issue here or contact us at [email protected]