Options
All
  • Public
  • Public/Protected
  • All
Menu

Interact with the AppDynamics agent running in your application.

This class provides a number of methods to interact with the AppDynamics agent including

  • Initializing the agent with the right application key
  • Reporting custom metrics/timers
  • Reporting info points manually

Initializing the agent

The agent does not automatically start with your application. Using the app key shown in your controller UI, you can initialize the agent. This has to be done near your application's entry point before any other initialization routines in your application.

For example:

Instrumentation.start({
     appKey: "ABC-DEF-GHI", // Replace with your actual application key
});

Once initialized, further calls to start have no effect on the agent.

About synchronicity

Because the react-native bridge is asynchronous, all of these API calls are asynchronous as well. A call to any of these functions doesn't take effect instantly, but some time in the near future.

Some methods return a Promise which resolve when the call is effective. For methods that don't return a promise, it is not possible to determine exactly when a call becomes effective. This peculiarity enables optimizations which allow the agent to preserve its negligible CPU footprint.

Reporting custom timers and metrics

You can also report custom timers and metrics using the following API(s):

Custom Metrics

Custom metrics allows you to report numeric values associated with a 'metric name'. For example, to track the number of times your users clicked the 'checkout' button, you can report it as easily as follows:

export default class App extends Component {
     render() {
         return <View>
             <TouchableHighlight title="checkout" onPress={() => this.doCheckout()}>
                 <Text>Checkout</Text>
             </TouchableHighlight>
         </View>
     }

     doCheckout() {
         Instrumentation.reportMetric("Checkout Count", 1);
         // ...rest of the checkout logic
     }
}

Custom Timers

Using Custom timers, we can time events in your applications that span across multiple threads/methods. For example, the code snippet below reports how long the checkout method took.


// ...

async doCheckout() {
    const CHECKOUT_TIMER = "Time Spent on checkout";
    Instrumentation.startTimer(CHECKOUT_TIMER);

    try {
        await someCheckoutService();
        await someOtherLongTask();
    } finally {
        Instrumentation.stopTimer(CHECKOUT_TIMER);
    }
}

// ...

Note that startTimer and stopTimer can be called from anywhere in your app.

Reporting info points

Info Points allows you to track execution of interesting synchronous and asynchronous methods in your application code. This includes reporting method arguments, return value and exception that was thrown by the synchronous method, or the success or error value of the promise for asynchronous methods.

For example, say you want to track the following function:

async function downloadImage(url) {
    const request = createRequest(url);
    const response = await request.execute();
    if (response.status >= 400) {
        throw new Error(`Bad status code: ${response.status}`);
    }
    return response.data;
}

The easiest way to add an info point to this method is using the InfoPoint decorator.

class DownloadService {
    @InfoPoint
    async downloadImage(url) {
         const request = createRequest(url);
         const response = await request.execute();
         if (response.status >= 400) {
             throw new Error(`Bad status code: ${response.status}`);
         }
         return response.data;
    }
}

Note Use @InfoPoint({ className: 'DownloadService', fnName: 'downloadImage' }) if your code is minified. More info on InfoPoint.

Alternatively, you can use the manual tracking api.

async function downloadImage(url) {
     return Instrumentation.trackCall('DownloadService', 'downloadImage', [url], async () => {
         const request = createRequest(url);
         const response = await request.execute();
         if (response.status >= 400) {
             throw new Error(`Bad status code: ${response.status}`);
         }
         return response.data;
     });
}

This has the same effect as the decorator above.

For more information please see trackCall and InfoPoint.


Further resources

More information about AppDynamics Mobile Real User Monitoring features can be found in the official documentation.

Hierarchy

  • Instrumentation

Index

Properties

Static Readonly MAX_USER_DATA_STRING_LENGTH

MAX_USER_DATA_STRING_LENGTH: number = InstrumentationConstants.MAX_USER_DATA_STRING_LENGTH

Maximum length for userdata parameters.

see

setUserData, setUserDataBoolean, setUserDataInteger, setUserDataDate, setUserDataDouble

Methods

Static blockScreenshots

  • blockScreenshots(): Promise<void>
  • Blocks screenshot capture if it is currently unblocked. Otherwise, this has no effect..

    If screenshots are disabled through AgentConfiguration.screenshotsEnabled or through the controller UI, this method has no effect.

    WARNING (1): This will block capture for the entire app. WARNING (2): Use the returned promise to determine when screenshots have effectively been blocked.

    The user is expected to manage any possible nesting issues that may occur if blocking and unblocking occur in different code paths.

    Returns Promise<void>

    A promise which resolves when screenshots are effectively blocked.

    See unblockScreenshots

Static changeAppKey

  • changeAppKey(appKey: string): Promise<void>
  • Change the app key. Older beacons/reports will be discarded when app key is changed.

    NOTE: Invoking this method has no effect unless the agent was already initialized by calling one of the start methods.

    Parameters

    • appKey: string

      The new application key to use for reporting beacons.

    Returns Promise<void>

    A promise which fails on an illegal appKey parameter.

Static leaveBreadcrumb

  • Leaves a breadcrumb that will appear in a crash report and, optionally, session.

    Call this when something interesting happens in your application. The breadcrumb will be included in different reports depending on the mode. Each crash report displays the most recent 99 breadcrumbs.

    If you would like it to appear also in sessions, use BreadcrumbVisibility.CRASHES_AND_SESSIONS.

    Parameters

    Returns void

Static removeUserData

  • removeUserData(key: string): void
  • Removes a key-value pair set with setUserData. The identifier can be used to add any data you wish.

    Parameters

    • key: string

      Key of the entry to remove.

    Returns void

Static removeUserDataBoolean

  • removeUserDataBoolean(key: string): void
  • Removes a key-value pair set with setUserDataBoolean. The identifier can be used to add any data you wish.

    Parameters

    • key: string

      Key of the entry to remove.

    Returns void

Static removeUserDataDate

  • removeUserDataDate(key: string): void
  • Removes a key-value pair set with setUserDataInteger. The identifier can be used to add any data you wish.

    Parameters

    • key: string

      Key of the entry to remove.

    Returns void

Static removeUserDataDouble

  • removeUserDataDouble(key: string): void
  • Removes a key-value pair set with setUserDataDouble. The identifier can be used to add any data you wish.

    Parameters

    • key: string

      Key of the entry to remove.

    Returns void

Static removeUserDataInteger

  • removeUserDataInteger(key: string): void
  • Removes a key-value pair set with setUserDataInteger. The identifier can be used to add any data you wish.

    Parameters

    • key: string

      Key of the entry to remove.

    Returns void

Static reportError

Static reportMetric

  • reportMetric(name: string, value: number): void
  • Reports metric value for the given name.

    The name should contain only alphanumeric characters and spaces.

    Illegal characters shall be replaced by their ASCII hex value.

    WARNING: The native agent expects a 64-bit signed integer. However, JavaScript numbers are never represented as such. The maximum and minimum integers which can be represented with exact accuracy are materialized by MAX_SAFE_INTEGER and MIN_SAFE_INTEGER.

    Any value that falls outside of this range will be reported with a different metric name, containing the word "INVALID"

    Parameters

    • name: string

      The name of the metric key.

    • value: number

      The value reported for the given key. Must be an integer between MAX_SAFE_INTEGER and MIN_SAFE_INTEGER.

    Returns void

Static restartAgent

  • restartAgent(): void
  • Restarts sending of beacons to the collector.

    Data will start flowing from the agent immediately. No change will occur if the shutdownAgent call has not been made.

    See also shutdownAgent

    Returns void

Static screenshotsBlocked

  • screenshotsBlocked(): Promise<boolean>
  • Returns Promise<boolean>

    boolean whether screenshot capture is blocked

Static setUserData

  • setUserData(key: string, value: string | null | undefined): void
  • Sets a key-value pair identifier that will be included in all snapshots. The identifier can be used to add any data you wish.

    The key must be unique across your application. The key namespace is distinct for each user data type. Re-using the same key overwrites the previous value. The key is limited to MAX_USER_DATA_STRING_LENGTH characters.

    A value of null will clear the data. The value is limited to MAX_USER_DATA_STRING_LENGTH characters.

    This information is not persisted across application runs. Once the application is destroyed, the user data is cleared.

    Parameters

    • key: string

      Your unique key.

    • value: string | null | undefined

      Your value.

    Returns void

Static setUserDataBoolean

  • setUserDataBoolean(key: string, value: boolean | null | undefined): void
  • Sets a key-value pair identifier that will be included in all snapshots. The identifier can be used to add any data you wish.

    The key must be unique across your application. The key namespace is distinct for each user data type. Re-using the same key overwrites the previous value. The key is limited to MAX_USER_DATA_STRING_LENGTH characters.

    A value of null will clear the data.

    This information is not persisted across application runs. Once the application is destroyed, the user data is cleared.

    Parameters

    • key: string

      Your unique key.

    • value: boolean | null | undefined

      Your value.

    Returns void

Static setUserDataDate

  • setUserDataDate(key: string, value: Date | null | undefined): void
  • Sets a key-value pair identifier that will be included in all snapshots. The identifier can be used to add any data you wish.

    The key must be unique across your application. The key namespace is distinct for each user data type. Re-using the same key overwrites the previous value. The key is limited to MAX_USER_DATA_STRING_LENGTH characters.

    A value of null will clear the data.

    This information is not persisted across application runs. Once the application is destroyed, the user data is cleared.

    Parameters

    • key: string

      Your unique key.

    • value: Date | null | undefined

      Your value.

    Returns void

Static setUserDataDouble

  • setUserDataDouble(key: string, value: number | null | undefined): void
  • Sets a key-value pair identifier that will be included in all snapshots. The identifier can be used to add any data you wish.

    The key must be unique across your application. The key namespace is distinct for each user data type. Re-using the same key overwrites the previous value. The key is limited to MAX_USER_DATA_STRING_LENGTH characters.

    A value of null will clear the data.

    The value has to be finite. Attempting to set infinite or NaN value, will clear the data.

    This information is not persisted across application runs. Once the application is destroyed, the user data is cleared.

    Parameters

    • key: string

      Your unique key.

    • value: number | null | undefined

      Your value.

    Returns void

Static setUserDataInteger

  • setUserDataInteger(key: string, value: number | null | undefined): void
  • Sets a key-value pair identifier that will be included in all snapshots. The identifier can be used to add any data you wish.

    The key must be unique across your application. The key namespace is distinct for each user data type. Re-using the same key overwrites the previous value. The key is limited to MAX_USER_DATA_STRING_LENGTH characters.

    WARNING: The JavaScript exact integer numbers are limited to the range [-(2^53 - 1) ; 2^53 - 1] as defined by MAX_SAFE_INTEGER and MIN_SAFE_INTEGER. Numbers will be truncated to this range!

    A value of null will clear the data.

    This information is not persisted across application runs. Once the application is destroyed, the user data is cleared.

    Parameters

    • key: string

      Your unique key.

    • value: number | null | undefined

      Your value.

    Returns void

Static shutdownAgent

  • shutdownAgent(): void
  • Stops sending of beacons to the collector.

    No data will come from the agent while shut down. All other activities of the agent will continue, except for event sending.

    See also restartAgent

    Returns void

Static start

  • Initialize the agent with the given configuration (and pass in hybrid Agent Info).

    Parameters

    Returns Promise<void>

    A promise which resolves on successful agent initialization and fails otherwise.

Static startNextSession

  • startNextSession(): void
  • Starts next session and ends the current session.

    The session started using this API may be ended by inactivity timeout set in the Application Configuration, before the next call to this API.

    Returns void

Static startSessionFrame

  • Starts a Session Frame.

    Parameters

    • sessionFrameName: string

      The name of the session frame that will appear in the UI.

    Returns SessionFrame

    A SessionFrame object is returned which should be retained for further operations.

Static startTimer

  • startTimer(name: string): void
  • Starts a global timer with the given name.

    The name should contain only alphanumeric characters and spaces.

    Illegal characters shall be replaced by their ASCII hex value.

    Parameters

    • name: string

      The name of the timer.

    Returns void

Static stopTimer

  • stopTimer(name: string): void
  • Stops a global timer with the given name and reports it to the cloud.

    The name should contain only alphanumeric characters and spaces.

    Illegal characters shall be replaced by their ASCII hex value.

    Parameters

    • name: string

      The name of the timer.

    Returns void

Static takeScreenshot

  • takeScreenshot(): void
  • Asynchronously takes a screenshot of the current screen.

    If screenshots are disabled through AgentConfiguration.screenshotsEnabled or through the controller UI, this method does nothing.

    This will capture everything, including personal information, so you must be cautious of when to take the screenshot.

    These screenshots will show up in the Sessions screen for this user.

    The screenshots are taken on a background thread, compressed, and only non-redundant parts are uploaded, so it is safe to take many of these without impacting performance of your application.

    Returns void

Static trackCall

  • trackCall<T>(className: string, methodName: string, args: any[], executionCallback: () => T): T
  • trackCall<T>(className: string, methodName: string, args: any[], executionCallback: () => Promise<T>): Promise<T>
  • Reports that an info point has started.

    The InfoPoint decorator provides an easier way to add info points to your app. Consider using that as a first resort.

    See the example provided in the documentation from Instrumentation.

    Type parameters

    • T

    Parameters

    • className: string
    • methodName: string
    • args: any[]
    • executionCallback: () => T
        • (): T
        • Returns T

    Returns T

  • Type parameters

    • T

    Parameters

    • className: string
    • methodName: string
    • args: any[]
    • executionCallback: () => Promise<T>
        • (): Promise<T>
        • Returns Promise<T>

    Returns Promise<T>

Static unblockScreenshots

  • unblockScreenshots(): Promise<void>
  • Unblocks screenshot capture if it is currently blocked. Otherwise, this has no effect.

    If screenshots are disabled through AgentConfiguration.screenshotsEnabled or through the controller UI, this method has no effect.

    If screenshots are set to manual mode in the controller UI, this method unblocks for manual mode only.

    WARNING (1): This will unblock capture for the entire app. WARNING (2): Use the returned promise to determine when screenshots have effectively been unblocked.

    The user is expected to manage any possible nesting issues that may occur if blocking and unblocking occur in different code paths.

    Returns Promise<void>

    A promise which resolves when screenshots are effectively unblocked.

    See blockScreenshots

Legend

  • Constructor
  • Property
  • Method
  • Inherited constructor
  • Inherited property
  • Inherited method
  • Property
  • Method
  • Private property
  • Private method
  • Static property
  • Static method

Generated using TypeDoc