> ## 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.

# How to send data from a New Relic Java app

> Route telemetry from a Java application using the New Relic agent and Telemetry SDK through the Sawmills Collector with environment variable configuration.

This guide shows how to route both New Relic metric paths from a Java app through Sawmills.
For collector endpoint exposure, first complete [How to send data to the Sawmills collector](/docs/send-data-to-collector).

## Prerequisites

* A running **Sawmills Collector** with a [New Relic source](/docs/source-new-relic) configured
* A **New Relic license key**
* A Java app instrumented with the New Relic Java agent and/or Telemetry SDK

## Environment Variables

Set both variables to route all telemetry through Sawmills. If you only set one, part of your data bypasses Sawmills.

| 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` |

Your `<collector-id>` is shown in the Sawmills UI under your pipeline's collector details.

<Warning>
  Setting only one of these variables causes partial routing — some telemetry will go directly to New Relic instead of through Sawmills.
</Warning>

## Configure the Java app

```bash theme={null}
export NEW_RELIC_LICENSE_KEY="<your-license-key>"
export NEW_RELIC_HOST="<collector-id>.collectors.sawmills.ai:10000"
export NEW_RELIC_METRICS_HOST="https://<collector-id>.collectors.sawmills.ai:10000"
```

For Kubernetes, inject both values from a ConfigMap:

```yaml theme={null}
env:
  - name: NEW_RELIC_LICENSE_KEY
    valueFrom:
      secretKeyRef:
        name: newrelic-license
        key: license_key
  - name: NEW_RELIC_HOST
    valueFrom:
      configMapKeyRef:
        name: newrelic-config
        key: NEW_RELIC_HOST
  - name: NEW_RELIC_METRICS_HOST
    valueFrom:
      configMapKeyRef:
        name: newrelic-config
        key: NEW_RELIC_METRICS_HOST
```

Restart the deployment after changes:

```bash theme={null}
kubectl rollout restart deployment/<your-app>
```

## Verify

1. Check application logs for connection to your Sawmills collector endpoint.
2. Validate metrics in New Relic:

```sql theme={null}
SELECT count(*) FROM Metric WHERE metricName LIKE 'system.%' SINCE 5 minutes ago
```

## Troubleshooting

| Symptom                               | Fix                                                                             |
| :------------------------------------ | :------------------------------------------------------------------------------ |
| Only some metrics go through Sawmills | Set **both** `NEW_RELIC_HOST` and `NEW_RELIC_METRICS_HOST`                      |
| Dimensional metrics fail              | Use a base URL only for `NEW_RELIC_METRICS_HOST` — don't append `/metric/v1`    |
| No data arrives                       | Verify DNS reachability to `<collector-id>.collectors.sawmills.ai` from the app |
| Changes not taking effect             | Restart the deployment after updating env vars                                  |

## Related Docs

* [New Relic Source](/docs/source-new-relic)
* [How to send data to the Sawmills collector](/docs/send-data-to-collector)
* [New Relic Destination](/docs/destination-new-relic)
