fix: lint
This commit is contained in:
parent
f55cba4e43
commit
df496c0765
3 changed files with 1800 additions and 113 deletions
1716
package-lock.json
generated
1716
package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
|
@ -1,6 +1,6 @@
|
|||
import * as Sentry from "@sentry/node";
|
||||
import { nodeProfilingIntegration } from "@sentry/profiling-node";
|
||||
import logger from "./util/logger.js";
|
||||
import { logger } from "./util/logger.js";
|
||||
import { getVersion } from "./version.js";
|
||||
|
||||
interface SentryConfig {
|
||||
|
|
@ -25,16 +25,22 @@ class SentryService {
|
|||
}
|
||||
|
||||
private loadConfig(): SentryConfig {
|
||||
const enabled = process.env.SENTRY_ENABLED !== "false" && !!process.env.SENTRY_DSN;
|
||||
|
||||
const enabled =
|
||||
process.env.SENTRY_ENABLED !== "false" && !!process.env.SENTRY_DSN;
|
||||
|
||||
return {
|
||||
enabled,
|
||||
dsn: process.env.SENTRY_DSN,
|
||||
environment: process.env.SENTRY_ENVIRONMENT || process.env.NODE_ENV || "development",
|
||||
environment:
|
||||
process.env.SENTRY_ENVIRONMENT || process.env.NODE_ENV || "development",
|
||||
release: getVersion(),
|
||||
sampleRate: parseFloat(process.env.SENTRY_SAMPLE_RATE || "1.0"),
|
||||
profilesSampleRate: parseFloat(process.env.SENTRY_PROFILES_SAMPLE_RATE || "1.0"),
|
||||
tracesSampleRate: parseFloat(process.env.SENTRY_TRACES_SAMPLE_RATE || "1.0"),
|
||||
profilesSampleRate: parseFloat(
|
||||
process.env.SENTRY_PROFILES_SAMPLE_RATE || "1.0"
|
||||
),
|
||||
tracesSampleRate: parseFloat(
|
||||
process.env.SENTRY_TRACES_SAMPLE_RATE || "1.0"
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -51,9 +57,7 @@ class SentryService {
|
|||
sampleRate: this.config.sampleRate,
|
||||
profilesSampleRate: this.config.profilesSampleRate,
|
||||
tracesSampleRate: this.config.tracesSampleRate,
|
||||
integrations: [
|
||||
nodeProfilingIntegration(),
|
||||
],
|
||||
integrations: [nodeProfilingIntegration()],
|
||||
beforeSend(event) {
|
||||
// Filter out certain error types if needed
|
||||
if (event.exception?.values?.[0]?.type === "AbortError") {
|
||||
|
|
@ -90,7 +94,11 @@ class SentryService {
|
|||
});
|
||||
}
|
||||
|
||||
public captureMessage(message: string, level: "info" | "warning" | "error" | "debug" | "fatal" = "info", context?: Record<string, any>) {
|
||||
public captureMessage(
|
||||
message: string,
|
||||
level: "info" | "warning" | "error" | "debug" | "fatal" = "info",
|
||||
context?: Record<string, any>
|
||||
) {
|
||||
if (!this.isEnabled()) return;
|
||||
|
||||
Sentry.withScope((scope) => {
|
||||
|
|
@ -121,7 +129,12 @@ class SentryService {
|
|||
Sentry.setContext(key, context);
|
||||
}
|
||||
|
||||
public addBreadcrumb(breadcrumb: { message: string; category?: string; level?: "fatal" | "error" | "warning" | "log" | "info" | "debug"; data?: Record<string, any> }) {
|
||||
public addBreadcrumb(breadcrumb: {
|
||||
message: string;
|
||||
category?: string;
|
||||
level?: "fatal" | "error" | "warning" | "log" | "info" | "debug";
|
||||
data?: Record<string, any>;
|
||||
}) {
|
||||
if (!this.isEnabled()) return;
|
||||
|
||||
Sentry.addBreadcrumb(breadcrumb);
|
||||
|
|
@ -147,4 +160,4 @@ class SentryService {
|
|||
}
|
||||
|
||||
export const sentryService = new SentryService();
|
||||
export default sentryService;
|
||||
export default sentryService;
|
||||
|
|
|
|||
|
|
@ -1,94 +1,96 @@
|
|||
import crypto from 'crypto';
|
||||
import fs from 'fs';
|
||||
import os from 'os';
|
||||
import path from 'path';
|
||||
import crypto from "crypto";
|
||||
import fs from "fs";
|
||||
import os from "os";
|
||||
import path from "path";
|
||||
|
||||
import chalk from 'chalk';
|
||||
import winston from 'winston';
|
||||
import sentryService from '../sentry.js';
|
||||
import chalk from "chalk";
|
||||
import winston from "winston";
|
||||
import sentryService from "../sentry.js";
|
||||
|
||||
const { combine, timestamp, printf, errors } = winston.format;
|
||||
|
||||
// Generate a unique session ID for this process
|
||||
const SESSION_ID = crypto.randomBytes(4).toString('hex');
|
||||
const SESSION_ID = crypto.randomBytes(4).toString("hex");
|
||||
|
||||
// Get log directory
|
||||
function getLogDir(): string {
|
||||
const homeDir = os.homedir();
|
||||
const logDir = path.join(homeDir, '.continue', 'logs');
|
||||
|
||||
const logDir = path.join(homeDir, ".continue", "logs");
|
||||
|
||||
// Create directory if it doesn't exist
|
||||
if (!fs.existsSync(logDir)) {
|
||||
fs.mkdirSync(logDir, { recursive: true });
|
||||
}
|
||||
|
||||
|
||||
return logDir;
|
||||
}
|
||||
|
||||
// Get current log file path
|
||||
function getLogFilePath(): string {
|
||||
const logDir = getLogDir();
|
||||
return path.join(logDir, 'cn.log');
|
||||
return path.join(logDir, "cn.log");
|
||||
}
|
||||
|
||||
// Simple replacer for JSON.stringify to handle common issues
|
||||
function createReplacer() {
|
||||
const seen = new Set();
|
||||
|
||||
|
||||
return (key: string, value: any) => {
|
||||
// Handle circular references
|
||||
if (typeof value === 'object' && value !== null) {
|
||||
if (typeof value === "object" && value !== null) {
|
||||
if (seen.has(value)) {
|
||||
return '[Circular]';
|
||||
return "[Circular]";
|
||||
}
|
||||
seen.add(value);
|
||||
}
|
||||
|
||||
|
||||
// Handle functions
|
||||
if (typeof value === 'function') {
|
||||
return '[Function]';
|
||||
if (typeof value === "function") {
|
||||
return "[Function]";
|
||||
}
|
||||
|
||||
|
||||
// Handle undefined (which JSON.stringify skips by default)
|
||||
if (value === undefined) {
|
||||
return '[undefined]';
|
||||
return "[undefined]";
|
||||
}
|
||||
|
||||
|
||||
return value;
|
||||
};
|
||||
}
|
||||
|
||||
// Custom format for log output
|
||||
const logFormat = printf(({ level, message, timestamp, stack, ...metadata }) => {
|
||||
let msg = `${timestamp} [${SESSION_ID}] [${level}]: ${message}`;
|
||||
|
||||
// Add metadata if present
|
||||
if (Object.keys(metadata).length > 0) {
|
||||
try {
|
||||
msg += ` ${JSON.stringify(metadata, createReplacer())}`;
|
||||
} catch (err) {
|
||||
// Fallback if stringify still fails somehow
|
||||
msg += ` [Failed to stringify metadata: ${err}]`;
|
||||
const logFormat = printf(
|
||||
({ level, message, timestamp, stack, ...metadata }) => {
|
||||
let msg = `${timestamp} [${SESSION_ID}] [${level}]: ${message}`;
|
||||
|
||||
// Add metadata if present
|
||||
if (Object.keys(metadata).length > 0) {
|
||||
try {
|
||||
msg += ` ${JSON.stringify(metadata, createReplacer())}`;
|
||||
} catch (err) {
|
||||
// Fallback if stringify still fails somehow
|
||||
msg += ` [Failed to stringify metadata: ${err}]`;
|
||||
}
|
||||
}
|
||||
|
||||
// Add stack trace for errors
|
||||
if (stack) {
|
||||
msg += `\n${stack}`;
|
||||
}
|
||||
|
||||
return msg;
|
||||
}
|
||||
|
||||
// Add stack trace for errors
|
||||
if (stack) {
|
||||
msg += `\n${stack}`;
|
||||
}
|
||||
|
||||
return msg;
|
||||
});
|
||||
);
|
||||
|
||||
// Track headless mode
|
||||
let isHeadlessMode = false;
|
||||
|
||||
// Create the logger instance
|
||||
// Create the winstonLogger instance
|
||||
const winstonLogger = winston.createLogger({
|
||||
level: 'info', // Default level
|
||||
level: "info", // Default level
|
||||
format: combine(
|
||||
errors({ stack: true }),
|
||||
timestamp({ format: 'YYYY-MM-DD HH:mm:ss.SSS' }),
|
||||
timestamp({ format: "YYYY-MM-DD HH:mm:ss.SSS" }),
|
||||
logFormat
|
||||
),
|
||||
transports: [
|
||||
|
|
@ -106,76 +108,36 @@ export function setLogLevel(level: string) {
|
|||
winstonLogger.level = level;
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
// Export logger methods
|
||||
export default {
|
||||
debug: (message: string, meta?: any) => logger.debug(message, meta),
|
||||
info: (message: string, meta?: any) => logger.info(message, meta),
|
||||
warn: (message: string, meta?: any) => {
|
||||
logger.warn(message, meta);
|
||||
sentryService.captureMessage(message, "warning", meta);
|
||||
},
|
||||
||||||| 48adb23
|
||||
// Export logger methods
|
||||
export default {
|
||||
debug: (message: string, meta?: any) => logger.debug(message, meta),
|
||||
info: (message: string, meta?: any) => logger.info(message, meta),
|
||||
warn: (message: string, meta?: any) => logger.warn(message, meta),
|
||||
=======
|
||||
// Function to configure headless mode
|
||||
export function configureHeadlessMode(headless: boolean) {
|
||||
isHeadlessMode = headless;
|
||||
}
|
||||
|
||||
// Export logger methods
|
||||
// Export winstonLogger methods
|
||||
export const logger = {
|
||||
debug: (message: string, meta?: any) => winstonLogger.debug(message, meta),
|
||||
info: (message: string, meta?: any) => winstonLogger.info(message, meta),
|
||||
warn: (message: string, meta?: any) => winstonLogger.warn(message, meta),
|
||||
>>>>>>> main
|
||||
warn: (message: string, meta?: any) => {
|
||||
winstonLogger.warn(message, meta);
|
||||
sentryService.captureMessage(message, "warning", meta);
|
||||
},
|
||||
error: (message: string, error?: Error | any, meta?: any) => {
|
||||
if (error instanceof Error) {
|
||||
<<<<<<< HEAD
|
||||
logger.error(message, { ...meta, error: error.message, stack: error.stack });
|
||||
winstonLogger.error(message, {
|
||||
...meta,
|
||||
error: error.message,
|
||||
stack: error.stack,
|
||||
});
|
||||
sentryService.captureException(error, { message, ...meta });
|
||||
||||||| 48adb23
|
||||
logger.error(message, { ...meta, error: error.message, stack: error.stack });
|
||||
=======
|
||||
winstonLogger.error(message, { ...meta, error: error.message, stack: error.stack });
|
||||
>>>>>>> main
|
||||
} else if (error) {
|
||||
<<<<<<< HEAD
|
||||
logger.error(message, { ...meta, error });
|
||||
sentryService.captureMessage(`${message}: ${String(error)}`, "error", meta);
|
||||
||||||| 48adb23
|
||||
logger.error(message, { ...meta, error });
|
||||
=======
|
||||
winstonLogger.error(message, { ...meta, error });
|
||||
>>>>>>> main
|
||||
sentryService.captureMessage(
|
||||
`${message}: ${String(error)}`,
|
||||
"error",
|
||||
meta
|
||||
);
|
||||
} else {
|
||||
<<<<<<< HEAD
|
||||
logger.error(message, meta);
|
||||
sentryService.captureMessage(message, "error", meta);
|
||||
||||||| 48adb23
|
||||
logger.error(message, meta);
|
||||
=======
|
||||
winstonLogger.error(message, meta);
|
||||
}
|
||||
|
||||
// In headless mode, also output to stderr
|
||||
if (isHeadlessMode) {
|
||||
if (error instanceof Error) {
|
||||
console.error(chalk.red(`${message}: ${error.message}`));
|
||||
} else if (error) {
|
||||
console.error(chalk.red(`${message}: ${error}`));
|
||||
} else {
|
||||
console.error(chalk.red(message));
|
||||
}
|
||||
>>>>>>> main
|
||||
sentryService.captureMessage(message, "error", meta);
|
||||
}
|
||||
},
|
||||
setLevel: setLogLevel,
|
||||
configureHeadlessMode,
|
||||
getLogPath: getLogFilePath,
|
||||
getSessionId: () => SESSION_ID,
|
||||
};
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue