fix(monitoring): allow distinguishing data from different deployments in New Relic#1311
Conversation
✅ Deploy Preview for antenna-ssec canceled.
|
✅ Deploy Preview for antenna-preview canceled.
|
|
Warning Rate limit exceeded
You’ve run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Pull request overview
This PR restores deterministic per-environment New Relic app_name selection via config/newrelic.ini sections after finding that, in newrelic agent 12.1.0, NEW_RELIC_APP_NAME does not override a base [newrelic] app_name value—preventing demo/staging traffic from being attributed to the wrong NR entity.
Changes:
- Re-add explicit
app_namefor[newrelic:production]and introduce[newrelic:demo], both keyed byNEW_RELIC_ENVIRONMENT. - Remove the misleading
NEW_RELIC_APP_NAMEline from the production env template and document the agent behavior/precedence.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
config/newrelic.ini |
Adds [newrelic:demo] and restores per-env app_name for production; documents why app_name must live in env sections. |
.envs/.production/.django-example |
Removes NEW_RELIC_APP_NAME template line and adds guidance to use NEW_RELIC_ENVIRONMENT-selected ini sections for app naming. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| # more aggressive tracing via NEW_RELIC_* env vars at deploy time. | ||
| # | ||
| # NOTE: app_name override via NEW_RELIC_APP_NAME env var does NOT work in | ||
| # agent 12.1.0 — the base [newrelic] section's app_name wins even when the |
| [newrelic:demo] | ||
| app_name = Antenna Backend (Demo) | ||
| monitor_mode = true | ||
|
|
||
| [newrelic:production] |
| # app_name is NOT settable via env var (NEW_RELIC_APP_NAME is ignored by | ||
| # agent 12.1.0 when [newrelic] sets app_name). Use NEW_RELIC_ENVIRONMENT | ||
| # to select a [newrelic:<env>] section in config/newrelic.ini, which is |
Drops `app_name` from every `[newrelic*]` section in `config/newrelic.ini` and requires each deploy to set `NEW_RELIC_APP_NAME` in `.envs/.production/.django`. This is the only configuration shape that actually lets per-deploy app names work in `newrelic` agent 12.1.0. ## Why this design PR #1299 intended `NEW_RELIC_APP_NAME` to override per-env. Empirically that doesn't work when `[newrelic]` (or any `[newrelic:<env>]` matched by `NEW_RELIC_ENVIRONMENT`) sets `app_name` — the ini value wins and the env var is silently ignored. Verified in a deployed django container: ``` $ docker exec <c> newrelic-admin run-program python -c \ "from newrelic.core.config import global_settings; \ print(global_settings().app_name)" # env NEW_RELIC_APP_NAME='Antenna Backend (Demo)' # resolved 'AMI Backend' ← base ini wins ``` Remove the base `app_name` line and the env var resolves correctly: ``` # (same command, ini base app_name commented out) # resolved 'Antenna Backend (Demo)' ``` So the fix is to leave `app_name` unset everywhere in the ini and treat the env var as the canonical source. None of `[newrelic]`, `[newrelic:development]`, `[newrelic:staging]`, `[newrelic:demo]`, `[newrelic:production]` set app_name anymore — `NEW_RELIC_APP_NAME` in `.envs/.production/.django` defines it per deploy. ## Failure mode is visible, not silent If a deploy forgets to set `NEW_RELIC_APP_NAME`, the agent reports under the literal name `Python Application`. That is an easy-to-spot orphan in NR's APM list, not a silent merge into another env's entity. This is the opposite of the pre-fix behavior, which (combined with an NR account alias mapping `AMI Backend` → the production entity) caused unrelated deploys to silently merge into prod APM metrics. ## Suits dynamic preview stacks Per-PR / per-branch preview stacks can set `NEW_RELIC_APP_NAME` at spawn time without committing a new `[newrelic:<env>]` section to this repo for every ephemeral environment. ## Deploy coordination — required before merge Each long-lived environment must set `NEW_RELIC_APP_NAME` in its deploy-time `.envs/.production/.django` BEFORE this lands, otherwise it will start reporting under `Python Application`. Values to set: | Env | NEW_RELIC_APP_NAME | |-----|--------------------| | production | `Antenna Backend (live)` | | demo | `Antenna Backend (Demo)` | | staging | `AMI Backend (Staging)` | | any preview stack | `Antenna Backend (preview-<id>)` | Adding the env var on hosts where the ini still sets `app_name` is a no-op (the ini wins today), so it can be staged in advance of merging this PR without any risk. ## Test plan - [x] In a running django container, build a temp ini with no app_name anywhere + set `NEW_RELIC_APP_NAME` env var → `global_settings()` resolves to the env var value. - [x] Same with no env var set → resolves to `Python Application` (confirmed orphan, no silent merge). - [ ] After deploy: each env's `appName` in NR matches the value of its `NEW_RELIC_APP_NAME` env var; no env reports as `Python Application` or `AMI Backend`. - [ ] CI agent log shows `NR-Activate-Session/<expected app name>` per env. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2c877ca to
04b265b
Compare
Summary
Narrow follow-up to #1299. The
NEW_RELIC_APP_NAMEenv var is silently ignored bynewrelicagent 12.1.0 when any[newrelic*]section inconfig/newrelic.inisetsapp_name. The previous PR removed it from[newrelic:production]only and assumed the env var would supply it — but the base[newrelic]section still set it, so the env var was never consulted.This PR drops
app_namefrom every[newrelic*]section, makingNEW_RELIC_APP_NAMEin.envs/.production/.djangothe single source of truth. This is the only configuration shape that actually lets per-deploy app naming work in 12.1.0, and it suits the upcoming dynamic preview stacks (each preview sets its ownNEW_RELIC_APP_NAMEat spawn time, no repo churn).Evidence
Reproduced inside a deployed django container (agent 12.1.0):
Comment out the base
app_name = AMI Backendline in a temp ini and re-run with the same env var:Confirms the ini base entry — not the env var read path — is the blocker. Removing
app_namefrom the ini is the fix.Failure mode is visible, not silent
If a deploy forgets to set
NEW_RELIC_APP_NAME, the agent reports under the literal namePython Application. That is an easy-to-spot orphan in NR's APM list, not a silent merge into another env's entity. Verified:This is the opposite of the pre-fix behavior, which (combined with an NR account-side alias mapping
AMI Backend→ the production entity) caused unrelated deploys to silently merge into prod APM metrics. That issue is what surfaced this PR.Suits dynamic preview stacks
Per-PR / per-branch preview stacks set
NEW_RELIC_APP_NAMEat spawn time without committing a new[newrelic:<env>]section to this repo for every ephemeral environment.Deploy coordination — required before merge
Each long-lived environment must set
NEW_RELIC_APP_NAMEin its deploy-time.envs/.production/.djangobefore this lands. Suggested values (use theAntenna Backend (<env>)pattern for any new entity; the legacyAMI Backend (Staging)entity already exists in NR and can keep that name for history continuity if preferred):Antenna Backend (live)Antenna Backend (Demo)Antenna Backend (Staging)(new) orAMI Backend (Staging)(keep)Antenna Backend (preview-<id>)Adding the env var on hosts where the ini still sets
app_nameis a no-op today (ini wins), so it can be staged in advance of merging without risk.Test plan
app_nameanywhere + setNEW_RELIC_APP_NAMEenv var →global_settings()resolves to the env var value.Python Application(confirmed orphan, no silent merge).appNamein NR matches the value of itsNEW_RELIC_APP_NAMEenv var; no env reports asPython ApplicationorAMI Backend.NR-Activate-Session/<expected app name>per env.🤖 Generated with Claude Code