Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Commit

Permalink
Remove API for managed Exception
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin Reimold committed Feb 2, 2016
1 parent c483abf commit f7f024e
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 106 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import android.support.v4.app.FragmentActivity;

import com.microsoft.applicationinsights.library.ApplicationInsights;
import com.microsoft.applicationinsights.library.TelemetryClient;
import com.microsoft.applicationinsights.library.config.Configuration;

import java.util.HashMap;
Expand Down Expand Up @@ -57,7 +58,7 @@ protected void onCreate(Bundle savedInstanceState) {
Configuration config = ApplicationInsights.getConfiguration();
//config.setSessionIntervalMs(30000);
//config.setEndpointUrl("https://myserver.com/v2/track");
config.setMaxBatchCount(45);
config.setMaxBatchCount(5);
//ApplicationInsights.setUserId("New user ID");
//ApplicationInsights.renewSession("New session ID");

Expand All @@ -67,6 +68,7 @@ protected void onCreate(Bundle savedInstanceState) {
properties.put("Hometown", "Karlsruhe");
ApplicationInsights.setCommonProperties(properties);
ApplicationInsights.start();
TelemetryClient.getInstance().trackMetric("blub", 1.0, null);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
import com.microsoft.applicationinsights.library.ApplicationInsights;
import com.microsoft.applicationinsights.library.TelemetryClient;

import java.util.ArrayList;

/**
* A list fragment representing a list of Items. This fragment
* also supports tablet devices by allowing list items to be given an
Expand Down Expand Up @@ -131,24 +129,12 @@ public void onListItemClick(ListView listView, View view, int position, long id)
ApplicationInsights.disableAutoSessionManagement();
break;
case 4:

ArrayList<Object> myList = new ArrayList<Object>();
try {
Object test = myList.get(2);
} catch (Exception e) {
TelemetryClient.getInstance().trackHandledException(e);
}
break;
case 5:
crashMe1();
break;
case 6:
ApplicationInsights.sendPendingData();
break;
case 7:
case 5:
TelemetryClient.getInstance().trackEvent("My Event");
break;
case 8:
case 6:
TelemetryClient.getInstance().trackMetric("SomeMetric", 2.0);
break;
default:
Expand All @@ -160,17 +146,6 @@ public void onListItemClick(ListView listView, View view, int position, long id)
mCallbacks.onItemSelected(DummyContent.ITEMS.get(position).id);
}

private void crashMe1() {
crashMe2();
}

private void crashMe2() {
crashMe3();
}

private void crashMe3() {
throw new RuntimeException("oh no!");
}

@Override
public void onSaveInstanceState(Bundle outState) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,10 @@ public class DummyContent {
addItem(new DummyItem("2", "Disable page view tracking"));
addItem(new DummyItem("3", "Enable session management"));
addItem(new DummyItem("4", "Disable session management"));
addItem(new DummyItem("5", "Send handled exception"));
addItem(new DummyItem("6", "Crash the App!"));
addItem(new DummyItem("7", "Trigger Synchronize"));
addItem(new DummyItem("8", "Track event"));
addItem(new DummyItem("9", "Send Metric"));
addItem(new DummyItem("5", "Send Managed Exception"));
addItem(new DummyItem("6", "Trigger Synchronize"));
addItem(new DummyItem("7", "Track event"));
addItem(new DummyItem("8", "Send Metric"));
}

private static void addItem(DummyItem item) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,6 @@ public void trackMetric(String name, double value) {
}
}

@Override
public void trackHandledException(Throwable handledException, Map<String, String> properties) {
if(this.mockTrackMethod) {
messages.add(EnvelopeFactory.getInstance().createExceptionData(handledException, properties, null));
}else{
super.trackHandledException(handledException, properties);
}
}

@Override
public void trackNewSession() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@

public class TelemetryClientTestE2E extends ApplicationTestCase<MockApplication> {

private static int batchCount = 10;
private LinkedHashMap<String, String> properties;
private LinkedHashMap<String, Double> measurements;
public TelemetryClientTestE2E() {
super(MockApplication.class);
}

private LinkedHashMap<String, String> properties;
private LinkedHashMap<String, Double> measurements;
private static int batchCount = 10;

public void setUp() throws Exception {
super.setUp();

Expand Down Expand Up @@ -73,19 +72,11 @@ public void testTrackPageView() throws Exception {
}

public void testTrackAllRequests() throws Exception {
Exception exception;
try {
throw new Exception();
} catch (Exception e) {
exception = e;
}

((Channel)Channel.getInstance()).queue.config.setMaxBatchCount(10);
((Channel) Channel.getInstance()).queue.config.setMaxBatchCount(10);
for (int i = 0; i < batchCount; i++) {
TelemetryClient.getInstance().trackEvent("android event");
TelemetryClient.getInstance().trackTrace("android trace");
TelemetryClient.getInstance().trackMetric("android metric", 0.0);
TelemetryClient.getInstance().trackHandledException(exception);
TelemetryClient.getInstance().trackPageView("android page");
Thread.sleep(10);
}
Expand All @@ -108,8 +99,8 @@ public void validate(int count) {
Log.w("BACKEND_ERROR", "response count is lower than enqueue count");
}

for(int i = 0; i < count; i++) {
if(i < sender.responseCodes.size()) {
for (int i = 0; i < count; i++) {
if (i < sender.responseCodes.size()) {
Assert.assertTrue("response is 206, some telemetry was rejected",
sender.responseCodes.get(i) == 200);
}
Expand All @@ -119,5 +110,5 @@ public void validate(int count) {
} catch (InterruptedException e) {
Assert.fail(e.toString());
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -260,55 +260,6 @@ public void trackMetric(String name, double value, Map<String, String> propertie
}
}

/**
* {@code properties} defaults to {@code null}.
* {@code measurements} defaults to {@code null}.
*
* @see TelemetryClient#trackHandledException(Throwable, Map)
*/
public void trackHandledException(Throwable handledException) {
this.trackHandledException(handledException, null, null);
}

/**
* Sends information about an handledException to Application Insights.
*
* @param handledException The handledException to track.
* @param properties Custom properties associated with the event. Note: values set here will
* supersede values set in {@link ApplicationInsights#setCommonProperties}.
*/
public void trackHandledException(Throwable handledException, Map<String, String> properties) {
trackHandledException(handledException, properties, null);
}

/**
* Sends information about an handledException to Application Insights.
*
* @param handledException The handledException to track.
* @param properties Custom properties associated with the event. Note: values set here will
* supersede values set in {@link ApplicationInsights#setCommonProperties}.
*/
public void trackHandledException(Throwable handledException, Map<String, String> properties, Map<String, Double> measurements) {
if (isTelemetryEnabled()) {
this.threadPoolExecutor.execute(new TrackDataOperation(TrackDataOperation.DataType.HANDLED_EXCEPTION,
handledException, properties, measurements));
}
}

/**
* Sends unhandled Exception to Application Insights. This method should be called from your
* Xamarin code to send the C# stacktrace to ApplicationInsights
*
* @param type the exception type
* @param message the exception message
* @param stacktrace the stacktrace for the exception
* @param handled a flag which determines if the exception was handled or not
*/
public void trackManagedException(String type, String message, String stacktrace, boolean handled) {
new TrackDataOperation(TrackDataOperation.DataType.MANAGED_EXCEPTION, type, message, stacktrace, handled).run();

}

/**
* {@code properties} defaults to {@code null}.
* {@code measurements} defaults to {@code null}.
Expand Down

0 comments on commit f7f024e

Please sign in to comment.