> ## Documentation Index
> Fetch the complete documentation index at: https://docs.sawmills.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# New Relic Source

> Configure the New Relic source in Sawmills to receive metrics from the New Relic Metric API and Agent protocol on configurable HTTP endpoints.

## Supported Data Types

📈 **Metrics**

## Overview

The New Relic source accepts metrics from the New Relic Metric API and the New Relic Agent protocol. Metric API payloads are received on `metrics_path`, and Agent payloads use `agent_base_path` with a `method` query parameter.

## Configuration

| Field           | Type   | Default                                                           | Required | Description                                                                 |
| :-------------- | :----- | :---------------------------------------------------------------- | :------- | :-------------------------------------------------------------------------- |
| Name            | String | none                                                              | true     | Unique identifier within Sawmills.                                          |
| Endpoint        | String | `0.0.0.0:14275`                                                   | true     | HTTP listen address for New Relic payloads.                                 |
| Metrics Path    | String | `/metric/v1`                                                      | true     | Path for New Relic Metric API requests.                                     |
| Agent Base Path | String | `/agent_listener/invoke_raw_method`                               | true     | Path for New Relic Agent protocol requests.                                 |
| Agent Endpoint  | String | `https://collector.newrelic.com/agent_listener/invoke_raw_method` | true     | Upstream New Relic agent endpoint used to proxy `preconnect` and `connect`. |

## Send metrics to the collector

Point your app's New Relic endpoints at the Sawmills collector. You need to configure two environment variables:

| Variable                 | Controls                            | Format              | Example                                               |
| :----------------------- | :---------------------------------- | :------------------ | :---------------------------------------------------- |
| `NEW_RELIC_HOST`         | Java agent (timeslice metrics)      | `host:port`         | `<collector-id>.collectors.sawmills.ai:10000`         |
| `NEW_RELIC_METRICS_HOST` | Telemetry SDK (dimensional metrics) | `https://host:port` | `https://<collector-id>.collectors.sawmills.ai:10000` |

Both must be set. If you only set one, part of your telemetry bypasses Sawmills.
Your `<collector-id>` is shown in the Sawmills UI under your pipeline's collector details.

For a full Java app walkthrough, see [How to send data from a New Relic Java app](/docs/guide-send-data-from-newrelic-java-app).

Minimal Telemetry SDK example:

```java theme={null}
// NEW_RELIC_METRICS_HOST="https://<collector-id>.collectors.sawmills.ai:10000"
String host = System.getenv("NEW_RELIC_METRICS_HOST");
String licenseKey = System.getenv("NEW_RELIC_LICENSE_KEY");

MetricBatchSender sender = MetricBatchSender.create(
  MetricBatchSenderFactory.fromHttpImplementation(OkHttpPoster::new)
    .configureWith(licenseKey)
    .endpoint(new URL(host + "/metric/v1"))
    .build()
);

Attributes common = new Attributes()
  .put("service.name", appName)
  .put("environment", environment);

MetricBuffer buffer = new MetricBuffer(common);
buffer.addMetric(new Gauge(
  "service.response.time",
  0.5,
  System.currentTimeMillis(),
  new Attributes().put("cluster", "default").put("region", "us-east-1")
));

sender.sendBatch(buffer.createBatch());
```

### Metric API Format

Supported metric types:

* `gauge`
* `count` (requires `interval.ms`)
* `summary`

### Agent Protocol

Supported methods:

* `preconnect`
* `connect`
* `metric_data`

Agent metrics are converted to Summary metrics and include:

* `count`
* `sum`
* `min` and `max` (as quantiles 0 and 1)
* `sawmills.scope` attribute when present
* `sawmills.exclusive_time` attribute
* `sawmills.sum_squares` attribute

## Example Payloads

### Metric API

```json theme={null}
[
  {
    "common": {
      "timestamp": 1700000000000,
      "interval.ms": 10000,
      "attributes": {"host.name": "server1"}
    },
    "metrics": [
      {
        "name": "service.response.time",
        "type": "gauge",
        "value": 0.5
      },
      {
        "name": "service.requests",
        "type": "count",
        "value": 100
      }
    ]
  }
]
```

### Agent (metric\_data)

```json theme={null}
["agent-run-id", 1700000000, 1700000060, [
  [{"name": "WebTransaction/Go/handler"}, [10, 5.5, 3.2, 0.1, 2.5, 15.0]],
  [{"name": "Datastore/MySQL/query", "scope": "WebTransaction/Go/handler"}, [5, 0.5, 0.5, 0.05, 0.2, 0.1]]
]]
```
