$npx -y skills add BagelHole/DevOps-Security-Agent-Skills --skill new-relicConfigure New Relic observability platform for infrastructure and application monitoring. Set up APM agents, create dashboards, configure alerts, and implement distributed tracing. Use when implementing full-stack observability with New Relic One.
| 1 | # New Relic |
| 2 | |
| 3 | Monitor applications and infrastructure with New Relic's observability platform. |
| 4 | |
| 5 | ## When to Use This Skill |
| 6 | |
| 7 | Use this skill when: |
| 8 | - Implementing full-stack observability |
| 9 | - Setting up APM for applications |
| 10 | - Monitoring infrastructure health |
| 11 | - Creating custom dashboards and alerts |
| 12 | - Implementing distributed tracing |
| 13 | |
| 14 | ## Prerequisites |
| 15 | |
| 16 | - New Relic account and license key |
| 17 | - Application access for APM agents |
| 18 | - Infrastructure access for host agents |
| 19 | |
| 20 | ## Infrastructure Agent |
| 21 | |
| 22 | ### Linux Installation |
| 23 | |
| 24 | ```bash |
| 25 | # Add repository and install |
| 26 | curl -Ls https://download.newrelic.com/install/newrelic-cli/scripts/install.sh | bash |
| 27 | |
| 28 | # Configure license key |
| 29 | sudo NEW_RELIC_API_KEY=<YOUR_API_KEY> NEW_RELIC_ACCOUNT_ID=<ACCOUNT_ID> /usr/local/bin/newrelic install |
| 30 | |
| 31 | # Or manual configuration |
| 32 | echo "license_key: YOUR_LICENSE_KEY" | sudo tee -a /etc/newrelic-infra.yml |
| 33 | sudo systemctl start newrelic-infra |
| 34 | ``` |
| 35 | |
| 36 | ### Docker |
| 37 | |
| 38 | ```yaml |
| 39 | # docker-compose.yml |
| 40 | version: '3.8' |
| 41 | |
| 42 | services: |
| 43 | newrelic-infra: |
| 44 | image: newrelic/infrastructure:latest |
| 45 | cap_add: |
| 46 | - SYS_PTRACE |
| 47 | privileged: true |
| 48 | pid: "host" |
| 49 | network_mode: "host" |
| 50 | environment: |
| 51 | - NRIA_LICENSE_KEY=${NEW_RELIC_LICENSE_KEY} |
| 52 | - NRIA_DISPLAY_NAME=docker-host |
| 53 | volumes: |
| 54 | - /:/host:ro |
| 55 | - /var/run/docker.sock:/var/run/docker.sock |
| 56 | ``` |
| 57 | |
| 58 | ### Kubernetes |
| 59 | |
| 60 | ```bash |
| 61 | # Using Helm |
| 62 | helm repo add newrelic https://helm-charts.newrelic.com |
| 63 | |
| 64 | helm install newrelic-bundle newrelic/nri-bundle \ |
| 65 | --namespace newrelic \ |
| 66 | --create-namespace \ |
| 67 | --set global.licenseKey=${NEW_RELIC_LICENSE_KEY} \ |
| 68 | --set global.cluster=my-cluster \ |
| 69 | --set newrelic-infrastructure.privileged=true \ |
| 70 | --set ksm.enabled=true \ |
| 71 | --set kubeEvents.enabled=true \ |
| 72 | --set logging.enabled=true |
| 73 | ``` |
| 74 | |
| 75 | ## APM Agents |
| 76 | |
| 77 | ### Node.js |
| 78 | |
| 79 | ```javascript |
| 80 | // At the very start of your application |
| 81 | require('newrelic'); |
| 82 | |
| 83 | // newrelic.js configuration |
| 84 | exports.config = { |
| 85 | app_name: ['My Application'], |
| 86 | license_key: process.env.NEW_RELIC_LICENSE_KEY, |
| 87 | distributed_tracing: { |
| 88 | enabled: true |
| 89 | }, |
| 90 | logging: { |
| 91 | level: 'info' |
| 92 | }, |
| 93 | error_collector: { |
| 94 | enabled: true, |
| 95 | ignore_status_codes: [404] |
| 96 | }, |
| 97 | transaction_tracer: { |
| 98 | enabled: true, |
| 99 | transaction_threshold: 'apdex_f', |
| 100 | record_sql: 'obfuscated' |
| 101 | } |
| 102 | }; |
| 103 | ``` |
| 104 | |
| 105 | ```bash |
| 106 | # Install agent |
| 107 | npm install newrelic |
| 108 | |
| 109 | # Run application |
| 110 | NEW_RELIC_LICENSE_KEY=xxx node -r newrelic app.js |
| 111 | ``` |
| 112 | |
| 113 | ### Python |
| 114 | |
| 115 | ```python |
| 116 | # newrelic.ini |
| 117 | [newrelic] |
| 118 | license_key = YOUR_LICENSE_KEY |
| 119 | app_name = My Application |
| 120 | distributed_tracing.enabled = true |
| 121 | transaction_tracer.enabled = true |
| 122 | error_collector.enabled = true |
| 123 | browser_monitoring.auto_instrument = true |
| 124 | ``` |
| 125 | |
| 126 | ```bash |
| 127 | # Install agent |
| 128 | pip install newrelic |
| 129 | |
| 130 | # Generate config file |
| 131 | newrelic-admin generate-config YOUR_LICENSE_KEY newrelic.ini |
| 132 | |
| 133 | # Run application |
| 134 | NEW_RELIC_CONFIG_FILE=newrelic.ini newrelic-admin run-program python app.py |
| 135 | |
| 136 | # Or with gunicorn |
| 137 | NEW_RELIC_CONFIG_FILE=newrelic.ini newrelic-admin run-program gunicorn app:app |
| 138 | ``` |
| 139 | |
| 140 | ### Java |
| 141 | |
| 142 | ```bash |
| 143 | # Download agent |
| 144 | curl -O https://download.newrelic.com/newrelic/java-agent/newrelic-agent/current/newrelic-java.zip |
| 145 | unzip newrelic-java.zip |
| 146 | |
| 147 | # Configure newrelic.yml |
| 148 | # license_key: YOUR_LICENSE_KEY |
| 149 | # app_name: My Application |
| 150 | |
| 151 | # Run with agent |
| 152 | java -javaagent:/path/to/newrelic.jar -jar myapp.jar |
| 153 | ``` |
| 154 | |
| 155 | ### Go |
| 156 | |
| 157 | ```go |
| 158 | package main |
| 159 | |
| 160 | import ( |
| 161 | "github.com/newrelic/go-agent/v3/newrelic" |
| 162 | "net/http" |
| 163 | ) |
| 164 | |
| 165 | func main() { |
| 166 | app, err := newrelic.NewApplication( |
| 167 | newrelic.ConfigAppName("My Application"), |
| 168 | newrelic.ConfigLicense("YOUR_LICENSE_KEY"), |
| 169 | newrelic.ConfigDistributedTracerEnabled(true), |
| 170 | ) |
| 171 | if err != nil { |
| 172 | panic(err) |
| 173 | } |
| 174 | |
| 175 | http.HandleFunc(newrelic.WrapHandleFunc(app, "/", indexHandler)) |
| 176 | http.ListenAndServe(":8080", nil) |
| 177 | } |
| 178 | |
| 179 | func indexHandler(w http.ResponseWriter, r *http.Request) { |
| 180 | txn := newrelic.FromContext(r.Context()) |
| 181 | txn.AddAttribute("user_id", "12345") |
| 182 | w.Write([]byte("Hello, World!")) |
| 183 | } |
| 184 | ``` |
| 185 | |
| 186 | ## Custom Instrumentation |
| 187 | |
| 188 | ### Custom Events |
| 189 | |
| 190 | ```python |
| 191 | import newrelic.agent |
| 192 | |
| 193 | # Record custom event |
| 194 | newrelic.agent.record_custom_event('OrderPlaced', { |
| 195 | 'order_id': '12345', |
| 196 | 'amount': 99.99, |
| 197 | 'customer_id': 'cust_001' |
| 198 | }) |
| 199 | ``` |
| 200 | |
| 201 | ### Custom Metrics |
| 202 | |
| 203 | ```python |
| 204 | import newrelic.agent |
| 205 | |
| 206 | # Record custom metric |
| 207 | newrelic.agent.record_custom_metric('Custom/OrderValue', 99.99) |
| 208 | |
| 209 | # With attributes |
| 210 | newrelic.agent.record_custom_metric('Custom/ProcessingTime', |
| 211 | processing_time, |
| 212 | {'unit': 'milliseconds'} |
| 213 | ) |
| 214 | ``` |
| 215 | |
| 216 | ### Custom Spans |
| 217 | |
| 218 | ```python |
| 219 | import newrelic.agent |
| 220 | |
| 221 | @newrelic.agent.function_trace(name='process_payment') |
| 222 | def process_payment(order_id, amount): |
| 223 | # This creates a custom span in the trac |