This page applies to an earlier version of the AppDynamics App IQ Platform.
See the latest version of the documentation.

Skip to end of metadata
Go to start of metadata

If you are using Nginx as your web container, or you are currently using, or willing to use, Nginx as a reverse proxy (see here for more information), you can use a container substitution module to automatically inject the JavaScript Agent into your pages. The module intercepts the response object as it is being returned and makes a string substitution.

This module is an extension and is not necessarily built in Nginx by default. The build must be enabled with the --with-http_sub_module configuration parameter. Check your version to make sure it is available.

Download the Agent

You must first download the JavaScript Agent from the Configuration screen.

  1. Open the browser application in which you are interested.

  2. From the left navigation menu, select Configuration

  3. Click the Configure and download JavaScript Agent.

  4. For the JavaScript hosting option, select I will host all the JavaScript agent files.

  5. Click Download to download the JavaScript Agent.

  6. Place the file somewhere accessible to the Nginx instance. The name of the saved file should be adrum.js.

Configure Nginx

The ngx_http_sub_module module is a filter that modifies a response by replacing one specified string by another. You can use this feature to have the server automatically inject the header portion of the JavaScript Agent into a served page. For more information on the process, see the Nginx documentation, Module ngx_http_sub_module.

For example, modify the location context to replace the <head> tag with the <head> tag and the JavaScript Agent scripts.

Sample Nginx Configuration

location / {
    sub_filter      <head>
        '<head><script>window["adrum-app-key"]="EUM-FOO-BAR";window["adrum-start-time"]=new Date().getTime();</script><script type="text/javascript" src="http://cdn.appdynamics.com/adrum/adrum-latest.js"></script>';
    sub_filter_once on;

Where /adrum.js is the path to a copy of the adrum file that is accessible to the server. Note the timer initialization: <script>window['adrum-start-time'] = new Date().getTime();</script>. Keeping this as close as possible to the top of the document, preferably right after the <head> tag, ensures the best possible timings.

If you use <meta> tags, you should place them right after your <head> tag, and then place the JavaScript Agent directly after the last <meta> tag. This can avoid issues with some versions of IE.

You may need to escape some characters, depending on your platform. For example, on MacOS:

location / {
    sub_filter      <head>
        '<head><script>window[\'adrum-start-time\'] = new Date().getTime();</script><script src="/adrum.js"></script>';
    sub_filter_once on;

This Nginx module is often used for adding the Google Analytics script.  Be careful not to overwrite any existing GA script when you do this.

Possible variations on the script string can be found in Customize the JavaScript Agent.