Enable APM Browser Agent Injection

Prerequisites

  • You need to acquire a public datakey that is generated when the APM domain is created.

    The public data key can be obtained doing the following:

    1. Open the navigation menu, click Observability & Management. Under Application Performance Monitoring, click Administration.

      On the Administration page, select the desired compartment and APM domain.

    2. Click on Data Keys under Resources to list the data keys.

      If no data key exists, then click on Generate Data Key and select the Public Data Key.

    3. Click on Copy which it's next to a data key of type Public to retrieve the value. This value will be used later on.

    For more details, see Obtain Data Upload Endpoint and Data Keys.

Enable via the Installer

Starting with the APM Agent version 1.6, you can enable APM Browser Agent injection when the agent is provisioned using the -enable-browser-agent-injection option.

Example:

java -jar apm-java-agent-installer-1.6 provision-agent -destination=/example/path/destination -service-name=example_apm_service -private-data-key=ExamplePrivateDataKey -data-upload-endpoint=https://dataUploadEndpoint.com -enable-browser-agent-injection -public-data-key=ExamplePublicDataKey

Where ExamplePublicDataKey would be replaced with the public data key retrieved from OCI Console earlier at step 3 during the prerequisites.

The Java agent will automatically be configured to perform browser agent injection on startup.

To view the help information when provisioning the agent, use the -help option. For example:

java -jar ./apm-java-agent-installer-<version>.jar provision-agent -help
Usage: 
apm-java-agent-installer-<version>.jar provision-agent [options ...] 

options:
...
...
   -enable-browser-agent-injection
       Enables the APM Agent to automatically inject the browser agent into HTML
       pages.  Make sure '-public-data-key' is also set, otherwise injection will
       not be enabled until one is provided.

   -public-data-key=<public_data_key>
       APM Agent public data key for Appserver Agents. This property is required
       for the injected browser agent to connect to the Oracle APM Cloud, and it
       is specific to your APM Cloud Domain.
...
...

For the complete list of options, see Help Usage Information.

Enable Manually

If you are upgrading from an older APM Agent version, or you did not enable the browser agent injection via the installer, you will need to enable this feature manually after the upgrade or install is performed.

  • Navigate to your existing oracle-apm-agent/config directory. From there, step into the directory for the latest version that you upgraded to.

  • In AgentConfig.properties file, the following two properties need to be uncommented (# symbol needs to be removed), and updated:
    • com.oracle.apm.agent.rum.enable.injection: Remove the # for this property and set the value to true
    • com.oracle.apm.agent.public.data.key: Remove the # for this property and set the value to the public data key acquired from step 3 during the prerequisites earlier.
    After above properties are updated, the file will look similar to the following:
    # APM Agent public data key. This property is required for the injected Browser Agent to connect to server, which can be
    # obtained at APM service sign up.
    # 
    ... 
    ...
    ...
    #--------------------------- Start of Browser Agent (RUM) Injection Properties---------------------------------------
    # Enables browser agent injection.
    # Once enabled, the agent will inject a few lines of JavaScript code into the HTTP pages served by this AppServer.
    # It is recommended to test the application and exclude any pages that may be adversely affected by this injection.
    # See "Configure APM Browser Agent Injection using APM Java Agent" in the service documentation for more details.
    com.oracle.apm.agent.rum.enable.injection=true
    
    # APM Agent public data key. This property is required for the injected Browser Agent to connect to server, which can be
    # obtained at APM service sign up.
    com.oracle.apm.agent.public.data.key=ExamplePublicDataKey

The APM Java Agent should now be configured to begin performing APM Browser Agent injection.