Skip to content

Commit 24f3c89

Browse files
Merge pull request #81 from nr-dmmm-25/patch-1
Update README.md
2 parents 5ddbfd5 + cf22c06 commit 24f3c89

1 file changed

Lines changed: 29 additions & 73 deletions

File tree

README.md

Lines changed: 29 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
This plugin allows you to instrument .NET MAUI mobile apps with help of native New Relic Android and iOS Bindings. The New Relic SDKs collect crashes, network traffic, and other information for hybrid apps using native components.
88

9-
109
## Features
1110

1211
* Capture Android and iOS Crashes
@@ -56,26 +55,23 @@ using NewRelic.MAUI.Plugin;
5655
.OnCreate((activity, savedInstanceState) => StartNewRelic()));
5756
#endif
5857
#if IOS
59-
6058
AppLifecycle.AddiOS(iOS => iOS.WillFinishLaunching((_,__) => {
6159
StartNewRelic();
6260
return false;
6361
}));
6462
#endif
6563
});
64+
6665
return builder.Build();
6766
}
6867

6968
private static void StartNewRelic()
7069
{
71-
7270
CrossNewRelic.Current.HandleUncaughtException();
73-
7471
// Set optional agent configuration
7572
// Options are: crashReportingEnabled, loggingEnabled, logLevel, collectorAddress, crashCollectorAddress,analyticsEventEnabled, networkErrorRequestEnabled, networkRequestEnabled, interactionTracingEnabled,webViewInstrumentation, fedRampEnabled,offlineStorageEnabled,newEventSystemEnabled,backgroundReportingEnabled
7673
// AgentStartConfiguration agentConfig = new AgentStartConfiguration(crashReportingEnabled:false);
7774
78-
7975
if (DeviceInfo.Current.Platform == DevicePlatform.Android)
8076
{
8177
CrossNewRelic.Current.Start("<APP-TOKEN-HERE>");
@@ -88,26 +84,40 @@ using NewRelic.MAUI.Plugin;
8884
// CrossNewRelic.Current.Start("<APP-TOKEN-HERE", agentConfig);
8985
}
9086
}
91-
9287
```
9388

94-
9589
## Screen Tracking Events
9690

97-
The .NET MAUI mobile plugin allows you to track navigation events within the [.NET MAUI Shell](https://learn.microsoft.com/en-us/dotnet/maui/fundamentals/shell/navigation). In order to do so, you only need to call:
91+
The .NET MAUI mobile plugin allows you to track navigation events within the [.NET MAUI Shell](https://learn.microsoft.com/en-us/dotnet/maui/fundamentals/shell/navigation). There are two ways to initialize this depending on your app's startup timing.
9892

93+
**Option 1: In the App Constructor**
94+
You can call the tracking method directly in the constructor immediately after setting the `MainPage`.
9995
```C#
10096
public App()
10197
{
10298
InitializeComponent();
103-
10499
MainPage = new AppShell();
105100
CrossNewRelic.Current.TrackShellNavigatedEvents();
101+
}
102+
```
106103

104+
**Option 2: In the OnStart Method (Recommended for timing/NullReferenceException issues)**
105+
If your application shell is not fully initialized during the constructor execution, calling the navigation tracker may result in a `System.NullReferenceException`. To avoid this, move the call into the MAUI `OnStart()` lifecycle method:
106+
```C#
107+
public App()
108+
{
109+
InitializeComponent();
110+
MainPage = new AppShell();
111+
}
112+
113+
protected override void OnStart()
114+
{
115+
base.OnStart();
116+
CrossNewRelic.Current.TrackShellNavigatedEvents();
107117
}
108118
```
109119

110-
It is recommended to call this method along when starting the agent. These events will only be recorded after navigation is complete. You can find this data through the data explorer in `MobileBreadcrumb` under the name `ShellNavigated` or by query:
120+
These events will only be recorded after navigation is complete. You can find this data through the data explorer in `MobileBreadcrumb` under the name `ShellNavigated` or by query:
111121

112122
```sql
113123
SELECT * FROM MobileBreadcrumb WHERE name = 'ShellNavigated' SINCE 24 HOURS AGO
@@ -122,41 +132,31 @@ The breadcrumb will contain three attributes:
122132

123133
See the examples below, and for more detail,
124134
see [New Relic iOS SDK doc](https://docs.newrelic.com/docs/mobile-monitoring/new-relic-mobile-ios/ios-sdk-api)
125-
or [Android SDK](https://docs.newrelic.com/docs/mobile-monitoring/new-relic-mobile-android/android-sdk-api)
126-
.
135+
or [Android SDK](https://docs.newrelic.com/docs/mobile-monitoring/new-relic-mobile-android/android-sdk-api).
127136

128137
### [CrashNow](https://docs.newrelic.com/docs/mobile-monitoring/new-relic-mobile-android/android-sdk-api/crashnow-android-sdk-api/)(string message = "") : void;
129-
130138
> Throws a demo run-time exception on Android/iOS to test New Relic crash reporting.
131-
132139
``` C#
133140
CrossNewRelic.Current.CrashNow();
134141
```
135142

136143
### [CurrentSessionId](https://docs.newrelic.com/docs/mobile-monitoring/new-relic-mobile-android/android-sdk-api/currentsessionid-android-sdk-api/)() : string;
137-
138144
> Returns ID for the current session.
139-
140145
``` C#
141146
string sessionId = CrossNewRelic.Current.CurrentSessionId();
142147
```
143148

144149
### [StartInteraction](https://docs.newrelic.com/docs/mobile-monitoring/new-relic-mobile-android/android-sdk-api/start-interaction)(string interactionName): string;
145-
146150
> Track a method as an interaction.
147151
148-
149152
### [EndInteraction](https://docs.newrelic.com/docs/mobile-monitoring/new-relic-mobile-android/android-sdk-api/end-interaction)(string interactionId): void;
150-
151153
> End an interaction
152154
> (Required). This uses the string ID for the interaction you want to end.
153155
> This string is returned when you use startInteraction().
154-
155156
``` C#
156157
HttpClient myClient = new HttpClient(CrossNewRelic.Current.GetHttpMessageHandler());
157158

158159
string interactionId = CrossNewRelic.Current.StartInteraction("Getting data from service");
159-
160160
var response = await myClient.GetAsync(new Uri("https://jsonplaceholder.typicode.com/todos/1"));
161161
if (response.IsSuccessStatusCode)
162162
{
@@ -165,15 +165,11 @@ or [Android SDK](https://docs.newrelic.com/docs/mobile-monitoring/new-relic-mobi
165165
{
166166
Console.WriteLine("Unsuccessful response code");
167167
}
168-
169168
CrossNewRelic.Current.EndInteraction(interactionId);
170-
171169
```
172170

173171
### [NoticeHttpTransaction](https://docs.newrelic.com/docs/mobile-monitoring/new-relic-mobile-android/android-sdk-api/notice-http-transaction/)(string url, string httpMethod, int statusCode, long startTime,long endTime, long bytesSent, long bytesReceived, string responseBody): void;
174-
175172
> Tracks network requests manually. You can use this method to record HTTP transactions, with an option to also send a response body.
176-
177173
``` C#
178174
CrossNewRelic.Current.NoticeHttpTransaction(
179175
"https://newrelic.com",
@@ -188,9 +184,7 @@ or [Android SDK](https://docs.newrelic.com/docs/mobile-monitoring/new-relic-mobi
188184
```
189185

190186
### [NoticeNetworkFailure](https://docs.newrelic.com/docs/mobile-monitoring/new-relic-mobile-android/android-sdk-api/notice-network-failure/)(string url, string httpMethod, int statusCode, long startTime,long endTime, long bytesSent, long bytesReceived, string responseBody): void;
191-
192187
> Records network failures. If a network request fails, use this method to record details about the failure.
193-
194188
``` C#
195189
CrossNewRelic.Current.NoticeNetworkFailure(
196190
"https://fakewebsite.com",
@@ -202,9 +196,7 @@ or [Android SDK](https://docs.newrelic.com/docs/mobile-monitoring/new-relic-mobi
202196
```
203197

204198
### [RecordBreadcrumb](https://docs.newrelic.com/docs/mobile-monitoring/new-relic-mobile-android/android-sdk-api/recordbreadcrumb)(string name, Dictionary<string, object> attributes): bool;
205-
206199
> This call creates and records a MobileBreadcrumb event, which can be queried with NRQL and in the crash event trail.
207-
208200
``` C#
209201
CrossNewRelic.Current.RecordBreadcrumb("MAUIExampleBreadcrumb", new Dictionary<string, object>()
210202
{
@@ -216,9 +208,7 @@ or [Android SDK](https://docs.newrelic.com/docs/mobile-monitoring/new-relic-mobi
216208
```
217209

218210
### [RecordCustomEvent](https://docs.newrelic.com/docs/mobile-monitoring/new-relic-mobile-android/android-sdk-api/recordcustomevent-android-sdk-api)(string eventType, string eventName, Dictionary<string, object> attributes): bool;
219-
220211
> Creates and records a custom event for use in New Relic Insights.
221-
222212
``` C#
223213
CrossNewRelic.Current.RecordCustomEvent("MAUICustomEvent", "MAUICustomEventCategory", new Dictionary<string, object>()
224214
{
@@ -231,9 +221,7 @@ or [Android SDK](https://docs.newrelic.com/docs/mobile-monitoring/new-relic-mobi
231221

232222
### [RecordMetric](https://docs.newrelic.com/docs/mobile-monitoring/new-relic-mobile-android/android-sdk-api/recordmetric-android-sdk-api/)(string name, string category) : void;
233223
### [RecordMetric](https://docs.newrelic.com/docs/mobile-monitoring/new-relic-mobile-android/android-sdk-api/recordmetric-android-sdk-api/)(string name, string category, double value) : void;
234-
235224
> Record custom metrics (arbitrary numerical data).
236-
237225
``` C#
238226
CrossNewRelic.Current.RecordMetric("Agent start", "Lifecycle");
239227
CrossNewRelic.Current.RecordMetric("Login Auth Metric", "Network", 78.9);
@@ -242,19 +230,15 @@ or [Android SDK](https://docs.newrelic.com/docs/mobile-monitoring/new-relic-mobi
242230
### [SetAttribute](https://docs.newrelic.com/docs/mobile-monitoring/new-relic-mobile-android/android-sdk-api/set-attribute)(string name, string value) : bool;
243231
### [SetAttribute](https://docs.newrelic.com/docs/mobile-monitoring/new-relic-mobile-android/android-sdk-api/set-attribute)(string name, double value) : bool;
244232
### [SetAttribute](https://docs.newrelic.com/docs/mobile-monitoring/new-relic-mobile-android/android-sdk-api/set-attribute)(string name, bool value) : bool;
245-
246233
> Creates a session-level attribute shared by multiple mobile event types. Overwrites its previous value and type each time it is called.
247-
248234
``` C#
249235
CrossNewRelic.Current.SetAttribute("MAUIBoolAttr", false);
250236
CrossNewRelic.Current.SetAttribute("MAUIStrAttr", "Cat");
251237
CrossNewRelic.Current.SetAttribute("MAUINumAttr", 13.5);
252238
```
253239

254240
### [IncrementAttribute](https://docs.newrelic.com/docs/mobile-monitoring/new-relic-mobile-android/android-sdk-api/set-attribute)(string name, float value = 1) : bool;
255-
256241
> Increments the count of an attriubte. Overwrites its previous value and type each time it is called.
257-
258242
``` C#
259243
// Increment by 1
260244
CrossNewRelic.Current.IncrementAttribute("MAUINumAttr");
@@ -263,51 +247,39 @@ or [Android SDK](https://docs.newrelic.com/docs/mobile-monitoring/new-relic-mobi
263247
```
264248

265249
### [RemoveAttribute](https://docs.newrelic.com/docs/mobile-monitoring/new-relic-mobile-android/android-sdk-api/remove-attribute)(string name) : bool;
266-
267250
> Removes an attribute.
268-
269251
``` C#
270252
CrossNewRelic.Current.RemoveAttribute("MAUINumAttr");
271253
```
272254

273255
### [RemoveAllAttributes](https://docs.newrelic.com/docs/mobile-monitoring/new-relic-mobile-android/android-sdk-api/remove-all-attributes)() : bool;
274-
275256
> Removes all attributes from the session.
276-
277257
``` C#
278258
CrossNewRelic.Current.RemoveAllAttributes();
279259
```
280260

281261
### [SetMaxEventBufferTime](https://docs.newrelic.com/docs/mobile-monitoring/new-relic-mobile-android/android-sdk-api/set-max-event-buffer-time)(int maxBufferTimeInSec) void;
282-
283262
> Sets the event harvest cycle length.
284-
285263
``` C#
286264
CrossNewRelic.Current.SetMaxEventBufferTime(200);
287265
```
288-
### [SetMaxEventPoolSize](https://docs.newrelic.com/docs/mobile-monitoring/new-relic-mobile-android/android-sdk-api/set-max-event-pool-size)(int maxPoolSize): void;
289266

267+
### [SetMaxEventPoolSize](https://docs.newrelic.com/docs/mobile-monitoring/new-relic-mobile-android/android-sdk-api/set-max-event-pool-size)(int maxPoolSize): void;
290268
> Sets the maximum size of the event pool.
291-
292269
``` C#
293270
CrossNewRelic.Current.SetMaxEventPoolSize(1500);
294271
```
295272

296273
### [SetUserId](https://docs.newrelic.com/docs/mobile-monitoring/new-relic-mobile-android/android-sdk-api/set-user-id)(string userId): bool;
297-
298274
> Set a custom user identifier value to associate user sessions with analytics events and attributes.
299-
300275
``` C#
301276
CrossNewRelic.Current.SetUserId("User123");
302277
```
303278

304279
### GetHttpMessageHandler() : HttpMessageHandler;
305-
306280
> Provides a HttpMessageHandler to instrument http requests through HttpClient.
307-
308281
``` C#
309282
HttpClient myClient = new HttpClient(CrossNewRelic.Current.GetHttpMessageHandler());
310-
311283
var response = await myClient.GetAsync(new Uri("https://jsonplaceholder.typicode.com/todos/1"));
312284
if (response.IsSuccessStatusCode)
313285
{
@@ -319,45 +291,36 @@ or [Android SDK](https://docs.newrelic.com/docs/mobile-monitoring/new-relic-mobi
319291
```
320292

321293
### AnalyticsEventEnabled(bool enabled) : void
322-
323294
> FOR ANDROID ONLY. Enable or disable collection of event data.
324-
325295
``` C#
326296
CrossNewRelic.Current.AnalyticsEventEnabled(true);
327297
```
328298

329299
### NetworkRequestEnabled(bool enabled) : void
330-
331300
> Enable or disable reporting successful HTTP requests to the MobileRequest event type.
332-
333301
``` C#
334302
CrossNewRelic.Current.NetworkRequestEnabled(true);
335303
```
336304

337305
### NetworkErrorRequestEnabled(bool enabled) : void
338-
339306
> Enable or disable reporting network and HTTP request errors to the MobileRequestError event type.
340-
341307
``` C#
342308
CrossNewRelic.Current.NetworkErrorRequestEnabled(true);
343309
```
344310

345311
### HttpResponseBodyCaptureEnabled(bool enabled) : void
346-
347312
> Enable or disable capture of HTTP response bodies for HTTP error traces, and MobileRequestError events.
348-
349313
``` C#
350314
CrossNewRelic.Current.HttpResponseBodyCaptureEnabled(true);
351315
```
352316

353317
### Shutdown() : void
354-
355318
> Shut down the agent within the current application lifecycle during runtime.
356319
``` C#
357320
CrossNewRelic.Current.Shutdown();
358321
```
359-
### SetMaxOfflineStorageSize(int megabytes) : void
360322

323+
### SetMaxOfflineStorageSize(int megabytes) : void
361324
> Sets the maximum size of total data that can be stored for offline storage.By default, mobile monitoring can collect a maximum of 100 megaBytes of offline storage.
362325
> When a data payload fails to send because the device doesn't have an internet connection, it can be stored in the file system until an internet connection has been made.
363326
> After a typical harvest payload has been successfully sent, all offline data is sent to New Relic and cleared from storage.
@@ -366,7 +329,6 @@ or [Android SDK](https://docs.newrelic.com/docs/mobile-monitoring/new-relic-mobi
366329
```
367330

368331
### LogInfo(String message) : void
369-
370332
> Logs an informational message to the New Relic log.
371333
``` C#
372334
CrossNewRelic.Current.LogInfo("This is an informational message");
@@ -377,6 +339,7 @@ or [Android SDK](https://docs.newrelic.com/docs/mobile-monitoring/new-relic-mobi
377339
``` C#
378340
CrossNewRelic.Current.LogError("This is an error message");
379341
```
342+
380343
### LogVerbose(String message) : void
381344
> Logs a verbose message to the New Relic log.
382345
``` C#
@@ -414,12 +377,12 @@ or [Android SDK](https://docs.newrelic.com/docs/mobile-monitoring/new-relic-mobi
414377
}
415378
);
416379
```
380+
417381
## Error reporting
418382

419383
This plugin provides a handler to record unhandled exceptions to New Relic. It is recommended to initialize the handler prior to starting the agent.
420384

421385
### HandleUncaughtException(bool shouldThrowFormattedException = true) : void;
422-
423386
``` C#
424387
CrossNewRelic.Current.HandleUncaughtException();
425388
if (DeviceInfo.Current.Platform == DevicePlatform.Android)
@@ -432,8 +395,8 @@ This plugin provides a handler to record unhandled exceptions to New Relic. It i
432395
```
433396

434397
This plugin also provides a method to manually record any handled exceptions as well:
435-
### RecordException(System.Exception exception) : void;
436398

399+
### RecordException(System.Exception exception) : void;
437400
``` C#
438401
try {
439402
some_code_that_throws_error();
@@ -442,42 +405,35 @@ This plugin also provides a method to manually record any handled exceptions as
442405
}
443406
```
444407

445-
446408
## Troubleshooting
447409

448410
- ### No Http data appears:
449411
- To instrument http data, make sure to use the HttpMessageHandler in HttpClient.
450412

451-
452413
- ### Crash reports may not be sent when ProGuard rules are not properly configured for New Relic in hybrid Android applications
453414
- Ensure proper ProGuard rules are added to your ProGuard configuration file. See ["Configuring ProGuard Rules"](https://docs.newrelic.com/docs/mobile-monitoring/new-relic-mobile-android/install-configure/configure-proguard-or-dexguard-android-apps/) in setup documentation.
454415

455-
- ### App Crashes When Adding `TrackNavigation` Method in `MauiProgram` or `AppShell` File
456-
- If you experience a crash in this scenario, ensure that the `TrackShellNavigatedEvents` method is called after setting the `MainPage` in the `App` constructor.
416+
- ### App Crashes or Throws NullReferenceException with `TrackShellNavigatedEvents`
417+
- If you experience a `System.NullReferenceException` when calling `CrossNewRelic.Current.TrackShellNavigatedEvents()` in the `App()` constructor, it is likely because the application shell is not fully bootstrapped yet. To resolve this, move the call out of the constructor and into the MAUI `OnStart()` lifecycle method within your `App.xaml.cs` file (see the **Screen Tracking Events** section for code examples).
457418

458419
## Support
459420

460421
New Relic hosts and moderates an online forum where customers, users, maintainers, contributors, and New Relic employees can discuss and collaborate:
461-
462422
[forum.newrelic.com](https://forum.newrelic.com/).
463423

464424
## Contribute
465425

466426
We encourage your contributions to improve [project name]! Keep in mind that when you submit your pull request, you'll need to sign the CLA via the click-through using CLA-Assistant. You only have to sign the CLA one time per project.
467-
468427
If you have any questions, or to execute our corporate CLA (which is required if your contribution is on behalf of a company), drop us an email at opensource@newrelic.com.
469428

470429
**A note about vulnerabilities**
471-
472430
As noted in our [security policy](../../security/policy), New Relic is committed to the privacy and security of our customers and their data. We believe that providing coordinated disclosure by security researchers and engaging with the security community are important means to achieve our security goals.
473-
474431
If you believe you have found a security vulnerability in this project or any of New Relic's products or websites, we welcome and greatly appreciate you reporting it to New Relic through [HackerOne](https://hackerone.com/newrelic).
475-
476432
If you would like to contribute to this project, review [these guidelines](./CONTRIBUTING.md).
477-
478433
To all contributors, we thank you! Without your contribution, this project would not be what it is today.
479434

480435
## License
436+
481437
Except as described below, the `newrelic-maui-plugin` is licensed under the [Apache 2.0](http://apache.org/licenses/LICENSE-2.0.txt) License.
482438

483439
The [New Relic XCFramework agent] (/docs.newrelic.com/docs/mobile-monitoring/new-relic-mobile-ios/get-started/introduction-new-relic-mobile-ios/) is licensed under the [New Relic Agent Software Notice] (/docs.newrelic.com/docs/licenses/license-information/distributed-licenses/new-relic-agent-software-notice/).

0 commit comments

Comments
 (0)