mirror of
https://github.com/MrUnknownDE/utools.git
synced 2026-04-18 21:53:44 +02:00
add sentry/profiling-node
This commit is contained in:
@@ -12,7 +12,6 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@maxmind/geoip2-node": "^6.0.0",
|
"@maxmind/geoip2-node": "^6.0.0",
|
||||||
"@sentry/node": "^8.0.0",
|
"@sentry/node": "^8.0.0",
|
||||||
"@sentry/profiling-node": "^8.0.0",
|
|
||||||
"cors": "^2.8.5",
|
"cors": "^2.8.5",
|
||||||
"dotenv": "^16.4.7",
|
"dotenv": "^16.4.7",
|
||||||
"express": "^4.21.2",
|
"express": "^4.21.2",
|
||||||
|
|||||||
@@ -1,31 +1,28 @@
|
|||||||
// server.js
|
// server.js
|
||||||
require('dotenv').config(); // Lädt Variablen aus .env in process.env
|
// Load .env variables FIRST!
|
||||||
|
require('dotenv').config();
|
||||||
|
|
||||||
// --- Sentry Initialisierung (GANZ OBEN!) ---
|
// --- Sentry Initialisierung (GANZ OBEN, nach dotenv) ---
|
||||||
const Sentry = require("@sentry/node");
|
const Sentry = require("@sentry/node");
|
||||||
// Korrigierter Import für ProfilingIntegration
|
|
||||||
const { nodeProfilingIntegration } = require("@sentry/profiling-node");
|
|
||||||
|
|
||||||
|
// Initialize Sentry BEFORE requiring any other modules!
|
||||||
Sentry.init({
|
Sentry.init({
|
||||||
// Ersetzen Sie dies durch Ihren echten Sentry DSN oder verwenden Sie die .env Datei
|
// DSN should now be available from process.env if set in .env
|
||||||
dsn: process.env.SENTRY_DSN || "YOUR_PLACEHOLDER_SENTRY_DSN",
|
// Using a syntactically valid but fake DSN as default
|
||||||
integrations: [
|
dsn: process.env.SENTRY_DSN || "https://7ea70caba68f548fb96482a573006a7b@o447623.ingest.us.sentry.io/4509062020333568",
|
||||||
// Standardintegrationen wie Http und Express werden automatisch hinzugefügt.
|
// Remove explicit integrations for now, rely on defaults
|
||||||
// Fügen Sie hier nur zusätzliche oder benutzerdefinierte Integrationen hinzu.
|
// integrations: [], // Let Sentry add defaults like Http, Express automatically
|
||||||
// Korrigierte Verwendung: Aufruf als Funktion, nicht mit 'new'
|
// Performance Monitoring - Keep enabled
|
||||||
nodeProfilingIntegration(),
|
tracesSampleRate: process.env.NODE_ENV === 'production' ? 0.1 : 1.0,
|
||||||
],
|
// Profiling disabled for now to simplify
|
||||||
// Performance Monitoring
|
// profilesSampleRate: process.env.NODE_ENV === 'production' ? 0.1 : 1.0,
|
||||||
tracesSampleRate: process.env.NODE_ENV === 'production' ? 0.1 : 1.0, // 10% in Produktion, 100% sonst
|
|
||||||
// Set sampling rate for profiling - this is relative to tracesSampleRate
|
|
||||||
profilesSampleRate: process.env.NODE_ENV === 'production' ? 0.1 : 1.0, // 10% in Produktion, 100% sonst
|
|
||||||
environment: process.env.NODE_ENV || 'development',
|
environment: process.env.NODE_ENV || 'development',
|
||||||
// Optional: Release-Version setzen (z.B. über GIT_COMMIT_SHA)
|
|
||||||
release: process.env.GIT_COMMIT_SHA || undefined,
|
release: process.env.GIT_COMMIT_SHA || undefined,
|
||||||
});
|
});
|
||||||
// --- Ende Sentry Initialisierung ---
|
// --- Ende Sentry Initialisierung ---
|
||||||
|
|
||||||
|
|
||||||
|
// Require other modules AFTER Sentry is initialized
|
||||||
const express = require('express');
|
const express = require('express');
|
||||||
const cors = require('cors');
|
const cors = require('cors');
|
||||||
const geoip = require('@maxmind/geoip2-node');
|
const geoip = require('@maxmind/geoip2-node');
|
||||||
@@ -34,29 +31,31 @@ const { spawn } = require('child_process');
|
|||||||
const dns = require('dns').promises;
|
const dns = require('dns').promises;
|
||||||
const pino = require('pino'); // Logging library
|
const pino = require('pino'); // Logging library
|
||||||
const rateLimit = require('express-rate-limit'); // Rate limiting middleware
|
const rateLimit = require('express-rate-limit'); // Rate limiting middleware
|
||||||
const whois = require('whois-json'); // Hinzugefügt für WHOIS
|
const whois = require('whois-json'); // Added for WHOIS
|
||||||
// REMOVED: const oui = require('oui');
|
// REMOVED: const oui = require('oui');
|
||||||
|
|
||||||
// --- Logger Initialisierung ---
|
// --- Logger Initialisierung ---
|
||||||
const logger = pino({
|
const logger = pino({
|
||||||
level: process.env.LOG_LEVEL || 'info', // Konfigurierbares Log-Level (z.B. 'debug', 'info', 'warn', 'error')
|
level: process.env.LOG_LEVEL || 'info', // Configurable log level (e.g., 'debug', 'info', 'warn', 'error')
|
||||||
// Pretty print nur im Development, sonst JSON für bessere Maschinenlesbarkeit
|
// Pretty print only in Development, otherwise JSON for better machine readability
|
||||||
transport: process.env.NODE_ENV !== 'production'
|
transport: process.env.NODE_ENV !== 'production'
|
||||||
? { target: 'pino-pretty', options: { colorize: true, translateTime: 'SYS:standard', ignore: 'pid,hostname' } }
|
? { target: 'pino-pretty', options: { colorize: true, translateTime: 'SYS:standard', ignore: 'pid,hostname' } }
|
||||||
: undefined,
|
: undefined,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Create Express app instance AFTER requiring express
|
||||||
const app = express();
|
const app = express();
|
||||||
const PORT = process.env.PORT || 3000;
|
const PORT = process.env.PORT || 3000;
|
||||||
|
|
||||||
// --- Sentry Request Handler (ALS ERSTE MIDDLEWARE!) ---
|
// --- Sentry Request Handler (AS FIRST MIDDLEWARE!) ---
|
||||||
// Dieser Handler muss VOR allen anderen Middlewares und Routen stehen.
|
// This handler must be the first middleware on the app.
|
||||||
|
// It needs to be called AFTER Sentry.init()
|
||||||
app.use(Sentry.Handlers.requestHandler());
|
app.use(Sentry.Handlers.requestHandler());
|
||||||
// --- Ende Sentry Request Handler ---
|
// --- Ende Sentry Request Handler ---
|
||||||
|
|
||||||
// --- Sentry Tracing Handler (NACH CORS/JSON, VOR ROUTEN) ---
|
// --- Sentry Tracing Handler (AFTER requestHandler, BEFORE routes) ---
|
||||||
// Dieser Handler muss NACH dem requestHandler und VOR den Routen stehen.
|
// This handler must be after requestHandler and before any routes.
|
||||||
// Er fügt Trace-Informationen zu eingehenden Anfragen hinzu.
|
// It adds tracing information to incoming requests.
|
||||||
app.use(Sentry.Handlers.tracingHandler());
|
app.use(Sentry.Handlers.tracingHandler());
|
||||||
// --- Ende Sentry Tracing Handler ---
|
// --- Ende Sentry Tracing Handler ---
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user