New Relic Agent For Xamarin
The Agent to Instrument New Relic in Xamarin is available on a NuGet Package called NewRelicAgentForXamarin.
MIT
To start Install the NuGet Package via Manage Nuget Packages under the Tools menu for Windows and under the Project menu on Mac.
Open AppDelegate.cs
and add the following to the top of the file:
using NewRelicXamarin;
Next, inside the class AppDelegate you need to add the following to the FinishedLaunching
function:
NRLogger.SetLogLevels((uint)NRLogLevels.All);
NewRelicXamarin.NewRelic.StartWithApplicationToken("new_relic_license_key");
Make sure you replace the new_relic_license_key
with your own. You can find your own license key by creating a Mobile app within the New Relic UI. Go to Mobile
> Add a new app
> Choose your platform > Give your App a name > Your license key is now visible lower down the page.
In the MainActivity class or equivalent
var config = new NewRelicXamarin.Android.AgentConfiguration();
config.ApplicationToken = "new_relic_license_key";
NewRelicXamarin.Android.AndroidAgentImpl.Init(this, config);
NewRelicXamarin.Android.Agent.Start();
Make sure you replace the new_relic_license_key
with your own.
For sending Custom events we use the method RecordCustomEvent
included in the package, sending as parameters an event name and optionally we can send custom attributes:
NewRelicXamarin.NewRelic.RecordCustomEvent(eventType, attributes);
NewRelicXamarin.Android.NewRelic.RecordCustomEvent(eventType, eventName, attributes);
On iOS the attributes parameter is nullable.
NewRelicXamarin.NewRelic.RecordCustomEvent(breadcrumbName, attributes);
On Android the second parameter is optional:
NewRelicXamarin.Android.NewRelic.RecordBreadcrumb(breadcrumbName, attributes);
Go to one.newrelic.com > Mobile > (select a mobile app) > Crash analysis.
On the lower right side of the Crash analysis page, select a crash type.
On the Crash details page, beside the stack trace, select Event trail.
Study the events leading up to a crash type for clues to the reasons for the crash.
To visualize the symbolicated stack trace on iOS it is required to upload the dSYM file.