> ## 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 Python app

> Route telemetry from a Python application using the New Relic agent through the Sawmills Collector with a single environment variable.

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

> **Note:** This guide covers the New Relic Python APM language agent (and,
> optionally, the standalone Telemetry SDK). It does not cover the New Relic
> Infrastructure agent. For Infrastructure setup, see [New Relic Infrastructure
> agent](/docs/guide-send-data-from-newrelic-infrastructure-agent).

## Prerequisites

* A running **Sawmills Collector** with a [New Relic source](/docs/source-new-relic) configured
* A **New Relic license key**
* A Python app instrumented with the New Relic Python agent (`newrelic`)

## Environment Variables

Unlike the Java agent — which splits timeslice and dimensional metrics across
two hosts — the New Relic **Python** agent sends its telemetry to a single
host, so one variable, `NEW_RELIC_HOST`, points the agent at Sawmills.

| Variable                | Controls                                        | Format | Example                                 |
| :---------------------- | :---------------------------------------------- | :----- | :-------------------------------------- |
| `NEW_RELIC_HOST`        | Python APM agent connection (timeslice metrics) | `host` | `<collector-id>.collectors.sawmills.ai` |
| `NEW_RELIC_LICENSE_KEY` | Authentication to New Relic                     | key    | `eu01xx...NRAL`                         |

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

<Note>
  The New Relic source processes the APM agent's **timeslice metrics**
  (`metric_data`) and forwards them to New Relic. Other APM payloads the agent
  sends over this connection — transaction traces, custom/analytics events,
  error data, and span events — are acknowledged by the collector but **not**
  forwarded. Route through Sawmills for APM metrics; if you depend on traces,
  events, or errors in New Relic, those are not preserved on this path today.
</Note>

<Warning>
  `NEW_RELIC_HOST` for the Python agent is a **hostname only** — do not include
  a scheme (`https://`) or a `:port` suffix. The Python agent does **not** read
  `NEW_RELIC_METRICS_HOST` (that variable is Java/Telemetry-SDK only); setting
  it here has no effect.
</Warning>

### Port

The Sawmills collector receives the New Relic protocols on a dedicated port
(the source's default is `14275`; your collector may differ). Find the exact
value under **New Relic ingestion endpoints → APM agent** in the collector
details in the Sawmills UI — copy the `host:port` shown there.

The Python agent takes the host and port as **separate** settings and defaults
to `443` when no port is given, so set the port explicitly to match your
collector endpoint. In `newrelic.ini`:

```ini theme={null}
[newrelic]
host = <collector-id>.collectors.sawmills.ai
port = 14275
```

Or via environment variable:

```bash theme={null}
export NEW_RELIC_PORT="14275"
```

## Configure the Python app

```bash theme={null}
export NEW_RELIC_LICENSE_KEY="<your-license-key>"
export NEW_RELIC_HOST="<collector-id>.collectors.sawmills.ai"
# Port shown for your collector's New Relic APM ingestion endpoint (default 14275):
export NEW_RELIC_PORT="14275"
```

Start the app under the New Relic admin wrapper so the agent is initialized:

```bash theme={null}
NEW_RELIC_CONFIG_FILE=newrelic.ini newrelic-admin run-program python your_app.py
```

For Kubernetes, inject the values from a ConfigMap and Secret:

```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
  # Port of your collector's New Relic APM ingestion endpoint (default 14275):
  - name: NEW_RELIC_PORT
    valueFrom:
      configMapKeyRef:
        name: newrelic-config
        key: NEW_RELIC_PORT
```

Restart the deployment after changes:

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

## Telemetry SDK (optional)

If your app uses the standalone **New Relic Telemetry SDK for Python**
(`newrelic-telemetry-sdk`) to send dimensional metrics directly to the Metric
API — separate from the APM agent — point its client host at the collector when
you construct it:

```python theme={null}
from newrelic_telemetry_sdk import MetricClient

client = MetricClient(
    license_key="<your-license-key>",
    host="<collector-id>.collectors.sawmills.ai",
    port=14275,  # your collector's New Relic endpoint port — the SDK defaults to 443
)
```

Most Python APM users do not use the Telemetry SDK; skip this section if you
only instrument with the `newrelic` agent.

## Verify

1. Check application logs for the agent connecting to your Sawmills collector
   endpoint (look for a line reporting the reporting host on agent startup).
2. Validate data in New Relic. The New Relic source forwards only the APM
   agent's `metric_data` (timeslice metrics), which New Relic stores as
   `Metric` — so query the `Metric` type, not `Transaction`:

```sql theme={null}
SELECT count(*) FROM Metric WHERE appName = '<your-app-name>' SINCE 5 minutes ago
```

## Troubleshooting

| Symptom                         | Fix                                                                                         |
| :------------------------------ | :------------------------------------------------------------------------------------------ |
| No data arrives                 | Verify DNS reachability to `<collector-id>.collectors.sawmills.ai` from the app             |
| Agent can't connect / TLS error | Ensure `NEW_RELIC_HOST` is a **hostname only** (no `https://`, no `:port`)                  |
| Connecting on the wrong port    | Set `port` in `newrelic.ini` or `NEW_RELIC_PORT` — not a `:port` suffix on `NEW_RELIC_HOST` |
| Agent never initializes         | Start the app with `newrelic-admin run-program`, or `import newrelic.agent; initialize()`   |
| Changes not taking effect       | Restart the deployment after updating env vars                                              |

## Related Docs

* [New Relic Source](/docs/source-new-relic)
* [New Relic Java App](/docs/guide-send-data-from-newrelic-java-app)
* [New Relic Infrastructure agent](/docs/guide-send-data-from-newrelic-infrastructure-agent)
* [How to send data to the Sawmills collector](/docs/send-data-to-collector)
* [New Relic Destination](/docs/destination-new-relic)
