### Manual Error and Resource Tracking Setup Source: https://github.com/newrelic/newrelic-flutter-agent/blob/main/README.md This alternative setup manually initializes the agent and sets up error handling using `runZonedGuarded`. Ensure `WidgetsFlutterBinding.ensureInitialized()` is called before starting the agent if not using `NewrelicMobile.instance.start`. ```dart if (Platform.isAndroid) { appToken = AppConfig.androidToken; } else if (Platform.isIOS) { appToken = AppConfig.iOSToken; } Config config = Config( accessToken: appToken, analyticsEventEnabled: true, networkErrorRequestEnabled: true, networkRequestEnabled: true, crashReportingEnabled: true, interactionTracingEnabled: true, httpResponseBodyCaptureEnabled: true, loggingEnabled: true, webViewInstrumentation: true, printStatementAsEventsEnabled: true, httpInstrumentationEnabled:true, distributedTracingEnabled: true); runZonedGuarded(() async { WidgetsFlutterBinding.ensureInitialized(); FlutterError.onError = NewrelicMobile.onError; await NewrelicMobile.instance.startAgent(config); runApp(MyApp()); }, (Object error, StackTrace stackTrace) { NewrelicMobile.instance.recordError(error, stackTrace); }); ``` -------------------------------- ### crashNow Source: https://github.com/newrelic/newrelic-flutter-agent/blob/main/README.md Throws a demo run-time exception to test New Relic crash reporting. This is useful for verifying that your crash reporting setup is functioning correctly. ```APIDOC ## crashNow({String name}) ### Description Throws a demo run-time exception to test New Relic crash reporting. This is useful for verifying that your crash reporting setup is functioning correctly. ### Method void ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body * **name** (String) - Optional - A name for the crash. ### Request Example ```dart NewrelicMobile.instance.crashNow(name: "This is a crash"); NewrelicMobile.instance.crashNow(); ``` ### Response #### Success Response (void) This method does not return a value. #### Response Example N/A ``` -------------------------------- ### Start New Relic Mobile Agent in Flutter App Source: https://github.com/newrelic/newrelic-flutter-agent/blob/main/WEB_SUPPORT.md This code initializes the New Relic Mobile agent with a configuration. On native platforms, it enables full monitoring. On web platforms, it compiles successfully and runs the app without monitoring. ```dart import 'package:newrelic_mobile/newrelic_mobile.dart'; import 'package:newrelic_mobile/config.dart'; void main() { Config config = Config( accessToken: 'YOUR_TOKEN', // ... other config options ); NewrelicMobile.instance.start(config, () { runApp(MyApp()); }); } ``` -------------------------------- ### Start and End Interaction Source: https://github.com/newrelic/newrelic-flutter-agent/blob/main/README.md Track a method as an interaction and end it using its ID. Ensure to wrap network requests in a try-catch block. ```dart var id = await NewrelicMobile.instance.startInteraction("Getting Data from Service"); try { var dio = Dio(); var response = await dio.get( 'https://reqres.in/api/users?delay=15'); print(response); NewrelicMobile.instance.endInteraction(id); Timeline.finishSync(); } catch (e) { print(e); } ``` -------------------------------- ### Add HTTP Headers for Tracking Source: https://github.com/newrelic/newrelic-flutter-agent/blob/main/README.md Adds specified header field strings to a list that gets recorded as attributes with networking request events. ```dart NewrelicMobile.instance.addHTTPHeadersTrackingFor(["Car","Music"]); ``` -------------------------------- ### endInteraction Source: https://github.com/newrelic/newrelic-flutter-agent/blob/main/README.md Ends a previously started interaction using its unique string ID. This is crucial for accurately measuring the duration of tracked operations. ```APIDOC ## endInteraction(String interactionId) ### Description Ends a previously started interaction using its unique string ID. This is crucial for accurately measuring the duration of tracked operations. ### Method `endInteraction` ### Parameters #### Path Parameters - **interactionId** (String) - Required - The ID of the interaction to end, obtained from `startInteraction`. ``` -------------------------------- ### Get Current Session ID Source: https://github.com/newrelic/newrelic-flutter-agent/blob/main/README.md Retrieves the current session ID for consolidating monitoring data. ```dart var sessionId = await NewrelicMobile.instance.currentSessionId(); ``` -------------------------------- ### Initialize New Relic Flutter Agent with Configuration Source: https://github.com/newrelic/newrelic-flutter-agent/blob/main/README.md This snippet shows the primary method for launching the New Relic agent with a comprehensive set of configuration options. Ensure you replace placeholder app tokens with your actual platform-specific tokens. ```dart import 'package:newrelic_mobile/newrelic_mobile.dart'; var appToken = ""; if (Platform.isAndroid) { appToken = ""; } else if (Platform.isIOS) { appToken = ""; } Config config = Config(accessToken: appToken, //Android Specific // Optional:Enable or disable collection of event data. analyticsEventEnabled: true, // Optional:Enable or disable reporting network and HTTP request errors to the MobileRequestError event type. networkErrorRequestEnabled: true, // Optional:Enable or disable reporting successful HTTP requests to the MobileRequest event type. networkRequestEnabled: true, // Optional:Enable or disable crash reporting. crashReportingEnabled: true, // Optional:Enable or disable interaction tracing. Trace instrumentation still occurs, but no traces are harvested. This will disable default and custom interactions. interactionTracingEnabled: true, // Optional:Enable or disable capture of HTTP response bodies for HTTP error traces, and MobileRequestError events. httpResponseBodyCaptureEnabled: true, // Optional: Enable or disable agent logging. loggingEnabled: true, //iOS Specific // Optional:Enable/Disable automatic instrumentation of WebViews webViewInstrumentation: true, //Optional: Enable or Disable Print Statements as Analytics Events printStatementAsEventsEnabled : true, // Optional:Enable/Disable automatic instrumentation of Http Request httpInstrumentationEnabled:true, // Optional : Enable or disable reporting data using different endpoints for US government clients fedRampEnabled: false , // Optional: Enable or disable offline data storage when no internet connection is available. offlineStorageEnabled:true, // iOS Specific // Optional: Enable or disable background reporting functionality. backgroundReportingEnabled: false, // iOS Specific // Optional: Enable or disable to use our new, more stable, event system for iOS agent. newEventSystemEnabled: false, // Optional: Enable or disable distributed tracing. distributedTracingEnabled: true, // Optional: Log Level for Agent Logs. logLevel: LogLevel.DEBUG ); NewrelicMobile.instance.start(config, () { runApp(MyApp()); }); class MyApp extends StatelessWidget { .... ``` -------------------------------- ### Apply New Relic Gradle Plugin (Plugins DSL) Source: https://github.com/newrelic/newrelic-flutter-agent/blob/main/README.md Configure your Android project to use the New Relic Gradle plugin with the Plugins DSL in `android/settings.gradle` and `android/app/build.gradle`. ```groovy plugins { id "dev.flutter.flutter-plugin-loader" version "1.0.0" id "com.android.application" version "7.4.2" apply false id "org.jetbrains.kotlin.android" version "1.7.10" apply false id "com.newrelic.agent.android" version "7.7.5" apply false // <-- include this } ``` ```groovy plugins { id "com.android.application" id "kotlin-android" id "dev.flutter.flutter-gradle-plugin" id "com.newrelic.agent.android" //<-- include this } ``` -------------------------------- ### Apply New Relic Gradle Plugin (Traditional) Source: https://github.com/newrelic/newrelic-flutter-agent/blob/main/README.md Configure your Android project to use the New Relic Gradle plugin using the traditional method in `android/app/build.gradle`. ```groovy buildscript { ... repositories { ... mavenCentral() } dependencies { ... classpath "com.newrelic.agent.android:agent-gradle-plugin:7.6.6" } } ``` ```groovy apply plugin: "com.android.application" apply plugin: 'newrelic' // <-- include this ``` -------------------------------- ### Enable GoRouter Instrumentation Source: https://github.com/newrelic/newrelic-flutter-agent/blob/main/README.md Enable automatic routing instrumentation for go_router by adding NewRelicNavigationObserver to its observers list. ```dart //.... import 'package:go_router/go_router.dart'; import 'package:newrelic_mobile/newrelic_navigation_observer.dart'; final router = GoRouter( routes: ..., observers: [NewRelicNavigationObserver()], ); ``` -------------------------------- ### startInteraction Source: https://github.com/newrelic/newrelic-flutter-agent/blob/main/README.md Tracks a method or operation as a distinct interaction within the application. It returns a string ID that should be used to end the interaction later. ```APIDOC ## startInteraction(String actionName) ### Description Tracks a method or operation as a distinct interaction within the application. It returns a string ID that should be used to end the interaction later. ### Method `startInteraction` ### Parameters #### Path Parameters - **actionName** (String) - Required - The name of the interaction to track. ``` -------------------------------- ### logInfo Source: https://github.com/newrelic/newrelic-flutter-agent/blob/main/README.md Logs an informational message to the New Relic log. Use this for general information about application flow. ```APIDOC ## logInfo ### Description Logs an informational message to the New Relic log. ### Method Signature `logInfo(String message) : void;` ### Parameters * **message** (String) - Required - The informational message to log. ### Request Example ```dart NewrelicMobile.instance.logInfo("This is an informational message"); ``` ``` -------------------------------- ### logAll Source: https://github.com/newrelic/newrelic-flutter-agent/blob/main/README.md Logs an exception along with associated attributes to the New Relic log. This is useful for capturing detailed context around exceptions. ```APIDOC ## logAll ### Description Logs an exception with attributes to the New Relic log. ### Method Signature `logAll(Exception exception,Map? attributes) : void;` ### Parameters * **exception** (Exception) - Required - The exception to log. * **attributes** (Map) - Optional - A map of attributes to associate with the exception. ### Request Example ```dart NewrelicMobile.instance.logAll(Exception("This is an exception"), {\"BreadNumValue\": 12.3 , \"BreadStrValue\": \"FlutterBread\", \"BreadBoolValue\": true , \"message\": \"This is a message with attributes\" } ); ``` ``` -------------------------------- ### Run Script for dSYM Upload in Xcode Source: https://github.com/newrelic/newrelic-flutter-agent/blob/main/README.md Add this script to a new Run Script Build Phase in your Xcode project to automatically upload dSYM files during the build process. Replace 'APP_TOKEN' with your actual iOS application token. ```bash ARTIFACT_DIR="${BUILD_DIR%Build/*}" SCRIPT=`/usr/bin/find "${SRCROOT}" "${ARTIFACT_DIR}" -type f -name run-symbol-tool | head -n 1` /bin/sh "${SCRIPT}" "APP_TOKEN" ``` -------------------------------- ### addHTTPHeadersTrackingFor Source: https://github.com/newrelic/newrelic-flutter-agent/blob/main/README.md Configures the agent to track specific HTTP header fields. These headers will be recorded as attributes with networking request events. ```APIDOC ## addHTTPHeadersTrackingFor ### Description This API allows you to add any header field strings to a list that gets recorded as attributes with networking request events. After header fields have been added using this function, if the headers are in a network call they will be included in networking events in NR1. ### Method Signature `addHTTPHeadersTrackingFor(headers: string[]) : void;` ### Parameters * **headers** (string[]) - Required - A list of header field names to track. ### Request Example ```dart NewrelicMobile.instance.addHTTPHeadersTrackingFor(["Car","Music"]); ``` ``` -------------------------------- ### Add New Relic Mobile to pubspec.yaml Source: https://github.com/newrelic/newrelic-flutter-agent/blob/main/README.md Add the New Relic Mobile plugin to your project's pubspec.yaml file to include it as a dependency. ```yaml dependencies: newrelic_mobile: 1.1.20 ``` -------------------------------- ### logVerbose Source: https://github.com/newrelic/newrelic-flutter-agent/blob/main/README.md Logs a verbose message to the New Relic log. This is useful for detailed debugging information. ```APIDOC ## logVerbose ### Description Logs a verbose message to the New Relic log. ### Method Signature `logVerbose(String message) : void;` ### Parameters * **message** (String) - Required - The verbose message to log. ### Request Example ```dart NewrelicMobile.instance.logVerbose("This is a verbose message"); ``` ``` -------------------------------- ### Log Exception with Attributes Source: https://github.com/newrelic/newrelic-flutter-agent/blob/main/README.md Logs an exception along with a map of attributes to the New Relic log. ```dart NewrelicMobile.instance.logAll(Exception("This is an exception"), {"BreadNumValue": 12.3 , "BreadStrValue": "FlutterBread", "BreadBoolValue": true , "message": "This is a message with attributes" } ); ``` -------------------------------- ### recordCustomEvent Source: https://github.com/newrelic/newrelic-flutter-agent/blob/main/README.md Creates and records a custom event. This is useful for tracking specific business events or user interactions within the application for analysis in New Relic Insights. ```APIDOC ## recordCustomEvent(String eventType, {String eventName = "", Map? eventAttributes}) ### Description Creates and records a custom event. This is useful for tracking specific business events or user interactions within the application for analysis in New Relic Insights. ### Method `recordCustomEvent` ### Parameters #### Path Parameters - **eventType** (String) - Required - The type of the custom event. - **eventName** (String) - Optional - The name of the custom event. Defaults to an empty string. - **eventAttributes** (Map) - Optional - Additional attributes to associate with the custom event. ``` -------------------------------- ### Simulate Crashes with New Relic Flutter Agent Source: https://github.com/newrelic/newrelic-flutter-agent/blob/main/README.md Throws demo run-time exceptions to test New Relic crash reporting. Can include a custom name for the crash. ```dart NewrelicMobile.instance.crashNow(name: "This is a crash"); NewrelicMobile.instance.crashNow(); ``` -------------------------------- ### Add NewRelicNavigationObserver to MaterialApp Source: https://github.com/newrelic/newrelic-flutter-agent/blob/main/README.md Integrate NewRelicNavigationObserver into your MaterialApp to track navigation events. Ensure route settings have a name. ```dart import 'package:newrelic_mobile/newrelic_navigation_observer.dart'; //.... MaterialApp( navigatorObservers: [ NewRelicNavigationObserver(), ], // other parameters ) ``` -------------------------------- ### Xcode Build Settings for dSYM Generation Source: https://github.com/newrelic/newrelic-flutter-agent/blob/main/README.md Ensure these build settings are configured in Xcode to generate dSYM files, which are necessary for crash symbolication. These settings are typically found under the 'Build Settings' tab for your application target. ```text Debug Information Format : Dwarf with dSYM File Deployment Postprocessing: Yes Strip Linked Product: Yes Strip Debug Symbols During Copy : Yes ``` -------------------------------- ### Record Breadcrumb Source: https://github.com/newrelic/newrelic-flutter-agent/blob/main/README.md Track app activity or screens that may be helpful for troubleshooting crashes. ```dart NewrelicMobile.instance.recordBreadcrumb("Button Got Pressed on Screen 3"), ``` -------------------------------- ### logWarning Source: https://github.com/newrelic/newrelic-flutter-agent/blob/main/README.md Logs a warning message to the New Relic log. Use this to indicate potential issues that do not necessarily stop execution. ```APIDOC ## logWarning ### Description Logs a warning message to the New Relic log. ### Method Signature `logWarning(String message) : void;` ### Parameters * **message** (String) - Required - The warning message to log. ### Request Example ```dart NewrelicMobile.instance.logWarning("This is a warning message"); ``` ``` -------------------------------- ### recordBreadcrumb Source: https://github.com/newrelic/newrelic-flutter-agent/blob/main/README.md Tracks a specific app activity or screen transition. Breadcrumbs are helpful for troubleshooting crashes by providing a timeline of user actions leading up to an event. ```APIDOC ## recordBreadcrumb(String name, {Map? eventAttributes}) ### Description Tracks a specific app activity or screen transition. Breadcrumbs are helpful for troubleshooting crashes by providing a timeline of user actions leading up to an event. ### Method `recordBreadcrumb` ### Parameters #### Path Parameters - **name** (String) - Required - The name of the breadcrumb event. - **eventAttributes** (Map) - Optional - Additional attributes to associate with the breadcrumb. ``` -------------------------------- ### Record Custom Metrics Source: https://github.com/newrelic/newrelic-flutter-agent/blob/main/README.md Records custom metrics with optional value units. Ensure all value, countUnit, and valueUnit are set if using units. ```dart NewrelicMobile.instance.recordMetric("testMetric", "Test Champ",value: 12.0); ``` ```dart NewrelicMobile.instance.recordMetric("testMetric1", "TestChamp12",value: 10,valueUnit: MetricUnit.BYTES,countUnit: MetricUnit.PERCENT); ``` -------------------------------- ### Notice Network Failure Source: https://github.com/newrelic/newrelic-flutter-agent/blob/main/README.md Records network failures. If a network request fails, use this method to record details about the failures. Supported failures include Unknown, BadURL, TimedOut, CannotConnectToHost, DNSLookupFailed, BadServerResponse, SecureConnectionFailed. ```dart NewrelicMobile.instance.noticeNetworkFailure("https://cb6b02be-a319-4de5-a3b1-361de2564493.mock.pstmn.io/searchpage", "GET", 1000, 2000,'Test Network Failure', NetworkFailure.dnsLookupFailed); ``` -------------------------------- ### Log Message with Level Source: https://github.com/newrelic/newrelic-flutter-agent/blob/main/README.md Logs a message to the New Relic log with a specified log level. ```dart NewrelicMobile.instance.log(LogLevel.Info, "This is an informational message"); ``` -------------------------------- ### log Source: https://github.com/newrelic/newrelic-flutter-agent/blob/main/README.md Logs a message to the New Relic log with a specified log level. This provides flexibility in categorizing log entries. ```APIDOC ## log ### Description Logs a message to the New Relic log with a specified log level. ### Method Signature `log(LogLevel level, String message) : void;` ### Parameters * **level** (LogLevel) - Required - The log level (e.g., Info, Warning, Error). * **message** (String) - Required - The message to log. ### Request Example ```dart NewrelicMobile.instance.log(LogLevel.Info, "This is an informational message"); ``` ``` -------------------------------- ### Log Warning Message Source: https://github.com/newrelic/newrelic-flutter-agent/blob/main/README.md Logs a warning message to the New Relic log. ```dart NewrelicMobile.instance.logWarning("This is a warning message"); ``` -------------------------------- ### Log Informational Message Source: https://github.com/newrelic/newrelic-flutter-agent/blob/main/README.md Logs an informational message to the New Relic log. ```dart NewrelicMobile.instance.logInfo("This is an informational message"); ``` -------------------------------- ### recordMetric Source: https://github.com/newrelic/newrelic-flutter-agent/blob/main/README.md Records custom metrics with optional value units and count units. This is useful for tracking arbitrary numerical data relevant to your application's performance. ```APIDOC ## recordMetric ### Description Records custom metrics (arbitrary numerical data), where countUnit is the measurement unit of the metric count and valueUnit is the measurement unit for the metric value. If using countUnit or valueUnit, then all of value, countUnit, and valueUnit must all be set. ### Method Signature `recordMetric(name: string, category: string, value?: number, countUnit?: string, valueUnit?: string): void;` ### Parameters * **name** (string) - Required - The name of the metric. * **category** (string) - Required - The category of the metric. * **value** (number) - Optional - The numerical value of the metric. * **countUnit** (string) - Optional - The unit of measurement for the metric count. * **valueUnit** (string) - Optional - The unit of measurement for the metric value. ### Request Example ```dart NewrelicMobile.instance.recordMetric("testMetric", "Test Champ",value: 12.0); NewrelicMobile.instance.recordMetric("testMetric1", "TestChamp12",value: 10,valueUnit: MetricUnit.BYTES,countUnit: MetricUnit.PERCENT); ``` ``` -------------------------------- ### logError Source: https://github.com/newrelic/newrelic-flutter-agent/blob/main/README.md Logs an error message to the New Relic log. Use this to report errors encountered during runtime. ```APIDOC ## logError ### Description Logs an error message to the New Relic log. ### Method Signature `logError(String message) : void;` ### Parameters * **message** (String) - Required - The error message to log. ### Request Example ```dart NewrelicMobile.instance.logError("This is an error message"); ``` ``` -------------------------------- ### Log Attributes with New Relic Flutter Agent Source: https://github.com/newrelic/newrelic-flutter-agent/blob/main/README.md Logs a message with various data types as attributes to the New Relic log. Ensure the NewrelicMobile instance is initialized. ```dart NewrelicMobile.instance.logAttributes({ "BreadNumValue": 12.3 , "BreadStrValue": "FlutterBread", "BreadBoolValue": true , "message": "This is a message with attributes" }); ``` -------------------------------- ### logDebug Source: https://github.com/newrelic/newrelic-flutter-agent/blob/main/README.md Logs a debug message to the New Relic log. This is intended for detailed debugging information during development. ```APIDOC ## logDebug ### Description Logs a debug message to the New Relic log. ### Method Signature `logDebug(String message) : void;` ### Parameters * **message** (String) - Required - The debug message to log. ### Request Example ```dart NewrelicMobile.instance.logDebug("This is a debug message"); ``` ``` -------------------------------- ### logAttributes Source: https://github.com/newrelic/newrelic-flutter-agent/blob/main/README.md Logs a message with attributes to the New Relic log. This method allows you to attach custom key-value pairs to log entries for detailed analysis. ```APIDOC ## logAttributes(Dictionary attributes) ### Description Logs a message with attributes to the New Relic log. This method allows you to attach custom key-value pairs to log entries for detailed analysis. ### Method void ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body * **attributes** (Dictionary) - Required - A dictionary containing key-value pairs to be logged as attributes. ### Request Example ```dart NewrelicMobile.instance.logAttributes({ "BreadNumValue": 12.3, "BreadStrValue": "FlutterBread", "BreadBoolValue": true, "message": "This is a message with attributes" }); ``` ### Response #### Success Response (void) This method does not return a value. #### Response Example N/A ``` -------------------------------- ### noticeNetworkFailure Source: https://github.com/newrelic/newrelic-flutter-agent/blob/main/README.md Records network failures, providing details about the failure event. This method is typically used within exception handlers to capture information about failed network requests. ```APIDOC ## noticeNetworkFailure(String url, String httpMethod, int startTime, int endTime, String errorCode, NetworkFailure failureType) ### Description Records network failures, providing details about the failure event. This method is typically used within exception handlers to capture information about failed network requests. ### Method `noticeNetworkFailure` ### Parameters #### Path Parameters - **url** (String) - Required - The URL of the failed network request. - **httpMethod** (String) - Required - The HTTP method used for the request. - **startTime** (int) - Required - The start time of the network request in milliseconds. - **endTime** (int) - Required - The end time of the network request in milliseconds. - **errorCode** (String) - Required - A string representing the error code or a description of the failure. - **failureType** (NetworkFailure) - Required - An enum value representing the type of network failure (e.g., NetworkFailure.dnsLookupFailed). ``` -------------------------------- ### Set Max Event Pool Size Source: https://github.com/newrelic/newrelic-flutter-agent/blob/main/README.md Sets the maximum size of the event pool. ```dart NewrelicMobile.instance.setMaxEventPoolSize(10000); ``` -------------------------------- ### Log Verbose Message Source: https://github.com/newrelic/newrelic-flutter-agent/blob/main/README.md Logs a verbose message to the New Relic log. ```dart NewrelicMobile.instance.logVerbose("This is a verbose message"); ``` -------------------------------- ### noticeHttpTransaction Source: https://github.com/newrelic/newrelic-flutter-agent/blob/main/README.md Manually tracks an HTTP transaction. This method allows for detailed recording of network requests, including status codes, timing, and data transfer sizes, with an option to include the response body. ```APIDOC ## noticeHttpTransaction(String url, String httpMethod, int statusCode, int startTime, int endTime, int bytesSent, int bytesReceived, Map? traceData, {String responseBody = ""}) ### Description Manually tracks an HTTP transaction. This method allows for detailed recording of network requests, including status codes, timing, and data transfer sizes, with an option to include the response body. ### Method `noticeHttpTransaction` ### Parameters #### Path Parameters - **url** (String) - Required - The URL of the HTTP transaction. - **httpMethod** (String) - Required - The HTTP method used (e.g., GET, POST). - **statusCode** (int) - Required - The HTTP status code of the response. - **startTime** (int) - Required - The start time of the transaction in milliseconds. - **endTime** (int) - Required - The end time of the transaction in milliseconds. - **bytesSent** (int) - Required - The number of bytes sent in the request. - **bytesReceived** (int) - Required - The number of bytes received in the response. - **traceData** (Map) - Optional - Additional trace data. - **responseBody** (String) - Optional - The response body of the transaction. ``` -------------------------------- ### Record Custom Event Source: https://github.com/newrelic/newrelic-flutter-agent/blob/main/README.md Creates and records a custom event for use in New Relic Insights. You can specify an event type, name, and attributes. ```dart NewrelicMobile.instance.recordCustomEvent("Major",eventName: "User Purchase",eventAttributes: {"item1":"Clothes","price":34.00}), child: const Text('Record Custom Event'), ``` -------------------------------- ### Set Max Event Buffer Time Source: https://github.com/newrelic/newrelic-flutter-agent/blob/main/README.md Sets the event harvest cycle length in seconds. ```dart NewrelicMobile.instance.setMaxEventBufferTime(200); ``` -------------------------------- ### setAttribute Source: https://github.com/newrelic/newrelic-flutter-agent/blob/main/README.md Creates or updates a session-level attribute. These attributes are shared across multiple mobile events and can be used for custom data tracking. Each call overwrites the previous value and type. ```APIDOC ## setAttribute(String name, dynamic value) ### Description Creates or updates a session-level attribute. These attributes are shared across multiple mobile events and can be used for custom data tracking. Each call overwrites the previous value and type. ### Method `setAttribute` ### Parameters #### Path Parameters - **name** (String) - Required - The name of the attribute. - **value** (dynamic) - Required - The value of the attribute. ``` -------------------------------- ### Log Debug Message Source: https://github.com/newrelic/newrelic-flutter-agent/blob/main/README.md Logs a debug message to the New Relic log. ```dart NewrelicMobile.instance.logDebug("This is a debug message"); ``` -------------------------------- ### Log Error Message Source: https://github.com/newrelic/newrelic-flutter-agent/blob/main/README.md Logs an error message to the New Relic log. ```dart NewrelicMobile.instance.logError("This is an error message"); ``` -------------------------------- ### Notice HTTP Transaction Source: https://github.com/newrelic/newrelic-flutter-agent/blob/main/README.md Tracks network requests manually. You can use this method to record HTTP transactions, with an option to also send a response body. ```dart NewrelicMobile.instance.noticeHttpTransaction("https://cb6b02be-a319-4de5-a3b1-361de2564493.mock.pstmn.io/searchpage", "GET",200, 1000, 2000,100,300,null,responseBody: "This is Test Payload"); ``` -------------------------------- ### recordError Source: https://github.com/newrelic/newrelic-flutter-agent/blob/main/README.md Registers non-fatal exceptions with custom attributes. This method is used within a try-catch block to report errors that do not terminate the application. ```APIDOC ## recordError(error, StackTrace.current, attributes: attributes) ### Description Registers non-fatal exceptions with custom attributes. This method is used within a try-catch block to report errors that do not terminate the application. ### Method void ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body * **error** - Required - The error object to be recorded. * **StackTrace.current** - Required - The current stack trace. * **attributes** (Dictionary) - Optional - A dictionary containing custom attributes to associate with the error. ### Request Example ```dart try { some_code_that_throws_error(); } catch (ex) { NewrelicMobile.instance .recordError(error, StackTrace.current, attributes: attributes); } ``` ### Response #### Success Response (void) This method does not return a value. #### Response Example N/A ``` -------------------------------- ### shutdown Source: https://github.com/newrelic/newrelic-flutter-agent/blob/main/README.md Shuts down the New Relic agent. This should be called when you want to stop the agent's operation within the current application lifecycle. ```APIDOC ## shutdown ### Description Shut down the agent within the current application lifecycle during runtime. ### Method Signature `shutdown() : void;` ### Request Example ```dart NewrelicMobile.instance.shutdown(); ``` ``` -------------------------------- ### setMaxEventPoolSize Source: https://github.com/newrelic/newrelic-flutter-agent/blob/main/README.md Sets the maximum number of events that can be stored in the event pool. This helps manage memory usage and data collection. ```APIDOC ## setMaxEventPoolSize(int maxSize) ### Description Sets the maximum number of events that can be stored in the event pool. This helps manage memory usage and data collection. ### Method `setMaxEventPoolSize` ### Parameters #### Path Parameters - **maxSize** (int) - Required - The maximum size of the event pool. ``` -------------------------------- ### setAttribute Source: https://github.com/newrelic/newrelic-flutter-agent/blob/main/README.md Sets a session-level attribute. This attribute will be shared across multiple mobile event types and can be used to tag events with custom information. ```APIDOC ## setAttribute ### Description Creates a session-level attribute shared by multiple mobile event types. Overwrites its previous value and type each time it is called. ### Method Signature `setAttribute(name: string, value: boolean | number | string): void;` ### Parameters * **name** (string) - Required - The name of the attribute. * **value** (boolean | number | string) - Required - The value of the attribute. ### Request Example ```dart NewrelicMobile.instance.setAttribute("FlutterCustomAttrNumber",value :5.0); ``` ``` -------------------------------- ### Set User ID Source: https://github.com/newrelic/newrelic-flutter-agent/blob/main/README.md Set a custom user identifier to associate user sessions with analytics events and attributes. ```dart NewrelicMobile.instance.setUserId("RN12934"); ``` -------------------------------- ### Record Errors with Custom Attributes Source: https://github.com/newrelic/newrelic-flutter-agent/blob/main/README.md Registers non-fatal exceptions using the recordError method, allowing for custom attributes to be attached. This is useful for manual error reporting. ```dart try { some_code_that_throws_error(); } catch (ex) { NewrelicMobile.instance .recordError(error, StackTrace.current, attributes: attributes); } ``` -------------------------------- ### Set Session Attribute Source: https://github.com/newrelic/newrelic-flutter-agent/blob/main/README.md Creates or overwrites a session-level attribute with a boolean, number, or string value. ```dart NewrelicMobile.instance.setAttribute("FlutterCustomAttrNumber",value :5.0); ``` -------------------------------- ### setMaxEventBufferTime Source: https://github.com/newrelic/newrelic-flutter-agent/blob/main/README.md Sets the duration of the event harvest cycle. This determines how often events are sent to the New Relic backend. ```APIDOC ## setMaxEventBufferTime(int maxBufferTimeInSec) ### Description Sets the duration of the event harvest cycle. This determines how often events are sent to the New Relic backend. ### Method `setMaxEventBufferTime` ### Parameters #### Path Parameters - **maxBufferTimeInSec** (int) - Required - The maximum time in seconds for the event buffer. ``` -------------------------------- ### currentSessionId Source: https://github.com/newrelic/newrelic-flutter-agent/blob/main/README.md Retrieves the current session ID for the New Relic agent. This is helpful for correlating data across different monitoring tools or for custom session tracking. ```APIDOC ## currentSessionId ### Description Returns the current session ID. This method is useful for consolidating monitoring of app data (not just New Relic data) based on a single session definition and identifier. ### Method Signature `currentSessionId(): Promise;` ### Response * **sessionId** (Promise) - The current session ID. ### Request Example ```dart var sessionId = await NewrelicMobile.instance.currentSessionId(); ``` ``` -------------------------------- ### setUserId Source: https://github.com/newrelic/newrelic-flutter-agent/blob/main/README.md Sets a custom user identifier. This allows associating user sessions with specific analytics events and attributes for better user behavior analysis. ```APIDOC ## setUserId(String userId) ### Description Sets a custom user identifier. This allows associating user sessions with specific analytics events and attributes for better user behavior analysis. ### Method `setUserId` ### Parameters #### Path Parameters - **userId** (String) - Required - The custom user identifier. ``` -------------------------------- ### Set Session Attribute Source: https://github.com/newrelic/newrelic-flutter-agent/blob/main/README.md Creates a session-level attribute. This overwrites its previous value and type each time it is called. ```dart NewrelicMobile.instance.setAttribute('RNCustomAttrNumber', 37); ``` -------------------------------- ### Shutdown New Relic Agent Source: https://github.com/newrelic/newrelic-flutter-agent/blob/main/README.md Shuts down the New Relic agent within the current application lifecycle. ```dart NewrelicMobile.instance.shutdown(); ``` -------------------------------- ### Increment Session Attribute Source: https://github.com/newrelic/newrelic-flutter-agent/blob/main/README.md Increments an attribute's count. Creates the attribute if it doesn't exist. Defaults to incrementing by 1 if no value is provided. ```dart NewrelicMobile.instance.incrementAttribute("FlutterCustomAttrNumber"); ``` ```dart NewrelicMobile.instance.incrementAttribute("FlutterCustomAttrNumber",value :5.0); ``` -------------------------------- ### incrementAttribute Source: https://github.com/newrelic/newrelic-flutter-agent/blob/main/README.md Increments the numerical value of an attribute. If the attribute does not exist, it will be created. You can optionally provide a value to increment by; otherwise, it increments by 1. ```APIDOC ## incrementAttribute ### Description Increments the count of an attribute with a specified name. Overwrites its previous value and type each time it is called. If the attribute does not exists, it creates a new attribute. If no value is given, it increments the value by 1. ### Method Signature `incrementAttribute(name: string, value?: number): void;` ### Parameters * **name** (string) - Required - The name of the attribute to increment. * **value** (number) - Optional - The amount to increment the attribute by. ### Request Example ```dart NewrelicMobile.instance.incrementAttribute("FlutterCustomAttrNumber"); NewrelicMobile.instance.incrementAttribute("FlutterCustomAttrNumber",value :5.0); ``` ``` -------------------------------- ### Remove Session Attribute Source: https://github.com/newrelic/newrelic-flutter-agent/blob/main/README.md Removes a session attribute specified by its name. ```dart NewrelicMobile.instance.removeAttribute("FlutterCustomAttrNumber"); ``` -------------------------------- ### removeAttribute Source: https://github.com/newrelic/newrelic-flutter-agent/blob/main/README.md Removes a previously set session-level attribute. Use this to clean up custom attributes when they are no longer needed. ```APIDOC ## removeAttribute ### Description This method removes the attribute specified by the name string. ### Method Signature `removeAttribute(name: string, value: boolean | number | string): void;` ### Parameters * **name** (string) - Required - The name of the attribute to remove. * **value** (boolean | number | string) - Required - The value of the attribute to remove. ### Request Example ```dart NewrelicMobile.instance.removeAttribute("FlutterCustomAttrNumber"); ``` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.