---
title: 'Log streaming: New Relic Logs'
summary: null
url: >-
  https://www.fastly.com/documentation/guides/integrations/logging-endpoints/log-management-and-observability/log-streaming-newrelic-logs
---

Fastly's [Real-Time Log Streaming](https://www.fastly.com/documentation/guides/integrations/streaming-logs/about-fastlys-realtime-log-streaming-features) feature can send log files to [New Relic Logs](https://newrelic.com/products/log-management).

> **NOTE:** 
>
> Fastly does not provide direct support for third-party services. Read [Fastly's Terms of Service](https://www.fastly.com/terms) for more information.
>
>

## Prerequisites

Before adding New Relic Logs as a logging endpoint for Fastly services, you will need to:

- Register for a [New Relic account](https://newrelic.com/signup).
- Obtain your [license key](https://docs.newrelic.com/docs/accounts/accounts-billing/account-setup/new-relic-license-key/).

## Adding New Relic Logs as a logging endpoint

Follow these instructions to add New Relic Logs as a logging endpoint:

### Cdn Services

1.   Review the information in our guide to [setting up remote log streaming](/guides/integrations/streaming-logs/setting-up-remote-log-streaming).

2. In the New Relic Logs area, click **Create endpoint**.
3. Fill out the **Create a New Relic Logs endpoint** fields as follows:
   -   In the **Name** field, enter a human-readable name for the endpoint.

   -   In the **Placement** area, select where the logging call should be placed in the generated VCL. Valid values are **Format Version Default** and **None**. Read our guide on [changing log placement](/guides/integrations/streaming-logs/changing-log-placement) for more information.

   -   In the **Log format** field, optionally enter an Apache-style string or VCL variables to use for log formatting. Consult the [example format section](#example-format) for details.

   - In the **License key / Insert key** field, enter your New Relic license key or Insert API key.
   - From the **Region** controls, select the region to stream logs to.
   -   *(Optional)* From the **Processing region** menu, select a geographic region where logs are processed before being sent to the logging endpoint. Our guide on [regional log aggregation](/guides/integrations/streaming-logs/setting-up-regional-log-aggregation) provides more information.

4.   Click **Create** to create the new logging endpoint.

5.   From the **Activate** menu, select **Activate on Production** to deploy your configuration changes.

### Example format

Data sent to New Relic Logs must be serialized as a JSON object. Here's the recommended example format string for sending data to New Relic Logs:

```json
{
  "timestamp": %{time.start.msec}V,
  "cache_status":"%{regsub(fastly_info.state, "^(HIT-(SYNTH)|(HITPASS|HIT|MISS|PASS|ERROR|PIPE)).*", "\\2\\3") }V",
  "client_ip":"%h",
  "client_device_type":"%{client.platform.hwtype}V",
  "client_os_name":"%{client.os.name}V",
  "client_os_version":"%{client.os.version}V",
  "client_browser_name":"%{client.browser.name}V",
  "client_browser_version":"%{client.browser.version}V",
  "client_as_name":"%{client.as.name}V",
  "client_as_number":"%{client.as.number}V",
  "client_connection_speed": "%{client.geo.conn_speed}V",
  "client_port": %{client.port}V,
  "client_rate_bps":%{client.socket.tcpi_delivery_rate}V,
  "client_recv_bytes":%{client.socket.tcpi_bytes_received}V,
  "client_requests_count":%{client.requests}V,
  "client_resp_body_size_write": %{resp.body_bytes_written}V,
  "client_resp_header_size_write": %{resp.header_bytes_written}V,
  "client_resp_ttfb": %{time.to_first_byte}V,
  "client_rtt_us":%{client.socket.tcpi_rtt}V,
  "content_type":"%{Content-Type}o",
  "domain": "%{Fastly-Orig-Host}i",
  "fastly_datacenter": "%{server.datacenter}V",
  "fastly_host": "%{server.hostname}V",
  "fastly_is_edge": %{if(fastly.ff.visits_this_service == 0, "true", "false")}V,
  "fastly_region": "%{server.region}V",
  "fastly_server": "%{json.escape(server.identity)}V",
  "host": "%v",
  "origin_host":"%v",
  "origin_name":"%{req.backend.name}V",
  "request":"%{req.request}V",
  "request_method":"%m",
  "request_accept_charset":"%{json.escape(req.http.Accept-Charset)}V",
  "request_accept_language":"%{json.escape(req.http.Accept-Language)}V",
  "request_referer":"%{json.escape(req.http.Referer)}V",
  "request_user_agent":"%{json.escape(req.http.User-Agent)}V",
  "resp_status":"%s",
  "response": "%{resp.response}V",
  "service_id":"%{req.service_id}V",
  "service_version": "%{req.vcl.version}V",
  "status":"%s",
  "time_start":"%{begin:%Y-%m-%dT%H:%M:%SZ}t",
  "time_end":"%{end:%Y-%m-%dT%H:%M:%SZ}t",
  "time_elapsed":%D,
  "tls_cipher":"%{json.escape(tls.client.cipher)}V",
  "tls_version":"%{json.escape(tls.client.protocol)}V",
  "url":"%{json.escape(req.url)}V",
  "user_agent":"%{json.escape(req.http.User-Agent)}V",
  "user_city":"%{client.geo.city.utf8}V",
  "user_country_code":"%{client.geo.country_code}V",
  "user_continent_code":"%{client.geo.continent_code}V",
  "user_region":"%{client.geo.region}V"
}
```

### Logging a timestamp

If a timestamp field is present in the Fastly log, it must be specified as milliseconds since Epoch to override the New Relic timestamp. If not included, Fastly will generate a timestamp.

### Using New Relic Instant Observability's prebuilt Fastly dashboard

[New Relic I/O](https://newrelic.com/platform/about-instant-observability) is an open source ecosystem of community-contributed quickstarts for hundreds of tools and technologies. We've worked with New Relic to develop a prebuilt dashboard that highlights certain key metrics we think are important and useful. Setting up the dashboard is easy and the code is [open source](https://github.com/newrelic/newrelic-quickstarts/tree/main/quickstarts/fastly) in case you want to customize it.

#### Configure your service to use the recommended expanded logging format

Since the prebuilt dashboard expects certain fields to be present, we encourage using the recommended logging format. That said, there is nothing to stop you from adding fields for your own purposes or to maintain backward compatibility with existing dashboards you've built. The dashboard won't break if you don't send some fields, but certain charts won't have data.

#### Install the Fastly dashboard

Follow these instructions to install the Fastly dashboard quickstart:

1. Select the Fastly dashboard quickstart from the [New Relic marketplace](https://developer.newrelic.com/instant-observability/).

   ![New Relic Marketplace](/img/new-relic-instant-observability-marketplace.png)

2. Click **Install quickstart**.

   ![New Relic Fastly Dashboard Page](/img/new-relic-instant-observability-fastly.png)

3. Click **Begin installation**.

   ![New Relic Fastly Dashboard Install Step 1](/img/new-relic-instant-observability-install-step-1.png)

4. Click **Done** or **Skip this step**.

   ![New Relic Fastly Dashboard Install Step 2](/img/new-relic-instant-observability-install-step-2.png)

5. Click **See your data**.

   ![New Relic Fastly Dashboard Install Step 3](/img/new-relic-instant-observability-install-step-3.png)

The Fastly dashboard appears.

![New Relic Fastly Dashboard](/img/new-relic-instant-observability-dashboard.png)

### Compute Services

1.   Review the information in our guide to [setting up remote log streaming for Compute](/guides/integrations/streaming-logs/setting-up-remote-log-streaming-for-compute). Additionally, our developer documentation provides more [information about logging](/guides/integrations/non-fastly-services/developer-guide-logging/) with Compute code written in our [supported languages](/reference/compute/sdks/).

2. In the New Relic Logs area, click **Create endpoint**.
3. Fill out the **Create a New Relic Logs endpoint** fields as follows:
   -   In the **Name** field, enter the endpoint name you specified in your Compute code. For example, in our [Rust code example](/guides/compute/developer-guides/rust/#logging), the name is `my_endpoint_name`.

   - In the **License key / Insert key** field, enter your New Relic license key or Insert API key.
4.   Click **Create** to create the new logging endpoint.

5.   From the **Activate** menu, select **Activate on Production** to deploy your configuration changes.

### Using New Relic Instant Observability's prebuilt Fastly dashboard

[New Relic I/O](https://newrelic.com/platform/about-instant-observability) is an open source ecosystem of a wide variety of community-contributed monitoring quickstarts. We worked with New Relic to develop a prebuilt dashboard that highlights key metrics. Because the code is [open source](https://github.com/newrelic/newrelic-quickstarts/tree/main/quickstarts/fastly), you can customize it.

![New Relic Fastly Dashboard](/img/new-relic-instant-observability-dashboard.png)

#### Configure your log messages

Data sent to New Relic Logs must be serialized as a JSON object. The JSON object should include the following fields:

- **`timestamp`:** when the request occurred. The timestamp must be specified as milliseconds since Epoch to override the New Relic timestamp. If timestamp is not included, Fastly will generate a timestamp.
- **`client_ip`:** the IP address of the client making the HTTP request.
- **`url`:** the URL of the request.
- **`resp_status`:** the HTTP status code of the request.
- **`client_resp_header_size_write`:** the size of the response header.
- **`client_resp_body_size_write`:** the size of the response body.
- **`fastly_datacenter`:** the three-character identifying code of the [FASTLY_POP](https://www.fastly.com/documentation/reference/compute/ecp-env/fastly-pop/) in which the current instance is running.
- **`time_elapsed`:** the time since the request started.
- **`service_id`:** the identifier for the [Fastly service](https://www.fastly.com/documentation/reference/compute/ecp-env/fastly-service-id/) that is processing the current request.

An example of the suggested more descriptive JSON log object is shown below.

```json
{
  "timestamp": 1661976797605,
  "cache_status": "ERROR",
  "client_ip": "127.0.0.1",
  "client_device_type": "Chromebook",
  "client_os_name": "Ubuntu",
  "client_os_version": "17.10 (Artful Aardvark)",
  "client_browser_name": "Firefox",
  "client_browser_version": "113.0",
  "client_as_name": "zayo bandwidth",
  "client_as_number": "1234",
  "client_connection_speed": "broadband",
  "client_port": 63850,
  "client_rate_bps": 0,
  "client_recv_bytes": 74,
  "client_requests_count": 1,
  "client_resp_body_size_write": 56789,
  "client_resp_header_size_write": 1234,
  "client_resp_ttfb": 1.342,
  "client_rtt_us": 6818,
  "content_type": "text/html; charset=utf-8",
  "domain": "example.com",
  "fastly_datacenter": "HNL",
  "fastly_host": "cache-hnl00001",
  "fastly_is_edge": true,
  "fastly_region": "US-Pacific",
  "fastly_server": "cache-hnl00001-HNL",
  "host": "example.com",
  "origin_host": "example.com",
  "origin_name": "n/a",
  "request": "GET",
  "request_method": "GET",
  "request_accept_charset": "utf-8",
  "request_accept_language": "en-US",
  "request_referer": "",
  "request_user_agent": "curl/7.68.0",
  "resp_status": "503",
  "response": "Backend unavailable, connection timeout",
  "service_id": "000q0j0WE0f00z0KEVj5I0",
  "service_version": "29",
  "status": "503",
  "time_start": "2023-05-18T23:21:52Z",
  "time_end": "2023-05-18T23:21:53Z",
  "time_elapsed": 237,
  "tls_cipher": "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256",
  "tls_version": "TLS 1.2",
  "url": "/",
  "user_agent": "curl/7.68.0",
  "user_city": "san francisco",
  "user_country_code": "US",
  "user_continent_code": "NA",
  "user_region": "CA"
}
```

While the prebuilt dashboard won't break if the JSON object doesn't include all of the expected fields, certain charts won't have data.

In addition to the suggested fields, you can include fields of your choosing in the JSON object for your own purposes or to maintain backward compatibility with existing dashboards you've built.

#### Install the Fastly dashboard

Follow these instructions to install the Fastly dashboard quickstart:

1. Select the Fastly dashboard quickstart from the [New Relic marketplace](https://developer.newrelic.com/instant-observability/).
2. Click **Install quickstart**.
3. Click **Begin installation**.
4. Click **Done** or **Skip this step**.
5. Click **See your data**. The Fastly dashboard appears.

## Related content

- [API reference: New Relic Logs streaming](https://www.fastly.com/documentation/reference/api/logging/new-relic/)
- [CLI reference: New Relic Logs streaming](https://www.fastly.com/documentation/reference/cli/logging/newrelic/)
