---
title: Install New Relic Ruby agent in GAE flexible environment
source: https://docs.newrelic.com/docs/apm/agents/ruby-agent/installation/install-new-relic-ruby-agent-gae-flexible-environment
---

With APM's [Ruby agent](https://docs.newrelic.com/docs/agents/ruby-agent/getting-started/introduction-new-relic-ruby), you can monitor applications that reside in the [Google App Engine (GAE) flexible environment](https://cloud.google.com/appengine/docs/flexible/ruby/). Adding New Relic to your GAE flex app gives you insight into the health and performance of your app and extends GAE with metrics you can view using solutions like [APM](https://docs.newrelic.com/docs/apm) and [browser monitoring](https://docs.newrelic.com/docs/browser/new-relic-browser/getting-started/introduction-new-relic-browser).

This document explains how to add New Relic to your GAE flex app using either of these methods:

-   Google App Engine's ["native mode"](https://docs.newrelic.com/docs/accounts-partnerships/partnerships/google-cloud-platform-gcp/google-app-engine-environment#native-mode) installation with a standard GAE runtime
-   Docker installation using a [custom runtime](https://cloud.google.com/appengine/docs/flexible/custom-runtimes/about-custom-runtimes)

The custom runtime method includes an example of deploying a Sinatra app. If you need specific libraries or headers, New Relic recommends using the custom runtime method.

## Deploy using GAE's native support [#native]

When using Google App Engine ["native mode"](https://docs.newrelic.com/docs/accounts-partnerships/partnerships/google-cloud-platform-gcp/google-app-engine-environment#native-mode) installation, you provide your app code and an `app.yaml` file. Google App Engine then deploys to a standard prebuilt Docker image.

To deploy with native support for Sinatra or Rails:

1.  Follow New Relic's standard procedures to [install the gem](https://docs.newrelic.com/docs/agents/ruby-agent/installation/install-new-relic-ruby-agent#Installing_the_Gem), including your license key.
2.  Install the Ruby agent [configuration file](https://docs.newrelic.com/docs/agents/ruby-agent/installation/install-new-relic-ruby-agent#Configuration_file).

Once the gem and configuration file have been installed, the Ruby agent can automatically monitor applications that reside in the GAE flexible environment. Wait until the deployment completes, then view your GAE flex app data in the [APM Summary page](https://docs.newrelic.com/docs/apm/applications-menu/monitoring/apm-overview-page).

## Build a custom runtime using Docker [#build-runtime]

> #### 💡 TIP
>
> If your Ruby app needs specific libraries or headers, New Relic recommends using the custom runtime method. In addition, New Relic recommends that you allow Google App Engine to handle health checks.

See [Google's documentation for building custom runtimes](https://cloud.google.com/appengine/docs/flexible/custom-runtimes/build). This example describes how to add New Relic to your GAE flex app by building a custom runtime for Docker. The example uses a Sinatra app for Ruby.

For more information about deploying and configuring your Ruby app in the GAE flexible environment, see:

-   [Google App Engine's documentation](https://cloud.google.com/appengine/docs/flexible/ruby/) for Ruby
-   [Google App Engine's tutorials](https://cloud.google.com/appengine/docs/flexible/ruby/tutorials) for Ruby

**1. Set up the GAE project and install dependencies**

1.  Follow standard procedures to install New Relic's Ruby agent, including your license key.
2.  Follow Google App Engine procedures for Ruby to create a new [Google Cloud Platform project](https://cloud.google.com/appengine/docs/flexible/ruby/managing-projects-apps-billing#create), create an App Engine application, and complete other prerequisites for the [Google Cloud SDK](http://cloud.google.com/appengine/docs/flexible/ruby/download).

    The Google Cloud SDK provides the `gcloud` command line tool to manage and deploy GAE apps.

**2. Configure your app.yaml**

The `app.yaml` configuration file is required for a GAE flexible environment app with a custom runtime. At a minimum, make sure it contains:

````yml
env: flex
runtime: custom
entrypoint: bundle exec ruby app.rb
```

````

**3. Configure a Dockerfile**

The [Dockerfile](http://docs.docker.com/engine/reference/builder/) defines the Docker image to be built and is required for a GAE flexible environment app. To create the recommended base image for apps monitored by the New Relic Ruby agent:

````dockerfile
FROM gcr.io/google-appengine/ruby:latest
```

````

**4. Build a Docker image**

Be sure to include the period at the end of the code, to indicate the current directory contains the build files.

````sh
docker build -f Dockerfile -t custom_ruby_app_container:latest .
```

After running this command, verify that you have a Docker image named `custom_ruby_app_container` and tagged `latest`.

````

**5. Deploy Docker image to initialized GAE flexible environment**

1.  To deploy your Docker image to your [initialized GAE flexible environment](https://cloud.google.com/sdk/docs/initializing), run the following command:

    ```sh
    gcloud app deploy
    ```
2.  Wait until the deployment completes.
3.  To open the app in the browser, run the following command:

    ```sh
    gcloud app browse
    ```
4.  To view your GAE flex app data in New Relic, go to the [APM Summary page](https://docs.newrelic.com/docs/apm/applications-menu/monitoring/apm-overview-page).

## Recommendation: Handle health checks [#health-checks]

Google App Engine sends [periodic health check requests](https://cloud.google.com/appengine/docs/flexible/ruby/how-instances-are-managed) to confirm that an instance has been successfully deployed, and to check that a running instance maintains a healthy status. A health check is an HTTP request to the URL `/_ah/health`.

If you create a custom runtime, your app must be able to handle a large number of health check requests. Otherwise, your app data may not display correctly in APM.

New Relic recommends that you [allow health checks for Ruby apps](https://cloud.google.com/appengine/docs/flexible/ruby/how-instances-are-managed#health_checking) so that Google can check that your service is up and balanced properly. However, if excessive health checks cause congested transaction traces, you can set the Ruby agent to ignore the health check requests.

-   To **handle** health checks, add a route for `_ah/health` in your app.
-   To **ignore** health check requests, set the `rules.ignore_url_regexes` config setting in the application’s Ruby agent config to include `'_ah/health'`.

## Get New Relic agent troubleshooting logs from GAE [#agent-logs]

Use these resources to troubleshoot your GAE flex environment app:

-   To connect to the GAE instance and start a shell in the Docker container running your code, see [Debugging an instance](https://cloud.google.com/appengine/docs/flexible/go/debugging-an-instance).
-   To redirect New Relic Ruby agent logs to [Stackdriver](http://cloud.google.com/logging/docs/view/logs_viewer_v2) in the [Cloud Platform Console](https://cloud.google.com/compute/docs/console), change the `newrelic.js` configuration file to:

    ```yml
    log_file_name: STDOUT
    ```
-   To view the logs, use the [Cloud Platform Console's Log Viewer](https://cloud.google.com/appengine/docs/flexible/php/writing-application-logs).
