Giter Club home page Giter Club logo

applicationinsights-android's Introduction

Download

Application Insights for Android (1.0-beta.10) DEPRECATED

This SDK is officially deprecated. Please switch to HockeyApp or consider MobileCenter.

You can find more about the transition from Application Insights to HockeyApp here and about how Mobile Center will be the future of HockeyApp here.

Please don't hesitate to get in touch via [email protected] if you have questions.

About

This project provides an Android SDK for Application Insights. Application Insights is a service for monitoring the performance and usage of your apps. This module allows you to send telemetry of various kinds (events, traces, etc.) to the Application Insights service where your data can be visualized in the Azure Portal.

The minimum SDK to use the Application Insights SDK in your app is 9.

Automatic collection of lifecycle-events requires API level 15 and up (Ice Cream Sandwich+).

Breaking Changes!

Version 1.0-beta.9 of the Application Insights for Android SDK came 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 Android 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.

Content

  1. Release Notes
  2. Setup
  3. Advanced Setup
  4. Developer Mode
  5. Basic Usage
  6. Automatic Collection of Lifecycle Events
  7. Additional configuration
  8. Documentation
  9. Contributing
  10. Contact

1. Release Notes

  • Fix for critical bug that prevented telemetry from being sent when developerMode was not enabled

See here for release notes of previous versions or our changelog.

## 2. Setup

This is the recommended way to setup Application Insights for your Android app. For other ways to setup the SDK, see Advanced Setup.

We're assuming you are using Android Studio and gradle to build your Android application.

2.1 Add a compile dependency for the SDK

In your module's build.gradleadd a dependency for Application Insights

dependencies {
    compile 'com.microsoft.azure:applicationinsights-android:1.0-beta.10'
}

2.2 Get the Instrumentation Key of an Application Insights resource

To view your telemetry, you'll need an Application Insights resource in the Microsoft Azure Portal. You can either:

Open your resource, open the Essentials drop-down. You'll need to copy the Instrumentation Key shortly.

2.3 Add permissions

Add the two permissions for INTERNET and ACCESS_NETWORK_STATE to your app's AndroidManifest.xml

<manifest>
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
</manifest>

2.4 Add your instrumentation key to manifest

Add the instrumentation key for your app to your Android Manifest as follows. Replace ${AI_INSTRUMENTATION_KEY} with your instrumentation key. You can leave the variable as is if you want to use your gradle.properties to set it (see Advanced Setup).

<manifest>
    <application>
        <meta-data
            android:name="com.microsoft.applicationinsights.instrumentationKey"
            android:value="${AI_INSTRUMENTATION_KEY}" />
    </application>
</manifest>

2.5 Add code to setup and start Application Insights

Add the following import to your app's root activity

import com.microsoft.applicationinsights.library.ApplicationInsights;

and add

ApplicationInsights.setup(this.getApplicationContext(), this.getApplication());
ApplicationInsights.start();

in the activity's onCreate-callback.

Congratulation, now you're all set to use Application Insights! See Usage on how to use Application Insights.

## 3. Advanced Setup

3.0 Download files manually

We recommend integrating our SDK as described above, if, however, you want to add our SDK to your project manually, press on the button below to download our SDK from Bintray.

Download

3.1 Set the instrumentation key in your gradle.properties

Add the <meta-data>to your Android Manifest as described above but leave the variable ${AI_INSTRUMENTATION_KEY}as is. In your global gradle.properties, add

ai_instrumentation_key=<KEY_PLACEHOLDER>

and replace <KEY_PLACEHOLDER> with your instrumentation key. After that, open your top-level build.gradleand add the mainfest placeholder as follows:

android {
    buildTypes {
        all {
            manifestPlaceholders = [AI_INSTRUMENTATION_KEY: ai_instrumentation_key]
        }
    }
}

3.2 Set instrumentation key in code

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 gradle or manifest file. Setting the instrumentation key programmatically can be done while setting up Application Insights:

ApplicationInsights.setup(this.getApplicationContext(), getApplication(), "<YOUR-INSTRUMENTATION-KEY>");
ApplicationInsights.start();

4. Developer Mode

The developer mode is enabled automatically in case the debugger is attached or if the app is running in the emulator. This will enable the console logging and decrease the number of telemetry items per batch (5 items) as well as the sending interval (3 seconds). If you don't want this behavior, disable the developer mode.

You can explicitly enable/disable the developer mode like this:

//do this after ApplicationInsights.setup(this.getApplicationContext(), this.getApplication())
//and before ApplicationInsights.start()

ApplicationInsights.setDeveloperMode(false);

5. Basic Usage

The TelemetryClient-instance provides various methods to track events, traces, metrics page views, and handled exceptions. To view metrics and event counts on the portal, use Metric Explorer. To inspect events, traces and exceptions, use Search.

	
//somewhere in your app, e.g. in the callback of a button
//or in the onCreate-callback of an activity
	
//Get the instance of TelemetryClient
TelemetryClient client = TelemetryClient.getInstance();

//track an event
client.trackEvent("sample event");

//track a trace
client.trackTrace("sample trace");

//track a metric
client.trackMetric("sample metric", 3);

//track handled exceptions
ArrayList<Object> myList = new ArrayList<Object>();
try{
	Object test = myList.get(2);
}catch(Exception e){
	TelemetryClient.getInstance().trackHandledException(e);
}

Some data types allow for custom properties.

//Get the instance of TelemetryClient
TelemetryClient client = TelemetryClient.getInstance();

//Setup a custom property
HashMap<String, String> properties = new HashMap<String, String>();
properties.put("property1", "my custom property");

//track an event with custom properties
client.trackEvent("sample event", properties);

See the Guide to the API for more about using the API and viewing the results.

6. Automatic collection of life-cycle events (Sessions & Page Views)

This only works in Android SDK version 14 and up (Ice Cream Sandwich+) and is enabled by default. Don't forget to provide an Application instance when setting up Application Insights (otherwise auto collection will be disabled):

ApplicationInsights.setup(this.getApplicationContext(), this.getApplication());

If you want to explicitly Disable automatic collection of life-cycle events (auto session tracking and auto page view tracking), call setAutoCollectionDisabled inbetween setup and start of Application Insights.

ApplicationInsights.setup(this.getApplicationContext());
ApplicationInsights.disableAutoCollection(); //disable the auto-collection
ApplicationInsights.start();

After ApplicationInsights.start() was called, you can enable or disable those features at any point, even if you have disabled it between setup and start of the Application Insights SDK:

// Disable automatic session renewal & tracking
ApplicationInsights.disableAutoSessionManagement();

// Enable automatic page view tracking
ApplicationInsights.enableAutoPageViewTracking();

###Note Automatic collection of pageviews logs the name of the activity class. If you need a more descriptive name for your pageviews, turn of autocollection of pageviews

ApplicationInsights.disableAutoPageViewTracking();

and log pageviews yourself using one of the three methods provided by TelemetryClient.

TelemetryClient.getInstance().trackPageView("Page 1");
 
//Setup a custom property
HashMap<String, String> properties = new HashMap<String, String>();
properties.put("property1", "my custom property");
TelemetryClient.getInstance().trackPageView("Page 2", properties);

HashMap<String, Double> measurements = new HashMap<String, Double>();
measurements.put("measurement1", 2);
TelemetryClient.getInstance().trackPageView("Page 3", properties, measurements);

7. Additional Configuration

To configure Application Insights according to your needs, first, call

ApplicationInsights.setup(this.getApplicationContext(), this.getApplication());

After that you can use Configuration to customize the behavior and values of the SDK.

ApplicationInsightsConfig config = ApplicationInsights.getConfig();
//do the different configurations

After all custom configurations have been made, just start ApplicationInsights:

ApplicationInsights.start();

7.1 Set User Session Time

The default time the users entering the app counts as a new session is 20s. If you want to set it to a different value, do the following:

config.setSessionIntervalMs(30000); //set intercal to 30s (30,000ms)

7.2 Batch Size for a Bundle of Telemetry

Regular telemetry data is send out in batches or after a specified interval.

[NOTE] The developer mode will automatically set the batching interval to 3s and the size of a batch to 5 items.

The default interval until a batch of telemetry is sent to the server is 15s. The following code will change it to 5s:

config.setMaxBatchIntervalMs(5000); //set the interval to e.g. 5s (5,000ms)

To set the maxBatchSize to a different value (default is 100) like this:

config.setMaxBatchCount(20); //set batch size to 20.

7.3 Set Different Endpoint

You can also configure a different server endpoint for the SDK if needed:

config.setEndpointUrl("https://myserver.com/v2/track");

7.4 Override sessionID and user fields

Application Insights manages the ID of a session for you. If you want to override the generated ID with your own, it can be done like this:

ApplicationInsights.renewSession("New session ID");

[NOTE] If you want to manage sessions manually, please disable Automatic Collection of Lifecycle Events.

It's also possible to make a lot of custom settings on the TelemetryContextof application insights, e.g. to set custom value for the authUserId. We're assuming that you know what you do if you customize the user object. Most user's won't need to customize the user object.

To get the TelemetryContext, call:

ApplicationInsights.getTelemetryContext();

The telemetryContext has a lot of setters, e.g. to customize the user object.

ApplicationInsights.getTelemetryContext().setAccountId("someId");

7.5 Other

For all available configarion options, see our Javadoc for Configuration

## 8. Documentation

Our Javadoc can be found at http://microsoft.github.io/ApplicationInsights-Android/

## 9. Contributing

Development environment

9.1 Code of Conduct

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

9.2 Contributor License

You must sign a Contributor License Agreement before submitting your pull request. To complete the Contributor License Agreement (CLA), you will need to submit a request via the form and then electronically sign the CLA when you receive the email containing the link to the document. You need to sign the CLA only once to cover submission to any Microsoft OSS project.

## 10. Contact

If you have further questions or are running into trouble that cannot be resolved by any of the steps here, feel free to contact us at [email protected].

applicationinsights-android's People

Contributors

crystk avatar dnduffy avatar johnmorman avatar lumaxis avatar matthiaswenz avatar mortonfox avatar peterivitz avatar southwood avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

applicationinsights-android's Issues

How to set role name in Android app ?

I can't find a way to identify a specific role name for my Android Application. Below is my personal view of how it should work but it didn't worked for me.

`

    <meta-data
        android:name="com.microsoft.applicationinsights.instrumentationKey"
        android:value="03998c1e-14c5-45e8-a305-2c07f25d5d16" />
    <meta-data
        android:name="com.microsoft.applicationinsights.roleName"
        android:value="AndroidApp" />

... Some code goes here ...

`

Is this a right way to set the role name or is there any other way to do that ?

Memory leak in com.microsoft.commonlogging.channel.Persistence.ctx

I'm using LeakCanary to look for memory leaks, and it looks like there is a static instance of Context being kept in Persistence.

08-06 15:22:09.320 8729-16627/D/LeakCanary﹕ * GC ROOT static com.microsoft.commonlogging.channel.Persistence.ctx

If you have more questions or want the full logs, I am a Microsoft employee. You can email me at [email protected].

1.0-beta.8 crash: Sender.java line 332

I have the following permissions defined in my app:

android.permission.INTERNET
android.permission.ACCESS_NETWORK_STATE
android.permission.WRITE_EXTERNAL_STORAGE
android.permission.ACCESS_COARSE_LOCATION

At the very least, ApplicationInsights should gracefully handle SecurityExceptions (and other exceptions), so that you don't crash our app...

I have over 100 crash reports in Crashlytics, for Sender.java line 332 with this stack trace:

Caused by java.lang.SecurityException: Permission denied (missing INTERNET permission?)
       at java.net.InetAddress.lookupHostByName(InetAddress.java)
       at java.net.InetAddress.getAllByNameImpl(InetAddress.java)
       at java.net.InetAddress.getAllByName(InetAddress.java)
       at com.android.okhttp.internal.Dns$1.getAllByName(Dns.java)
       at com.android.okhttp.internal.http.RouteSelector.resetNextInetSocketAddress(RouteSelector.java)
       at com.android.okhttp.internal.http.RouteSelector.next(RouteSelector.java)
       at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java)
       at com.android.okhttp.internal.http.HttpEngine.sendSocketRequest(HttpEngine.java)
       at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java)
       at com.android.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java)
       at com.android.okhttp.internal.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java)
       at com.android.okhttp.internal.http.HttpURLConnectionImpl.getOutputStream(HttpURLConnectionImpl.java)
       at com.android.okhttp.internal.http.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java)
       at com.microsoft.applicationinsights.library.i.a(Sender.java)
       at com.microsoft.applicationinsights.library.i.a(Sender.java)
       at com.microsoft.applicationinsights.library.i.a(Sender.java)
       at com.microsoft.applicationinsights.library.i.c(Sender.java)
       at com.microsoft.applicationinsights.library.j.a(Sender.java)
       at com.microsoft.applicationinsights.library.j.doInBackground(Sender.java)
       at android.os.AsyncTask$2.call(AsyncTask.java)
       at java.util.concurrent.FutureTask.run(FutureTask.java)
       at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java)
       at java.lang.Thread.run(Thread.java)
Caused by libcore.io.GaiException: getaddrinfo failed: EAI_NODATA (No address associated with hostname)
       at libcore.io.Posix.getaddrinfo(Posix.java)
       at libcore.io.ForwardingOs.getaddrinfo(ForwardingOs.java)
       at java.net.InetAddress.lookupHostByName(InetAddress.java)
       at java.net.InetAddress.getAllByNameImpl(InetAddress.java)
       at java.net.InetAddress.getAllByName(InetAddress.java)
       at com.android.okhttp.internal.Dns$1.getAllByName(Dns.java)
       at com.android.okhttp.internal.http.RouteSelector.resetNextInetSocketAddress(RouteSelector.java)
       at com.android.okhttp.internal.http.RouteSelector.next(RouteSelector.java)
       at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java)
       at com.android.okhttp.internal.http.HttpEngine.sendSocketRequest(HttpEngine.java)
       at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java)
       at com.android.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java)
       at com.android.okhttp.internal.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java)
       at com.android.okhttp.internal.http.HttpURLConnectionImpl.getOutputStream(HttpURLConnectionImpl.java)
       at com.android.okhttp.internal.http.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java)
       at com.microsoft.applicationinsights.library.i.a(Sender.java)
       at com.microsoft.applicationinsights.library.i.a(Sender.java)
       at com.microsoft.applicationinsights.library.i.a(Sender.java)
       at com.microsoft.applicationinsights.library.i.c(Sender.java)
       at com.microsoft.applicationinsights.library.j.a(Sender.java)
       at com.microsoft.applicationinsights.library.j.doInBackground(Sender.java)
       at android.os.AsyncTask$2.call(AsyncTask.java)
       at java.util.concurrent.FutureTask.run(FutureTask.java)
       at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java)
       at java.lang.Thread.run(Thread.java)
Caused by libcore.io.ErrnoException: getaddrinfo failed: EACCES (Permission denied)
       at libcore.io.Posix.getaddrinfo(Posix.java)
       at libcore.io.ForwardingOs.getaddrinfo(ForwardingOs.java)
       at java.net.InetAddress.lookupHostByName(InetAddress.java)
       at java.net.InetAddress.getAllByNameImpl(InetAddress.java)
       at java.net.InetAddress.getAllByName(InetAddress.java)
       at com.android.okhttp.internal.Dns$1.getAllByName(Dns.java)
       at com.android.okhttp.internal.http.RouteSelector.resetNextInetSocketAddress(RouteSelector.java)
       at com.android.okhttp.internal.http.RouteSelector.next(RouteSelector.java)
       at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java)
       at com.android.okhttp.internal.http.HttpEngine.sendSocketRequest(HttpEngine.java)
       at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java)
       at com.android.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java)
       at com.android.okhttp.internal.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java)
       at com.android.okhttp.internal.http.HttpURLConnectionImpl.getOutputStream(HttpURLConnectionImpl.java)
       at com.android.okhttp.internal.http.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java)
       at com.microsoft.applicationinsights.library.i.a(Sender.java)
       at com.microsoft.applicationinsights.library.i.a(Sender.java)
       at com.microsoft.applicationinsights.library.i.a(Sender.java)
       at com.microsoft.applicationinsights.library.i.c(Sender.java)
       at com.microsoft.applicationinsights.library.j.a(Sender.java)
       at com.microsoft.applicationinsights.library.j.doInBackground(Sender.java)
       at android.os.AsyncTask$2.call(AsyncTask.java)
       at java.util.concurrent.FutureTask.run(FutureTask.java)
       at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java)
       at java.lang.Thread.run(Thread.java)

App crashes on Android 2.3.x

Hi,
on any Android 2.3.x-devices my app crashes upon startup with the following stack trace:

3089-3089/net.hockeyapp.client E/AndroidRuntime﹕ FATAL EXCEPTION: main
    java.lang.NoClassDefFoundError: com.microsoft.applicationinsights.library.f
            at com.microsoft.applicationinsights.library.ApplicationInsights.startInstance(ApplicationInsights.java:203)
            at com.microsoft.applicationinsights.library.ApplicationInsights.start(ApplicationInsights.java:169)
            at net.hockeyapp.client.HomeActivity.onCreate(HomeActivity.java:67)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1622)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1674)
            at android.app.ActivityThread.access$1500(ActivityThread.java:117)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:942)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:130)
            at android.app.ActivityThread.main(ActivityThread.java:3694)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:507)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
            at dalvik.system.NativeStart.main(Native Method)

Here's my environment:

  • several Android 2.3.x devices (LG P970, 2.3.4, Genymotion Nexus One Emulator, 2.3.7)
  • MSAI Android SDK 1.0 beta 2 / beta 4
  • integrated via Maven

Please let me know if you need additional information.
Best,
Mat

null-ref exception if instrumentation key is not provided

Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.os.Bundle.getString(java.lang.String)' on a null object reference
            at com.microsoft.commonlogging.channel.TelemetryChannelConfig.readInstrumentationKey(TelemetryChannelConfig.java:113)
            at com.microsoft.commonlogging.channel.TelemetryChannelConfig.<init>(TelemetryChannelConfig.java:82)
            at com.microsoft.applicationinsights.TelemetryClientConfig.<init>(TelemetryClientConfig.java:18)
            at com.microsoft.applicationinsights.TelemetryClient.getInstance(TelemetryClient.java:47)
            at com.example.vseqa1.myapplication3.MainActivity.onCreate(MainActivity.java:21)

setDeveloperMode(false) disables sending of Telemetry

With 1.0-beta.9 a severe bug found it's way into the SDK that prevents any sending of telemetry in case the SDK's developer mode is disabled.

Version 1.0-beta.10 has fixed in #80 and we urge everyone to update to this version of the SDK.

We apologize for any inconvenience this may have caused.

Android app Crash reports are not reflected in Azure application insights dashboard?

Currently am using "com.microsoft.azure:applicationinsights-android:1.0-beta.8" version for unhand-led crash reports. But reports are not reflected in dashboard. I refereed below link for setup/integrating: https://github.com/microsoft/ApplicationInsights-Android#2

Since, SDK in version 1.0-beta.9 on words SDK is officially deprecated. But i am using 1.0-beta.8 version.So it should work for me right. please help me if i am doing wrong at any place.

Is there any other way for getting crash reports for android?
Kindly help me anyone on this issue.
Thank you in Advance !!

Failing tests when including the library

When including application insights in our project, our robolectric tests are failing:

java.lang.RuntimeException: Could not find any resource  from reference ResName{com.myapp:style/Theme_AppCompat_Light_NoActionBar} from style StyleData{name='AppTheme_Base', parent='Theme_AppCompat_Light_NoActionBar'} with theme null
    at org.robolectric.shadows.ShadowAssetManager$StyleResolver.getParent(ShadowAssetManager.java:456)
    at org.robolectric.shadows.ShadowAssetManager$StyleResolver.getAttrValue(ShadowAssetManager.java:394)
    at org.robolectric.shadows.ShadowResources.getOverlayedThemeValue(ShadowResources.java:294)
    at org.robolectric.shadows.ShadowResources.findAttributeValue(ShadowResources.java:283)
    at org.robolectric.shadows.ShadowResources.attrsToTypedArray(ShadowResources.java:186)
...
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:724)

At first glance it looks like an issue related to Robolectric but we're using plenty other aar libraries and we don't have this issue. Removing the dependency to application insights fixes the issue. So I'm wondering if it could be related to the content of the manifest or something...

The only way I found to fix the issue is to put this dirty hack in our gradle.properties:

android.library.reference.1=../app/build/intermediates/exploded-aar/com.microsoft.azure/applicationinsights-android/1.0-beta.3

It looks pretty similar to this issue although support libraries don't complain for me.

1.0-beta.8 crash: Sender.java line 336

This is probably a duplicate of #74.

Caused by java.lang.SecurityException: Permission denied (missing INTERNET permission?)
       at java.net.InetAddress.lookupHostByName(InetAddress.java)
       at java.net.InetAddress.getAllByNameImpl(InetAddress.java)
       at java.net.InetAddress.getAllByName(InetAddress.java)
       at libcore.net.http.HttpConnection.(HttpConnection.java)
       at libcore.net.http.HttpConnection.(HttpConnection.java)
       at libcore.net.http.HttpConnection$Address.connect(HttpConnection.java)
       at libcore.net.http.HttpConnectionPool.get(HttpConnectionPool.java)
       at libcore.net.http.HttpConnection.connect(HttpConnection.java)
       at libcore.net.http.HttpEngine.openSocketConnection(HttpEngine.java)
       at libcore.net.http.HttpsURLConnectionImpl$HttpsEngine.makeSslConnection(HttpsURLConnectionImpl.java)
       at libcore.net.http.HttpsURLConnectionImpl$HttpsEngine.connect(HttpsURLConnectionImpl.java)
       at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java)
       at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java)
       at libcore.net.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java)
       at libcore.net.http.HttpURLConnectionImpl.getOutputStream(HttpURLConnectionImpl.java)
       at libcore.net.http.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java)
       at com.microsoft.applicationinsights.library.i.a(Sender.java)
       at com.microsoft.applicationinsights.library.i.a(Sender.java)
       at com.microsoft.applicationinsights.library.i.a(Sender.java)
       at com.microsoft.applicationinsights.library.i.c(Sender.java)
       at com.microsoft.applicationinsights.library.j.a(Sender.java)
       at com.microsoft.applicationinsights.library.j.doInBackground(Sender.java)
       at android.os.AsyncTask$2.call(AsyncTask.java)
       at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java)
       at java.util.concurrent.FutureTask.run(FutureTask.java)
       at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java)
       at java.lang.Thread.run(Thread.java)
Caused by libcore.io.GaiException: getaddrinfo failed: EAI_NODATA (No address associated with hostname)
       at libcore.io.Posix.getaddrinfo(Posix.java)
       at libcore.io.ForwardingOs.getaddrinfo(ForwardingOs.java)
       at java.net.InetAddress.lookupHostByName(InetAddress.java)
       at java.net.InetAddress.getAllByNameImpl(InetAddress.java)
       at java.net.InetAddress.getAllByName(InetAddress.java)
       at libcore.net.http.HttpConnection.(HttpConnection.java)
       at libcore.net.http.HttpConnection.(HttpConnection.java)
       at libcore.net.http.HttpConnection$Address.connect(HttpConnection.java)
       at libcore.net.http.HttpConnectionPool.get(HttpConnectionPool.java)
       at libcore.net.http.HttpConnection.connect(HttpConnection.java)
       at libcore.net.http.HttpEngine.openSocketConnection(HttpEngine.java)
       at libcore.net.http.HttpsURLConnectionImpl$HttpsEngine.makeSslConnection(HttpsURLConnectionImpl.java)
       at libcore.net.http.HttpsURLConnectionImpl$HttpsEngine.connect(HttpsURLConnectionImpl.java)
       at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java)
       at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java)
       at libcore.net.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java)
       at libcore.net.http.HttpURLConnectionImpl.getOutputStream(HttpURLConnectionImpl.java)
       at libcore.net.http.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java)
       at com.microsoft.applicationinsights.library.i.a(Sender.java)
       at com.microsoft.applicationinsights.library.i.a(Sender.java)
       at com.microsoft.applicationinsights.library.i.a(Sender.java)
       at com.microsoft.applicationinsights.library.i.c(Sender.java)
       at com.microsoft.applicationinsights.library.j.a(Sender.java)
       at com.microsoft.applicationinsights.library.j.doInBackground(Sender.java)
       at android.os.AsyncTask$2.call(AsyncTask.java)
       at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java)
       at java.util.concurrent.FutureTask.run(FutureTask.java)
       at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java)
       at java.lang.Thread.run(Thread.java)
Caused by libcore.io.ErrnoException: getaddrinfo failed: EACCES (Permission denied)
       at libcore.io.Posix.getaddrinfo(Posix.java)
       at libcore.io.ForwardingOs.getaddrinfo(ForwardingOs.java)
       at java.net.InetAddress.lookupHostByName(InetAddress.java)
       at java.net.InetAddress.getAllByNameImpl(InetAddress.java)
       at java.net.InetAddress.getAllByName(InetAddress.java)
       at libcore.net.http.HttpConnection.(HttpConnection.java)
       at libcore.net.http.HttpConnection.(HttpConnection.java)
       at libcore.net.http.HttpConnection$Address.connect(HttpConnection.java)
       at libcore.net.http.HttpConnectionPool.get(HttpConnectionPool.java)
       at libcore.net.http.HttpConnection.connect(HttpConnection.java)
       at libcore.net.http.HttpEngine.openSocketConnection(HttpEngine.java)
       at libcore.net.http.HttpsURLConnectionImpl$HttpsEngine.makeSslConnection(HttpsURLConnectionImpl.java)
       at libcore.net.http.HttpsURLConnectionImpl$HttpsEngine.connect(HttpsURLConnectionImpl.java)
       at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java)
       at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java)
       at libcore.net.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java)
       at libcore.net.http.HttpURLConnectionImpl.getOutputStream(HttpURLConnectionImpl.java)
       at libcore.net.http.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java)
       at com.microsoft.applicationinsights.library.i.a(Sender.java)
       at com.microsoft.applicationinsights.library.i.a(Sender.java)
       at com.microsoft.applicationinsights.library.i.a(Sender.java)
       at com.microsoft.applicationinsights.library.i.c(Sender.java)
       at com.microsoft.applicationinsights.library.j.a(Sender.java)
       at com.microsoft.applicationinsights.library.j.doInBackground(Sender.java)
       at android.os.AsyncTask$2.call(AsyncTask.java)
       at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java)
       at java.util.concurrent.FutureTask.run(FutureTask.java)
       at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java)
       at java.lang.Thread.run(Thread.java)

internal SDK version is not set

We should be emitting this to the context tags:
https://github.com/Microsoft/AppInsights-Android/blob/feature/channel-refactoring/applicationinsights-android/src/main/java/com/microsoft/applicationinsights/internal/TelemetryContext.java#L345-L353

currently it's not set in the payload:

[{
    "ver": 1,
    "name": "Microsoft.ApplicationInsights.Crash",
    "time": "2015-04-11T00:22:40.291Z",
    "sampleRate": 100.0,
    "iKey": "1743b6cf-8366-4a85-91c9-8ddfdeaefc3e",
    "deviceId": "CD4AB54D1385C789980EFA8C2F881F7EFF1049BF1DBD6F3628541CC3475175B0",
    "os": "Android",
    "osVer": "5.0",
    "appId": "com.microsoft.applicationinsights.sampleapp",
    "appVer": "com.microsoft.applicationinsights.sampleapp (1)",
    "userId": "7991fd27-8257-48f9-8dd6-07a3d47d3cb6",
    "tags": {
        "ai.device.id": "CD4AB54D1385C789980EFA8C2F881F7EFF1049BF1DBD6F3628541CC3475175B0",
        "ai.device.locale": "en_US",
        "ai.device.model": "[Emulator]Android SDK built for x86",
        "ai.device.network": "Mobile",
        "ai.device.oemName": "unknown",
        "ai.device.os": "Android",
        "ai.device.osVersion": "5.0",
        "ai.device.type": "Phone",
        "ai.session.id": "eda04a63-5be7-4a95-8f09-a5a403de1fae",
        "ai.user.accountAcquisitionDate": "2015-04-10T21:42:30.380Z",
        "ai.user.id": "7991fd27-8257-48f9-8dd6-07a3d47d3cb6"
    },
    "data": {
        "baseType": "Microsoft.ApplicationInsights.CrashData",
        "baseData": {
            "ver": 2,
            "headers": {
                "id": "56303f84-91c5-4e54-bba7-4d25016350fd",
                "applicationPath": "com.microsoft.applicationinsights.sampleapp",
                "exceptionType": "java.lang.RuntimeException",
                "exceptionReason": "oh no!"
            },
            "threads": [{
                "id": 0,
                "frames": [{
                    "address": "",
                    "symbol": "com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)"
                }, {
                    "address": "",
                    "symbol": "com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)"
                }, {
                    "address": "",
                    "symbol": "java.lang.reflect.Method.invoke(Method.java:372)"
                }, {
                    "address": "",
                    "symbol": "java.lang.reflect.Method.invoke(Native Method)"
                }, {
                    "address": "",
                    "symbol": "android.app.ActivityThread.main(ActivityThread.java:5221)"
                }, {
                    "address": "",
                    "symbol": "android.os.Looper.loop(Looper.java:135)"
                }, {
                    "address": "",
                    "symbol": "android.os.Handler.dispatchMessage(Handler.java:95)"
                }, {
                    "address": "",
                    "symbol": "android.os.Handler.handleCallback(Handler.java:739)"
                }, {
                    "address": "",
                    "symbol": "android.widget.AbsListView$3.run(AbsListView.java:3833)"
                }, {
                    "address": "",
                    "symbol": "android.widget.AbsListView$PerformClick.run(AbsListView.java:3044)"
                }, {
                    "address": "",
                    "symbol": "android.widget.AbsListView.performItemClick(AbsListView.java:1143)"
                }, {
                    "address": "",
                    "symbol": "android.widget.AdapterView.performItemClick(AdapterView.java:300)"
                }, {
                    "address": "",
                    "symbol": "android.support.v4.app.ListFragment$2.onItemClick(ListFragment.java:58)"
                }, {
                    "address": "",
                    "symbol": "com.microsoft.applicationinsights.appsample.ItemListFragment.onListItemClick(ItemListFragment.java:138)"
                }, {
                    "address": "",
                    "symbol": "com.microsoft.applicationinsights.appsample.ItemListFragment.crashMe1(ItemListFragment.java:158)"
                }, {
                    "address": "",
                    "symbol": "com.microsoft.applicationinsights.appsample.ItemListFragment.crashMe2(ItemListFragment.java:162)"
                }, {
                    "address": "",
                    "symbol": "com.microsoft.applicationinsights.appsample.ItemListFragment.crashMe3(ItemListFragment.java:166)"
                }]
            }]
        }
    }
}]

Multiple instances of the same event being reported

I'm using com.microsoft.azure:applicationinsights-android:1.0-beta.10 in my Android app, and I've noticed that, in some occasions, it is reporting the same event multiple times; sometimes it is working fine, but some others it reports 2, 3 or 4 times the same event for the same user, and almost with an identical timestamp.

I haven't been able to find the root cause, or even how to reproduce it.

Thanks,
Jorge

trackHandledException logs exception as a "Crash" in Application Insights Dashboard

Have a few places where we log exceptions that aren't a crash but malformed data or something else that is recoverable.

TelemetryClient.trackHandledException(exception)

Logs this just like an uncaught exception in the portal even though the name is "Handled Exception."

I guess this will just have to be logged as a normal event?

SDK Sample App crashes on Android 2.3.x

After testing a fix to #46 in a feature branch, this exception occurs on all Android 2.3.x devices for me:

06-08 17:37:08.046  13194-13194/com.microsoft.applicationinsights.sampleapp E/AndroidRuntime﹕ FATAL EXCEPTION: main
    java.lang.NullPointerException
            at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:355)
            at android.widget.ArrayAdapter.getView(ArrayAdapter.java:323)
            at android.widget.AbsListView.obtainView(AbsListView.java:2096)
            at android.widget.ListView.makeAndAddView(ListView.java:1752)
            at android.widget.ListView.fillDown(ListView.java:677)
            at android.widget.ListView.fillFromTop(ListView.java:734)
            at android.widget.ListView.layoutChildren(ListView.java:1605)
            at android.widget.AbsListView.onLayout(AbsListView.java:1925)
            at android.view.View.layout(View.java:7446)
            at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
            at android.view.View.layout(View.java:7446)
            at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
            at android.view.View.layout(View.java:7446)
            at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
            at android.view.View.layout(View.java:7446)
            at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
            at android.view.View.layout(View.java:7446)
            at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
            at android.view.View.layout(View.java:7446)
            at android.view.ViewRoot.performTraversals(ViewRoot.java:1140)
            at android.view.ViewRoot.handleMessage(ViewRoot.java:1859)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:130)
            at android.app.ActivityThread.main(ActivityThread.java:3694)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:507)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
            at dalvik.system.NativeStart.main(Native Method)

Seems related to the setup of the list adapter in ItemListFragment.java.

trackHandledException not defined - 1.0-beta.9

Hi, this is my first time using ApplicationInsights in Android, but I can't track exceptions.
I can see trackEvent, trackTrace... but not trackHandledException.
I looked also at the source code and didn't find that method. Is that new in this version or what?
I'm using version 1.0-beta.9 and Android Studio
Thanks..

NullPointerException when calling trackMetric with a null properties map

Steps:

  1. Call TrackMetric with a null properties map

Result:
In the logCat output you will see the following exception that is eaten by the sdk, which is probably ok given that I don't want properties checked anyway and it doesn't cause my app to crash, it is just noise.

Expected:
No exception.

The code here should add a check if properties is null before call HashMap new on it:
protected TrackDataOperation(TrackDataOperation$DataType type, String metricName, double metric, Map<String, String> properties) {
this.a = type;
this.h = metric;

    try {
        this.b = (String)this.a(metricName);
        this.c = new HashMap(properties);
    } catch (Exception var7) {
        var7.printStackTrace();
    }
}

Here's the useful part of the stack:
01-25 10:06:54.790 2387-2387/com.hockeyapp.hockeydevapp W/System.err: java.lang.NullPointerException: Attempt to invoke interface method 'int java.util.Map.size()' on a null object reference
01-25 10:06:54.793 2387-2387/com.hockeyapp.hockeydevapp W/System.err: at java.util.HashMap.(HashMap.java:195)
01-25 10:06:54.793 2387-2387/com.hockeyapp.hockeydevapp W/System.err: at com.microsoft.applicationinsights.library.TrackDataOperation.(TrackDataOperation.java:81)
01-25 10:06:54.793 2387-2387/com.hockeyapp.hockeydevapp W/System.err: at com.microsoft.applicationinsights.library.TelemetryClient.trackMetric(TelemetryClient.java:242)
01-25 10:06:54.793 2387-2387/com.hockeyapp.hockeydevapp W/System.err: at com.microsoft.applicationinsights.library.TelemetryClient.trackMetric(TelemetryClient.java:229)
01-25 10:06:54.793 2387-2387/com.hockeyapp.hockeydevapp W/System.err: at com.hockeyapp.hockeydevapp.helper.TelemetryWrapper.trackMetric(TelemetryWrapper.java:26)

error running tests on samsung galaxy S4

Error in testOnStartEventMultipleActivities:
java.lang.IllegalStateException: System services not available to Activities before onCreate()
at android.app.Activity.getSystemService(Activity.java:4738)
at android.app.Activity.getMultiWindowStyle(Activity.java:4563)
at android.app.Activity.getMultiWindowStyle(Activity.java:4568)
at android.app.Activity.onPause(Activity.java:1366)
at android.app.Activity.performPause(Activity.java:5555)
at android.app.Instrumentation.callActivityOnPause(Instrumentation.java:1239)
at com.microsoft.applicationinsights.LifeCycleTrackingTest.testOnStartEventMultipleActivities(LifeCycleTrackingTest.java:136)
at java.lang.reflect.Method.invokeNative(Native Method)
at android.test.InstrumentationTestCase.runMethod(InstrumentationTestCase.java:214)
at android.test.InstrumentationTestCase.runTest(InstrumentationTestCase.java:199)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:191)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:176)
at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:554)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1729)

context and application leaked by ApplicationInsights

Hi!

I'm getting started with ApplicationInsights, interesting project. By looking at the source code I can see one problem with the way you deal with Android resources.

First, ApplicationInsights.setup() methods take a context. The reference to this context is then kept statically by the field INSTANCE. That's pretty bad and can lead to emory leaks. The documentation advises to use an Activity context, which is even worse than the Application context. See this post for more details about the problem. One solution would be to keep a weak reference to this context or add a setContext() to clear it up when the activity is released.
I noticed this context is only used by Telemetry and Persistence, why not adding this context when enabling these services? ApplicationInsights.setTelemetryEnabled(context).

Second, there's another memory leak problem with application. Moreover, the design could be improved on that side. It doesn't look obvious to me that passing an application to the setup() method initializes the LifeCycleTracking. In fact, the comment says @param application the application needed for auto collecting telemetry data but it's not used by the telemetry. Only by the LifeCycleTracking https://github.com/Microsoft/ApplicationInsights-Android/blob/master/applicationinsights-android/src/main/java/com/microsoft/applicationinsights/library/ApplicationInsights.java#L193-L199

1.0-beta.8: Millions of unwanted Trace events causing monthly quota to be reached prematurely

We only post PageView and custom Event transactions to the TelemetryClient. That's it.

Here's our configuration bootstrap:

ApplicationInsights.setup(context, application);
ApplicationInsights.setDeveloperMode(!BuildConfigUtil.isRelease());
ApplicationInsights.disableAutoCollection();
ApplicationInsights.disableAutoPageViewTracking();

In our September release, we added this line of code to our bootstrap code:

ApplicationInsights.enableAutoSessionManagement();

When the September release went live, the number of Trace events in our dashboard went into the millions, causing our monthly quota to be reached only a few days into each month. Notably, in previous releases, we still saw Trace events which we are NOT explicitly tracking.

We are currently experimenting with Application Insights for several enterprise apps; and this is a very serious issue which will likely determine whether or not we continue to evaluate ApplicationInsights.

At the very least, can you add a method like this?

ApplicationInsights.disableTraceTracking();

Such a method implementation should be trivial, and the outcome should be that when this method is invoked, zero Trace events should be recorded.

For now, we will be adding these lines to our configuration:

//ApplicationInsights.enableAutoSessionManagement();
ApplicationInsights.disableAutoSessionManagement();
ApplicationInsights.setExceptionTrackingDisabled(true);

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.