Add console log forwarding to New Relic and enable application logging
All checks were successful
Build and Deploy / build (push) Successful in 1m47s
All checks were successful
Build and Deploy / build (push) Successful in 1m47s
- Add console shim to forward log/error/warn/info to New Relic - Enable application_logging with forwarding in newrelic.cjs - Import newrelic in server.js for recordLogEvent API - Update CI workflow with New Relic config Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
58959fe347
commit
421cd97fe9
1
.github/workflows/build.yml
vendored
1
.github/workflows/build.yml
vendored
@ -57,6 +57,7 @@ jobs:
|
|||||||
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
|
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
|
||||||
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
|
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
|
||||||
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
||||||
|
NEW_RELIC_LICENSE_KEY: ${{ secrets.NEW_RELIC_LICENSE_KEY }}
|
||||||
run: |
|
run: |
|
||||||
# Create .env.production with secrets (only accessible by immersive user)
|
# Create .env.production with secrets (only accessible by immersive user)
|
||||||
echo "# Auto-generated by CI/CD - Do not edit manually" > /opt/immersive/.env.production
|
echo "# Auto-generated by CI/CD - Do not edit manually" > /opt/immersive/.env.production
|
||||||
|
|||||||
18
newrelic.cjs
18
newrelic.cjs
@ -1,5 +1,7 @@
|
|||||||
'use strict'
|
'use strict'
|
||||||
|
// Load .env.local first (has the secrets), then .env as fallback
|
||||||
|
require('dotenv').config({ path: '.env.local' });
|
||||||
|
require('dotenv').config();
|
||||||
/**
|
/**
|
||||||
* New Relic Node.js APM Configuration
|
* New Relic Node.js APM Configuration
|
||||||
*
|
*
|
||||||
@ -10,14 +12,24 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
exports.config = {
|
exports.config = {
|
||||||
app_name: ['dasfad'],
|
app_name: ['dasfad-backend'],
|
||||||
license_key: process.env.NEW_RELIC_KEY,
|
license_key: process.env.NEW_RELIC_LICENSE_KEY,
|
||||||
distributed_tracing: {
|
distributed_tracing: {
|
||||||
enabled: true
|
enabled: true
|
||||||
},
|
},
|
||||||
logging: {
|
logging: {
|
||||||
level: 'info'
|
level: 'info'
|
||||||
},
|
},
|
||||||
|
application_logging: {
|
||||||
|
enabled: true,
|
||||||
|
forwarding: {
|
||||||
|
enabled: true,
|
||||||
|
max_samples_stored: 10000
|
||||||
|
},
|
||||||
|
local_decorating: {
|
||||||
|
enabled: true
|
||||||
|
}
|
||||||
|
},
|
||||||
allow_all_headers: true,
|
allow_all_headers: true,
|
||||||
attributes: {
|
attributes: {
|
||||||
exclude: [
|
exclude: [
|
||||||
|
|||||||
41
server.js
41
server.js
@ -2,6 +2,7 @@ import express from "express";
|
|||||||
import ViteExpress from "vite-express";
|
import ViteExpress from "vite-express";
|
||||||
import cors from "cors";
|
import cors from "cors";
|
||||||
import dotenv from "dotenv";
|
import dotenv from "dotenv";
|
||||||
|
import newrelic from "newrelic";
|
||||||
import apiRoutes from "./server/api/index.js";
|
import apiRoutes from "./server/api/index.js";
|
||||||
import { pouchApp, PouchDB } from "./server/services/databaseService.js";
|
import { pouchApp, PouchDB } from "./server/services/databaseService.js";
|
||||||
import { dbAuthMiddleware } from "./server/middleware/dbAuth.js";
|
import { dbAuthMiddleware } from "./server/middleware/dbAuth.js";
|
||||||
@ -10,6 +11,46 @@ import { dbAuthMiddleware } from "./server/middleware/dbAuth.js";
|
|||||||
dotenv.config({ path: '.env.local' });
|
dotenv.config({ path: '.env.local' });
|
||||||
dotenv.config();
|
dotenv.config();
|
||||||
|
|
||||||
|
// Console shim to forward logs to New Relic while preserving local output
|
||||||
|
const originalConsole = {
|
||||||
|
log: console.log.bind(console),
|
||||||
|
error: console.error.bind(console),
|
||||||
|
warn: console.warn.bind(console),
|
||||||
|
info: console.info.bind(console)
|
||||||
|
};
|
||||||
|
|
||||||
|
function forwardToNewRelic(level, args) {
|
||||||
|
const message = args.map(arg =>
|
||||||
|
typeof arg === 'object' ? JSON.stringify(arg) : String(arg)
|
||||||
|
).join(' ');
|
||||||
|
|
||||||
|
newrelic.recordLogEvent({
|
||||||
|
message,
|
||||||
|
level,
|
||||||
|
timestamp: Date.now()
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log = (...args) => {
|
||||||
|
forwardToNewRelic('info', args);
|
||||||
|
originalConsole.log(...args);
|
||||||
|
};
|
||||||
|
|
||||||
|
console.error = (...args) => {
|
||||||
|
forwardToNewRelic('error', args);
|
||||||
|
originalConsole.error(...args);
|
||||||
|
};
|
||||||
|
|
||||||
|
console.warn = (...args) => {
|
||||||
|
forwardToNewRelic('warn', args);
|
||||||
|
originalConsole.warn(...args);
|
||||||
|
};
|
||||||
|
|
||||||
|
console.info = (...args) => {
|
||||||
|
forwardToNewRelic('info', args);
|
||||||
|
originalConsole.info(...args);
|
||||||
|
};
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
|
|
||||||
// CORS configuration for split deployment
|
// CORS configuration for split deployment
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user