SiamCafe.net Blog
Technology

New Relic One Technical Debt Management วดและจัดการ Technical Debt ด้วย Data

new relic one technical debt management
New Relic One Technical Debt Management | SiamCafe Blog
2025-10-16· อ. บอม — SiamCafe.net· 1,299 คำ

Technical Debt ?????????????????????

Technical Debt ?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????? optimal ??????????????????????????????????????????????????? ???????????????????????????????????????????????????????????????????????? software ??????????????? deliver ??????????????????????????????????????????????????????????????? ???????????????????????? "????????????????????????" ???????????????????????? maintenance cost, bugs, performance issues ???????????????????????????

??????????????????????????? Technical Debt Code debt (code ?????????????????????, ??????????????? tests, naming ???????????????), Architecture debt (monolith ?????????????????????????????? microservices, tight coupling), Infrastructure debt (outdated dependencies, manual deployments), Documentation debt (??????????????? docs, docs ????????? update), Test debt (coverage ?????????, flaky tests)

New Relic One ???????????? observability platform ????????????????????????????????????????????????????????? technical debt ???????????? application performance metrics, error rates, deployment frequency, code-level insights ?????????????????????????????????????????????????????? debt ????????? prioritize ????????????????????????????????? data-driven

????????????????????? New Relic One ?????????????????? Debt Tracking

Setup New Relic ???????????????????????????????????? technical debt

# === New Relic One Setup for Technical Debt ===

# 1. Install New Relic Agent (Node.js)
npm install newrelic
cat > newrelic.js << 'EOF'
'use strict';
exports.config = {
  app_name: ['MyApp-Production'],
  license_key: process.env.NEW_RELIC_LICENSE_KEY,
  logging: { level: 'info' },
  allow_all_headers: true,
  attributes: {
    exclude: [
      'request.headers.cookie',
      'request.headers.authorization',
    ],
  },
  distributed_tracing: { enabled: true },
  error_collector: {
    enabled: true,
    ignore_status_codes: [404],
  },
  custom_insights_events: { enabled: true },
  transaction_tracer: {
    enabled: true,
    transaction_threshold: 'apdex_f',
    record_sql: 'obfuscated',
  },
};
EOF

# 2. Install Infrastructure Agent (Linux)
curl -Ls https://download.newrelic.com/install/newrelic-cli/scripts/install.sh | \
  bash && sudo NEW_RELIC_API_KEY=NRAK-xxx \
  NEW_RELIC_ACCOUNT_ID=12345 \
  /usr/local/bin/newrelic install

# 3. Custom Events for Debt Tracking
cat > debt_tracker.js << 'JSEOF'
const newrelic = require('newrelic');

// Track technical debt events
function trackDebtItem(item) {
  newrelic.recordCustomEvent('TechnicalDebt', {
    category: item.category,    // 'code', 'architecture', 'infra', 'test'
    severity: item.severity,    // 'critical', 'high', 'medium', 'low'
    component: item.component,
    description: item.description,
    estimatedHours: item.estimatedHours,
    createdDate: item.createdDate,
    assignee: item.assignee,
  });
}

// Track dependency vulnerabilities
function trackVulnerability(vuln) {
  newrelic.recordCustomEvent('DependencyVuln', {
    package: vuln.package,
    currentVersion: vuln.currentVersion,
    latestVersion: vuln.latestVersion,
    severity: vuln.severity,
    cve: vuln.cve,
  });
}

// Track code complexity
function trackComplexity(metrics) {
  newrelic.recordCustomEvent('CodeComplexity', {
    file: metrics.file,
    cyclomaticComplexity: metrics.complexity,
    linesOfCode: metrics.loc,
    duplicateLines: metrics.duplicates,
    testCoverage: metrics.coverage,
  });
}

module.exports = { trackDebtItem, trackVulnerability, trackComplexity };
JSEOF

echo "New Relic configured for debt tracking"

????????? Technical Debt ???????????? Metrics

Metrics ??????????????????????????? technical debt

#!/usr/bin/env python3
# debt_metrics.py ??? Technical Debt Metrics
import json
import logging
from typing import Dict, List

logging.basicConfig(level=logging.INFO)
logger = logging.getLogger("metrics")

class TechnicalDebtMetrics:
    def __init__(self):
        pass
    
    def dora_metrics(self):
        """DORA metrics indicate tech debt level"""
        return {
            "deployment_frequency": {
                "elite": "Multiple deploys per day",
                "high": "Once per day to once per week",
                "medium": "Once per week to once per month",
                "low": "Less than once per month",
                "current": "3x per week",
                "target": "Daily",
                "debt_indicator": "Low frequency = high deployment debt",
            },
            "lead_time_for_changes": {
                "elite": "Less than 1 hour",
                "high": "1 day to 1 week",
                "medium": "1 week to 1 month",
                "low": "More than 1 month",
                "current": "3 days",
                "target": "< 1 day",
                "debt_indicator": "Long lead time = complex, coupled codebase",
            },
            "change_failure_rate": {
                "elite": "0-15%",
                "high": "16-30%",
                "medium": "31-45%",
                "low": "46-60%",
                "current": "22%",
                "target": "< 15%",
                "debt_indicator": "High failure rate = test debt, quality issues",
            },
            "mttr": {
                "elite": "Less than 1 hour",
                "high": "Less than 1 day",
                "medium": "1 day to 1 week",
                "low": "More than 1 week",
                "current": "4 hours",
                "target": "< 1 hour",
                "debt_indicator": "Long MTTR = observability debt, complex architecture",
            },
        }
    
    def code_health_metrics(self):
        return {
            "test_coverage": {"current": 62, "target": 80, "unit": "%", "debt": "test"},
            "cyclomatic_complexity_avg": {"current": 18, "target": 10, "unit": "per function", "debt": "code"},
            "duplicate_code_pct": {"current": 8.5, "target": 3, "unit": "%", "debt": "code"},
            "outdated_dependencies": {"current": 23, "target": 0, "unit": "packages", "debt": "infra"},
            "critical_vulns": {"current": 3, "target": 0, "unit": "CVEs", "debt": "security"},
            "api_response_p99": {"current": 850, "target": 500, "unit": "ms", "debt": "performance"},
            "error_rate": {"current": 2.3, "target": 0.5, "unit": "%", "debt": "quality"},
        }
    
    def debt_score(self):
        """Calculate overall technical debt score (0-100, lower is better)"""
        metrics = self.code_health_metrics()
        scores = []
        for name, m in metrics.items():
            if m["target"] == 0:
                score = min(100, m["current"] * 10)
            elif m["current"] > m["target"]:
                score = min(100, (m["current"] / m["target"] - 1) * 100)
            else:
                score = 0
            scores.append(score)
        return round(sum(scores) / len(scores), 1)

metrics = TechnicalDebtMetrics()
dora = metrics.dora_metrics()
print("DORA Metrics:")
for name, info in dora.items():
    print(f"  {name}: {info['current']} (target: {info['target']})")

health = metrics.code_health_metrics()
print("\nCode Health:")
for name, info in health.items():
    status = "OK" if info["current"] <= info["target"] else "DEBT"
    print(f"  [{status}] {name}: {info['current']}{info['unit']} (target: {info['target']})")

print(f"\nOverall Debt Score: {metrics.debt_score()}/100")

Dashboard ????????? Visualization

??????????????? New Relic dashboard ?????????????????? debt visibility

# === New Relic NRQL Queries for Debt Dashboard ===

# 1. Technical Debt Overview Dashboard
cat > dashboard_queries.nrql << 'EOF'
-- Widget 1: Debt Items by Category (Pie Chart)
SELECT count(*) FROM TechnicalDebt
FACET category SINCE 30 days ago

-- Widget 2: Debt Trend Over Time (Line Chart)
SELECT count(*) FROM TechnicalDebt
FACET severity TIMESERIES 1 week SINCE 90 days ago

-- Widget 3: Error Rate Trend (Line Chart)
SELECT percentage(count(*), WHERE error IS true)
FROM Transaction TIMESERIES AUTO SINCE 30 days ago

-- Widget 4: Deployment Frequency (Billboard)
SELECT count(*) as 'Deployments'
FROM Deployment SINCE 30 days ago

-- Widget 5: P99 Response Time (Line Chart)
SELECT percentile(duration, 99) FROM Transaction
WHERE appName = 'MyApp-Production'
TIMESERIES AUTO SINCE 7 days ago

-- Widget 6: Outdated Dependencies (Table)
SELECT package, currentVersion, latestVersion, severity
FROM DependencyVuln SINCE 1 day ago
ORDER BY severity

-- Widget 7: Code Complexity Hotspots (Bar Chart)
SELECT max(cyclomaticComplexity) FROM CodeComplexity
FACET file SINCE 7 days ago LIMIT 20

-- Widget 8: Test Coverage by Component (Bar Chart)
SELECT latest(testCoverage) FROM CodeComplexity
FACET component SINCE 1 day ago

-- Widget 9: MTTR (Billboard)
SELECT average(duration) as 'Avg MTTR (min)'
FROM IncidentResolution SINCE 30 days ago

-- Widget 10: Change Failure Rate (Billboard)
SELECT percentage(count(*), WHERE outcome = 'failure')
as 'Change Failure Rate'
FROM Deployment SINCE 30 days ago
EOF

# 2. Create Dashboard via NerdGraph API
cat > create_dashboard.sh << 'BASH'
#!/bin/bash
API_KEY="NRAK-your-api-key"

curl -X POST https://api.newrelic.com/graphql \
  -H "Content-Type: application/json" \
  -H "API-Key: $API_KEY" \
  -d '{
    "query": "mutation { dashboardCreate(accountId: 12345, dashboard: { name: \"Technical Debt Dashboard\", permissions: PRIVATE, pages: [{ name: \"Overview\", widgets: [{ title: \"Debt by Category\", layout: { column: 1, row: 1, width: 4, height: 3 }, rawConfiguration: { nrqlQueries: [{ accountIds: [12345], query: \"SELECT count(*) FROM TechnicalDebt FACET category SINCE 30 days ago\" }] } }] }] }) { entityResult { guid } } }"
  }'

echo "Dashboard created"
BASH

echo "Dashboard queries ready"

Automated Debt Detection

????????????????????? technical debt ???????????????????????????

#!/usr/bin/env python3
# debt_detector.py ??? Automated Technical Debt Detection
import json
import logging
from typing import Dict, List

logging.basicConfig(level=logging.INFO)
logger = logging.getLogger("detector")

class DebtDetector:
    def __init__(self):
        self.rules = []
        self.findings = []
    
    def add_rule(self, rule):
        self.rules.append(rule)
    
    def detect(self, metrics):
        for rule in self.rules:
            metric_value = metrics.get(rule["metric"])
            if metric_value is None:
                continue
            
            triggered = False
            if rule["operator"] == ">" and metric_value > rule["threshold"]:
                triggered = True
            elif rule["operator"] == "<" and metric_value < rule["threshold"]:
                triggered = True
            
            if triggered:
                self.findings.append({
                    "rule": rule["name"],
                    "metric": rule["metric"],
                    "value": metric_value,
                    "threshold": rule["threshold"],
                    "severity": rule["severity"],
                    "recommendation": rule["recommendation"],
                })
        
        return self.findings
    
    def prioritize(self):
        severity_order = {"critical": 0, "high": 1, "medium": 2, "low": 3}
        return sorted(self.findings, key=lambda x: severity_order.get(x["severity"], 4))

# Setup detector
detector = DebtDetector()

# Detection rules
detector.add_rule({
    "name": "High Error Rate",
    "metric": "error_rate_pct",
    "operator": ">",
    "threshold": 1.0,
    "severity": "critical",
    "recommendation": "Fix top error sources, add error handling, increase test coverage",
})
detector.add_rule({
    "name": "Slow Response Time",
    "metric": "p99_latency_ms",
    "operator": ">",
    "threshold": 500,
    "severity": "high",
    "recommendation": "Profile slow endpoints, add caching, optimize database queries",
})
detector.add_rule({
    "name": "Low Test Coverage",
    "metric": "test_coverage_pct",
    "operator": "<",
    "threshold": 70,
    "severity": "high",
    "recommendation": "Add unit tests for critical paths, enforce coverage in CI",
})
detector.add_rule({
    "name": "High Complexity",
    "metric": "avg_cyclomatic_complexity",
    "operator": ">",
    "threshold": 15,
    "severity": "medium",
    "recommendation": "Refactor complex functions, extract methods, simplify conditionals",
})
detector.add_rule({
    "name": "Outdated Dependencies",
    "metric": "outdated_deps_count",
    "operator": ">",
    "threshold": 10,
    "severity": "medium",
    "recommendation": "Run dependency update, use Dependabot/Renovate for automation",
})

# Current metrics
current_metrics = {
    "error_rate_pct": 2.3,
    "p99_latency_ms": 850,
    "test_coverage_pct": 62,
    "avg_cyclomatic_complexity": 18,
    "outdated_deps_count": 23,
}

findings = detector.detect(current_metrics)
prioritized = detector.prioritize()

print(f"Debt Detection: {len(findings)} issues found")
for f in prioritized:
    print(f"\n  [{f['severity'].upper()}] {f['rule']}")
    print(f"    Value: {f['value']} (threshold: {f['threshold']})")
    print(f"    Fix: {f['recommendation']}")

Remediation Strategy

????????????????????????????????????????????? technical debt

# === Debt Remediation Strategy ===

cat > remediation_plan.yaml << 'EOF'
technical_debt_remediation:
  framework:
    name: "20% Rule"
    description: "?????????????????? 20% ????????? sprint capacity ?????????????????? debt reduction"
    implementation:
      - "Sprint planning: reserve 2 days ????????? 10 days sprint"
      - "Prioritize debt items ????????? impact + effort matrix"
      - "Track debt reduction ?????? New Relic dashboard"
      
  prioritization_matrix:
    high_impact_low_effort:
      priority: 1
      action: "????????????????????? (Quick Wins)"
      examples:
        - "Update critical dependencies"
        - "Add missing error handling"
        - "Fix flaky tests"
    high_impact_high_effort:
      priority: 2
      action: "?????????????????????????????? sprint ???????????????"
      examples:
        - "Refactor monolith to microservices"
        - "Migrate database"
        - "Rewrite legacy module"
    low_impact_low_effort:
      priority: 3
      action: "??????????????????????????????????????????????????? (Boy Scout Rule)"
      examples:
        - "Improve variable naming"
        - "Add missing comments"
        - "Clean up unused code"
    low_impact_high_effort:
      priority: 4
      action: "??????????????? ???????????? defer"
      examples:
        - "Rewrite working legacy system"
        - "Change framework for aesthetics"
      
  automation:
    dependency_updates: "Renovate Bot (weekly PRs)"
    code_quality: "SonarQube in CI pipeline"
    security_scanning: "Snyk/Dependabot alerts"
    performance_testing: "k6 load tests in CI"
    debt_tracking: "New Relic custom events + NRQL alerts"
    
  new_relic_alerts:
    - name: "Error Rate Spike"
      condition: "error_rate > 2% for 5 minutes"
      action: "PagerDuty notification"
    - name: "Performance Degradation"
      condition: "p99_latency > 1000ms for 10 minutes"
      action: "Slack notification"
    - name: "New Critical Vulnerability"
      condition: "DependencyVuln WHERE severity = 'critical'"
      action: "Jira ticket auto-creation"
EOF

python3 -c "
import yaml
with open('remediation_plan.yaml') as f:
    data = yaml.safe_load(f)
plan = data['technical_debt_remediation']
print(f'Framework: {plan[\"framework\"][\"name\"]}')
print(f'Description: {plan[\"framework\"][\"description\"]}')
print('\nPrioritization:')
for level, info in plan['prioritization_matrix'].items():
    print(f'  P{info[\"priority\"]} ({level}): {info[\"action\"]}')
"

echo "Remediation strategy defined"

FAQ ??????????????????????????????????????????

Q: Technical Debt ??????????????????????????????????????????????????????????????????????

A: ?????????????????? ??????????????????????????????????????? 100% ????????? proxy metrics ???????????? Code metrics (complexity, duplication, test coverage) ??????????????????????????? SonarQube/CodeClimate, Performance metrics (latency, error rate, throughput) ??????????????????????????? New Relic/Datadog, Process metrics (deployment frequency, lead time, MTTR) ??????????????????????????? CI/CD tools, Cost metrics (time spent on bug fixes vs features) ??????????????????????????? project management tools SonarQube ?????? "Technical Debt" metric ????????????????????????????????????????????????????????????????????????????????????????????? ????????????????????? estimate New Relic ???????????????????????? runtime metrics (performance debt, reliability debt) ?????????????????????????????????????????? tools ??????????????????????????????????????????????????????????????????

Q: New Relic One ????????? Datadog ??????????????????????????????????????????????????? debt tracking?

A: New Relic One ??????????????????????????? 100GB/month data ingest, NRQL query language ?????????????????????, built-in Lookout ?????????????????? anomaly detection, Errors inbox ????????????????????????????????? error tracking integration ????????? CodeStream ?????????????????? code-level insights Datadog pricing ????????? volume ??????????????????????????????, UI ???????????????????????? opinion ???????????????????????????, APM + logs + traces integrated ??????, Watchdog AI ?????????????????? anomaly detection ?????????????????? debt tracking ???????????????????????? New Relic free tier + custom events ????????????????????? ?????????????????? Datadog ???????????????????????????????????????????????????????????????????????????????????? custom metrics

Q: ???????????????????????????????????????????????? technical debt ?????????????????????????

A: ???????????????????????? 20% ????????? sprint capacity ????????? 1 ?????????????????? 5 ????????? ???????????? 2 ?????????????????? 10 ????????? sprint ??????????????????????????????????????? "Tech Debt Sprint" ????????? 4-6 sprints ??????????????? 1 sprint ?????????????????????????????? debt reduction ????????????????????????????????????????????? Boy Scout Rule "Leave code better than you found it" ?????????????????????????????????????????? code ????????? improve ???????????????????????? ??????????????????????????? dedicated time ????????? debt ?????????????????????????????????????????? productivity ????????????????????????????????? ??????????????????????????????????????? 30-50% ?????????????????????????????????????????????????????? ??????????????????????????? ?????????????????????????????? buy-in ????????? management ???????????????????????? data ????????? debt ??????????????? velocity/quality ?????????????????????

Q: ??????????????????????????? technical debt ???????????????????????????????????????????

A: Prevention ?????????????????? cure Code review ?????????????????????????????? ????????? merge code ???????????????????????? tests ???????????? complexity ?????????, CI/CD quality gates block merge ????????? test coverage ????????????????????? threshold, Automated dependency updates (Renovate/Dependabot) ?????????????????? deps ????????????, Architecture Decision Records (ADR) document ????????? tradeoff decisions, Definition of Done ????????? "no new tech debt" ???????????? criteria, Regular refactoring sprints ???????????? 20% rule, Monitoring ???????????? New Relic ???????????? alerts ??????????????? metrics ????????? ????????????????????? 100% ?????????????????? technical debt ????????????????????????????????? "deliberate" (??????????????????????????????????????????????????????????????? ship ????????????) ???????????? OK ????????? track ????????? plan ?????????

📖 บทความที่เกี่ยวข้อง

New Relic One Micro-segmentationอ่านบทความ → New Relic One MLOps Workflowอ่านบทความ → New Relic One Team Productivityอ่านบทความ → New Relic One สำหรับมือใหม่ Step by Stepอ่านบทความ → New Relic One Citizen Developerอ่านบทความ →

📚 ดูบทความทั้งหมด →