@ancientwhispers54/leafengines-mcp-server 1.1.8 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CONTRIBUTING.md +1 -0
- package/README.md +196 -116
- package/dist/index.d.ts +1 -13
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +132 -198
- package/dist/index.js.map +1 -1
- package/dist/index_final.d.ts +20 -0
- package/dist/index_final.d.ts.map +1 -0
- package/dist/index_final.js +474 -0
- package/dist/index_final.js.map +1 -0
- package/dist/index_simple.d.ts +6 -0
- package/dist/index_simple.d.ts.map +1 -0
- package/dist/index_simple.js +220 -0
- package/dist/index_simple.js.map +1 -0
- package/dist/index_updated.d.ts +20 -0
- package/dist/index_updated.d.ts.map +1 -0
- package/dist/index_updated.js +390 -0
- package/dist/index_updated.js.map +1 -0
- package/dist/logger.d.ts +17 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +155 -0
- package/dist/logger.js.map +1 -0
- package/dist/metrics-server.d.ts +11 -0
- package/dist/metrics-server.d.ts.map +1 -0
- package/dist/metrics-server.js +106 -0
- package/dist/metrics-server.js.map +1 -0
- package/dist/metrics.d.ts +37 -0
- package/dist/metrics.d.ts.map +1 -0
- package/dist/metrics.js +223 -0
- package/dist/metrics.js.map +1 -0
- package/dist/sentry.d.ts +17 -0
- package/dist/sentry.d.ts.map +1 -0
- package/dist/sentry.js +166 -0
- package/dist/sentry.js.map +1 -0
- package/package.json +6 -2
package/dist/logger.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Structured logging for LeafEngines MCP Server
|
|
3
|
+
* Uses Pino for high-performance structured logging
|
|
4
|
+
*/
|
|
5
|
+
import pino from 'pino';
|
|
6
|
+
declare const logger: pino.Logger<never, boolean>;
|
|
7
|
+
export declare const logging: {
|
|
8
|
+
toolExecution: (toolName: string, params: any, durationMs: number, success: boolean, error?: any) => void;
|
|
9
|
+
apiRequest: (endpoint: string, method: string, statusCode: number, durationMs: number, userId?: string) => void;
|
|
10
|
+
error: (context: string, error: Error, additionalData?: any) => void;
|
|
11
|
+
performance: (operation: string, durationMs: number, metadata?: any) => void;
|
|
12
|
+
businessEvent: (eventType: string, data: any) => void;
|
|
13
|
+
startup: (version: string, environment: string) => void;
|
|
14
|
+
shutdown: (reason: string) => void;
|
|
15
|
+
};
|
|
16
|
+
export default logger;
|
|
17
|
+
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,IAAI,MAAM,MAAM,CAAC;AAOxB,QAAA,MAAM,MAAM,6BAiCV,CAAC;AAGH,eAAO,MAAM,OAAO;8BAEQ,MAAM,UAAU,GAAG,cAAc,MAAM,WAAW,OAAO,UAAU,GAAG;2BAmBzE,MAAM,UAAU,MAAM,cAAc,MAAM,cAAc,MAAM,WAAW,MAAM;qBAarF,MAAM,SAAS,KAAK,mBAAmB,GAAG;6BAYlC,MAAM,cAAc,MAAM,aAAa,GAAG;+BAUxC,MAAM,QAAQ,GAAG;uBASzB,MAAM,eAAe,MAAM;uBAS3B,MAAM;CAO1B,CAAC;AAmCF,eAAe,MAAM,CAAC"}
|
package/dist/logger.js
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Structured logging for LeafEngines MCP Server
|
|
4
|
+
* Uses Pino for high-performance structured logging
|
|
5
|
+
*/
|
|
6
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
7
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
8
|
+
};
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.logging = void 0;
|
|
11
|
+
const pino_1 = __importDefault(require("pino"));
|
|
12
|
+
// Environment-based configuration
|
|
13
|
+
const logLevel = process.env.LOG_LEVEL || 'info';
|
|
14
|
+
const isDevelopment = process.env.NODE_ENV === 'development';
|
|
15
|
+
// Create logger instance
|
|
16
|
+
const logger = (0, pino_1.default)({
|
|
17
|
+
level: logLevel,
|
|
18
|
+
transport: isDevelopment ? {
|
|
19
|
+
target: 'pino-pretty',
|
|
20
|
+
options: {
|
|
21
|
+
colorize: true,
|
|
22
|
+
translateTime: 'SYS:standard',
|
|
23
|
+
ignore: 'pid,hostname',
|
|
24
|
+
messageFormat: '{msg}',
|
|
25
|
+
customPrettifiers: {
|
|
26
|
+
time: (timestamp) => `[${timestamp}]`,
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
} : undefined,
|
|
30
|
+
base: {
|
|
31
|
+
service: 'leafengines-mcp-server',
|
|
32
|
+
version: process.env.npm_package_version || '1.1.9',
|
|
33
|
+
environment: process.env.NODE_ENV || 'production'
|
|
34
|
+
},
|
|
35
|
+
timestamp: pino_1.default.stdTimeFunctions.isoTime,
|
|
36
|
+
formatters: {
|
|
37
|
+
level: (label) => ({ level: label.toUpperCase() }),
|
|
38
|
+
bindings: (bindings) => ({
|
|
39
|
+
pid: bindings.pid,
|
|
40
|
+
hostname: bindings.hostname,
|
|
41
|
+
service: bindings.service
|
|
42
|
+
})
|
|
43
|
+
},
|
|
44
|
+
serializers: {
|
|
45
|
+
req: pino_1.default.stdSerializers.req,
|
|
46
|
+
res: pino_1.default.stdSerializers.res,
|
|
47
|
+
err: pino_1.default.stdSerializers.err
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
// Logging utilities for common scenarios
|
|
51
|
+
exports.logging = {
|
|
52
|
+
// Tool execution logging
|
|
53
|
+
toolExecution: (toolName, params, durationMs, success, error) => {
|
|
54
|
+
const logData = {
|
|
55
|
+
event: 'tool_execution',
|
|
56
|
+
tool: toolName,
|
|
57
|
+
params: sanitizeParams(params),
|
|
58
|
+
duration_ms: durationMs,
|
|
59
|
+
success,
|
|
60
|
+
error: error ? error.message : undefined,
|
|
61
|
+
error_type: error ? error.constructor.name : undefined
|
|
62
|
+
};
|
|
63
|
+
if (success) {
|
|
64
|
+
logger.info(logData, `Tool executed: ${toolName}`);
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
logger.error(logData, `Tool execution failed: ${toolName}`);
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
// API request logging
|
|
71
|
+
apiRequest: (endpoint, method, statusCode, durationMs, userId) => {
|
|
72
|
+
logger.info({
|
|
73
|
+
event: 'api_request',
|
|
74
|
+
endpoint,
|
|
75
|
+
method,
|
|
76
|
+
status_code: statusCode,
|
|
77
|
+
duration_ms: durationMs,
|
|
78
|
+
user_id: userId || 'anonymous',
|
|
79
|
+
user_type: userId ? 'authenticated' : 'anonymous'
|
|
80
|
+
}, `API ${method} ${endpoint} - ${statusCode} (${durationMs}ms)`);
|
|
81
|
+
},
|
|
82
|
+
// Error logging with context
|
|
83
|
+
error: (context, error, additionalData) => {
|
|
84
|
+
logger.error({
|
|
85
|
+
event: 'error',
|
|
86
|
+
context,
|
|
87
|
+
error_message: error.message,
|
|
88
|
+
error_stack: error.stack,
|
|
89
|
+
error_name: error.name,
|
|
90
|
+
...additionalData
|
|
91
|
+
}, `Error in ${context}: ${error.message}`);
|
|
92
|
+
},
|
|
93
|
+
// Performance logging
|
|
94
|
+
performance: (operation, durationMs, metadata) => {
|
|
95
|
+
logger.info({
|
|
96
|
+
event: 'performance',
|
|
97
|
+
operation,
|
|
98
|
+
duration_ms: durationMs,
|
|
99
|
+
...metadata
|
|
100
|
+
}, `${operation} completed in ${durationMs}ms`);
|
|
101
|
+
},
|
|
102
|
+
// Business event logging
|
|
103
|
+
businessEvent: (eventType, data) => {
|
|
104
|
+
logger.info({
|
|
105
|
+
event: 'business',
|
|
106
|
+
type: eventType,
|
|
107
|
+
...sanitizeBusinessData(data)
|
|
108
|
+
}, `Business event: ${eventType}`);
|
|
109
|
+
},
|
|
110
|
+
// Startup/shutdown logging
|
|
111
|
+
startup: (version, environment) => {
|
|
112
|
+
logger.info({
|
|
113
|
+
event: 'startup',
|
|
114
|
+
version,
|
|
115
|
+
environment,
|
|
116
|
+
timestamp: new Date().toISOString()
|
|
117
|
+
}, `LeafEngines MCP Server v${version} starting in ${environment} environment`);
|
|
118
|
+
},
|
|
119
|
+
shutdown: (reason) => {
|
|
120
|
+
logger.info({
|
|
121
|
+
event: 'shutdown',
|
|
122
|
+
reason,
|
|
123
|
+
timestamp: new Date().toISOString()
|
|
124
|
+
}, `Server shutting down: ${reason}`);
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
// Sanitize parameters to remove sensitive data
|
|
128
|
+
function sanitizeParams(params) {
|
|
129
|
+
if (!params || typeof params !== 'object')
|
|
130
|
+
return params;
|
|
131
|
+
const sanitized = { ...params };
|
|
132
|
+
const sensitiveFields = ['api_key', 'token', 'password', 'secret', 'authorization', 'x-api-key'];
|
|
133
|
+
for (const field of sensitiveFields) {
|
|
134
|
+
if (sanitized[field]) {
|
|
135
|
+
sanitized[field] = '[REDACTED]';
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return sanitized;
|
|
139
|
+
}
|
|
140
|
+
// Sanitize business data
|
|
141
|
+
function sanitizeBusinessData(data) {
|
|
142
|
+
if (!data || typeof data !== 'object')
|
|
143
|
+
return data;
|
|
144
|
+
const sanitized = { ...data };
|
|
145
|
+
const businessSensitive = ['email', 'phone', 'address', 'ssn', 'credit_card'];
|
|
146
|
+
for (const field of businessSensitive) {
|
|
147
|
+
if (sanitized[field]) {
|
|
148
|
+
sanitized[field] = '[REDACTED]';
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
return sanitized;
|
|
152
|
+
}
|
|
153
|
+
// Export the logger instance
|
|
154
|
+
exports.default = logger;
|
|
155
|
+
//# sourceMappingURL=logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"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
+
*
|
|
4
|
+
* Runs a separate HTTP server to expose metrics on /metrics endpoint
|
|
5
|
+
*/
|
|
6
|
+
import http from 'http';
|
|
7
|
+
declare const server: http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>;
|
|
8
|
+
export declare function startMetricsServer(): Promise<http.Server>;
|
|
9
|
+
export declare function stopMetricsServer(): Promise<void>;
|
|
10
|
+
export default server;
|
|
11
|
+
//# sourceMappingURL=metrics-server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"metrics-server.d.ts","sourceRoot":"","sources":["../src/metrics-server.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,IAAI,MAAM,MAAM,CAAC;AASxB,QAAA,MAAM,MAAM,sEAkCV,CAAC;AAGH,wBAAgB,kBAAkB,IAAI,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAqBzD;AAGD,wBAAgB,iBAAiB,IAAI,OAAO,CAAC,IAAI,CAAC,CAiBjD;AAgBD,eAAe,MAAM,CAAC"}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Metrics HTTP server for Prometheus scraping
|
|
4
|
+
*
|
|
5
|
+
* Runs a separate HTTP server to expose metrics on /metrics endpoint
|
|
6
|
+
*/
|
|
7
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
8
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
9
|
+
};
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.startMetricsServer = startMetricsServer;
|
|
12
|
+
exports.stopMetricsServer = stopMetricsServer;
|
|
13
|
+
const http_1 = __importDefault(require("http"));
|
|
14
|
+
const logger_js_1 = require("./logger.js");
|
|
15
|
+
const metrics_js_1 = __importDefault(require("./metrics.js"));
|
|
16
|
+
// Configuration
|
|
17
|
+
const METRICS_PORT = parseInt(process.env.METRICS_PORT || '9464');
|
|
18
|
+
const METRICS_HOST = process.env.METRICS_HOST || '0.0.0.0';
|
|
19
|
+
// Create HTTP server
|
|
20
|
+
const server = http_1.default.createServer(async (req, res) => {
|
|
21
|
+
// Only allow GET requests to /metrics
|
|
22
|
+
if (req.url === '/metrics' && req.method === 'GET') {
|
|
23
|
+
try {
|
|
24
|
+
const metricsData = await metrics_js_1.default.getMetrics();
|
|
25
|
+
res.writeHead(200, {
|
|
26
|
+
'Content-Type': 'text/plain; version=0.0.4',
|
|
27
|
+
'Content-Length': Buffer.byteLength(metricsData)
|
|
28
|
+
});
|
|
29
|
+
res.end(metricsData);
|
|
30
|
+
// Log metrics request
|
|
31
|
+
logger_js_1.logging.apiRequest('/metrics', 'GET', 200, 0, 'metrics_scraper');
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
logger_js_1.logging.error('metrics_endpoint', error);
|
|
35
|
+
res.writeHead(500, { 'Content-Type': 'text/plain' });
|
|
36
|
+
res.end('Error collecting metrics');
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
else if (req.url === '/health' && req.method === 'GET') {
|
|
40
|
+
// Simple health check endpoint
|
|
41
|
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
42
|
+
res.end(JSON.stringify({
|
|
43
|
+
status: 'healthy',
|
|
44
|
+
service: 'leafengines-metrics',
|
|
45
|
+
timestamp: new Date().toISOString(),
|
|
46
|
+
uptime: process.uptime()
|
|
47
|
+
}));
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
res.writeHead(404, { 'Content-Type': 'text/plain' });
|
|
51
|
+
res.end('Not Found');
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
// Start metrics server
|
|
55
|
+
function startMetricsServer() {
|
|
56
|
+
return new Promise((resolve, reject) => {
|
|
57
|
+
server.listen(METRICS_PORT, METRICS_HOST, () => {
|
|
58
|
+
logger_js_1.logging.businessEvent('metrics_server_started', {
|
|
59
|
+
host: METRICS_HOST,
|
|
60
|
+
port: METRICS_PORT,
|
|
61
|
+
endpoints: ['/metrics', '/health']
|
|
62
|
+
});
|
|
63
|
+
console.log(`📊 Metrics server listening on http://${METRICS_HOST}:${METRICS_PORT}`);
|
|
64
|
+
console.log(` • Metrics endpoint: http://${METRICS_HOST}:${METRICS_PORT}/metrics`);
|
|
65
|
+
console.log(` • Health endpoint: http://${METRICS_HOST}:${METRICS_PORT}/health`);
|
|
66
|
+
resolve(server);
|
|
67
|
+
});
|
|
68
|
+
server.on('error', (error) => {
|
|
69
|
+
logger_js_1.logging.error('metrics_server_error', error);
|
|
70
|
+
reject(error);
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
// Graceful shutdown
|
|
75
|
+
function stopMetricsServer() {
|
|
76
|
+
return new Promise((resolve, reject) => {
|
|
77
|
+
if (!server.listening) {
|
|
78
|
+
resolve();
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
server.close((error) => {
|
|
82
|
+
if (error) {
|
|
83
|
+
logger_js_1.logging.error('metrics_server_shutdown', error);
|
|
84
|
+
reject(error);
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
logger_js_1.logging.businessEvent('metrics_server_stopped', {});
|
|
88
|
+
resolve();
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
// Handle process signals
|
|
94
|
+
process.on('SIGINT', async () => {
|
|
95
|
+
logger_js_1.logging.shutdown('SIGINT');
|
|
96
|
+
await stopMetricsServer();
|
|
97
|
+
process.exit(0);
|
|
98
|
+
});
|
|
99
|
+
process.on('SIGTERM', async () => {
|
|
100
|
+
logger_js_1.logging.shutdown('SIGTERM');
|
|
101
|
+
await stopMetricsServer();
|
|
102
|
+
process.exit(0);
|
|
103
|
+
});
|
|
104
|
+
// Export server instance
|
|
105
|
+
exports.default = server;
|
|
106
|
+
//# sourceMappingURL=metrics-server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"metrics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"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prometheus metrics for LeafEngines MCP Server
|
|
3
|
+
*
|
|
4
|
+
* Provides business and performance metrics for monitoring
|
|
5
|
+
*/
|
|
6
|
+
import client from 'prom-client';
|
|
7
|
+
declare const register: client.Registry<"text/plain; version=0.0.4; charset=utf-8">;
|
|
8
|
+
export declare const businessMetrics: {
|
|
9
|
+
toolUsageCounter: client.Counter<"status" | "user_type" | "tool_name">;
|
|
10
|
+
apiRequestCounter: client.Counter<"method" | "endpoint" | "status_code" | "user_type">;
|
|
11
|
+
apiResponseTimeHistogram: client.Histogram<"method" | "endpoint">;
|
|
12
|
+
errorCounter: client.Counter<"context" | "error_type" | "severity">;
|
|
13
|
+
userTypeGauge: client.Gauge<"user_type">;
|
|
14
|
+
featureUsageCounter: client.Counter<"user_type" | "feature">;
|
|
15
|
+
performanceHistogram: client.Histogram<"operation" | "component">;
|
|
16
|
+
memoryUsageGauge: client.Gauge<"type">;
|
|
17
|
+
activeConnectionsGauge: client.Gauge<string>;
|
|
18
|
+
revenueEstimateGauge: client.Gauge<string>;
|
|
19
|
+
conversionCounter: client.Counter<"conversion_type" | "source">;
|
|
20
|
+
};
|
|
21
|
+
export declare const metrics: {
|
|
22
|
+
recordToolUsage: (toolName: string, success: boolean, userType: "free" | "paid" | "anonymous") => void;
|
|
23
|
+
recordApiRequest: (endpoint: string, method: string, statusCode: number, durationSeconds: number, userType: string) => void;
|
|
24
|
+
recordError: (errorType: string, context: string, severity: "low" | "medium" | "high" | "critical") => void;
|
|
25
|
+
updateUserType: (freeUsers: number, paidUsers: number, anonymousUsers: number) => void;
|
|
26
|
+
recordPerformance: (operation: string, component: string, durationSeconds: number) => void;
|
|
27
|
+
updateMemoryUsage: () => void;
|
|
28
|
+
updateActiveConnections: (count: number) => void;
|
|
29
|
+
updateRevenueEstimate: (paidUsers: number, averageMonthlyRate?: number) => void;
|
|
30
|
+
recordConversion: (conversionType: "free_to_paid" | "trial_to_paid" | "upgrade", source: string) => void;
|
|
31
|
+
updateErrorRate: () => void;
|
|
32
|
+
getMetrics: () => Promise<string>;
|
|
33
|
+
initialize: () => NodeJS.Timeout;
|
|
34
|
+
};
|
|
35
|
+
export { register };
|
|
36
|
+
export default metrics;
|
|
37
|
+
//# sourceMappingURL=metrics.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"metrics.d.ts","sourceRoot":"","sources":["../src/metrics.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,MAAM,MAAM,aAAa,CAAC;AAIjC,QAAA,MAAM,QAAQ,6DAAwB,CAAC;AAavC,eAAO,MAAM,eAAe;;;;;;;;;;;;CA6E3B,CAAC;AAQF,eAAO,MAAM,OAAO;gCAEU,MAAM,WAAW,OAAO,YAAY,MAAM,GAAG,MAAM,GAAG,WAAW;iCAiBhE,MAAM,UAAU,MAAM,cAAc,MAAM,mBAAmB,MAAM,YAAY,MAAM;6BAsBzF,MAAM,WAAW,MAAM,YAAY,KAAK,GAAG,QAAQ,GAAG,MAAM,GAAG,UAAU;gCAYtE,MAAM,aAAa,MAAM,kBAAkB,MAAM;mCAO9C,MAAM,aAAa,MAAM,mBAAmB,MAAM;;qCAkBhD,MAAM;uCAKJ,MAAM,uBAAsB,MAAM;uCAMlC,cAAc,GAAG,eAAe,GAAG,SAAS,UAAU,MAAM;;sBAiBzE,OAAO,CAAC,MAAM,CAAC;;CAqCtC,CAAC;AAGF,OAAO,EAAE,QAAQ,EAAE,CAAC;AAGpB,eAAe,OAAO,CAAC"}
|
package/dist/metrics.js
ADDED
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Prometheus metrics for LeafEngines MCP Server
|
|
4
|
+
*
|
|
5
|
+
* Provides business and performance metrics for monitoring
|
|
6
|
+
*/
|
|
7
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
8
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
9
|
+
};
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.register = exports.metrics = exports.businessMetrics = void 0;
|
|
12
|
+
const prom_client_1 = __importDefault(require("prom-client"));
|
|
13
|
+
const logger_js_1 = require("./logger.js");
|
|
14
|
+
// Create a Registry to register metrics
|
|
15
|
+
const register = new prom_client_1.default.Registry();
|
|
16
|
+
exports.register = register;
|
|
17
|
+
// Set default labels (applied to all metrics)
|
|
18
|
+
register.setDefaultLabels({
|
|
19
|
+
app: 'leafengines-mcp-server',
|
|
20
|
+
version: process.env.npm_package_version || '1.1.9',
|
|
21
|
+
environment: process.env.NODE_ENV || 'production'
|
|
22
|
+
});
|
|
23
|
+
// Enable collection of default metrics
|
|
24
|
+
prom_client_1.default.collectDefaultMetrics({ register });
|
|
25
|
+
// Business Metrics
|
|
26
|
+
exports.businessMetrics = {
|
|
27
|
+
// Tool usage counters
|
|
28
|
+
toolUsageCounter: new prom_client_1.default.Counter({
|
|
29
|
+
name: 'leafengines_tool_usage_total',
|
|
30
|
+
help: 'Total number of tool executions',
|
|
31
|
+
labelNames: ['tool_name', 'status', 'user_type']
|
|
32
|
+
}),
|
|
33
|
+
// API request metrics
|
|
34
|
+
apiRequestCounter: new prom_client_1.default.Counter({
|
|
35
|
+
name: 'leafengines_api_requests_total',
|
|
36
|
+
help: 'Total number of API requests',
|
|
37
|
+
labelNames: ['endpoint', 'method', 'status_code', 'user_type']
|
|
38
|
+
}),
|
|
39
|
+
// API response time histogram
|
|
40
|
+
apiResponseTimeHistogram: new prom_client_1.default.Histogram({
|
|
41
|
+
name: 'leafengines_api_response_time_seconds',
|
|
42
|
+
help: 'API response time in seconds',
|
|
43
|
+
labelNames: ['endpoint', 'method'],
|
|
44
|
+
buckets: [0.1, 0.5, 1, 2, 5, 10] // buckets in seconds
|
|
45
|
+
}),
|
|
46
|
+
// Error counter
|
|
47
|
+
errorCounter: new prom_client_1.default.Counter({
|
|
48
|
+
name: 'leafengines_errors_total',
|
|
49
|
+
help: 'Total number of errors',
|
|
50
|
+
labelNames: ['error_type', 'context', 'severity']
|
|
51
|
+
}),
|
|
52
|
+
// User type distribution
|
|
53
|
+
userTypeGauge: new prom_client_1.default.Gauge({
|
|
54
|
+
name: 'leafengines_user_type_current',
|
|
55
|
+
help: 'Current distribution of user types',
|
|
56
|
+
labelNames: ['user_type']
|
|
57
|
+
}),
|
|
58
|
+
// Feature usage
|
|
59
|
+
featureUsageCounter: new prom_client_1.default.Counter({
|
|
60
|
+
name: 'leafengines_feature_usage_total',
|
|
61
|
+
help: 'Total feature usage count',
|
|
62
|
+
labelNames: ['feature', 'user_type']
|
|
63
|
+
}),
|
|
64
|
+
// Performance metrics
|
|
65
|
+
performanceHistogram: new prom_client_1.default.Histogram({
|
|
66
|
+
name: 'leafengines_performance_seconds',
|
|
67
|
+
help: 'Performance timing for various operations',
|
|
68
|
+
labelNames: ['operation', 'component'],
|
|
69
|
+
buckets: [0.001, 0.005, 0.01, 0.05, 0.1, 0.5, 1, 2, 5]
|
|
70
|
+
}),
|
|
71
|
+
// Memory usage
|
|
72
|
+
memoryUsageGauge: new prom_client_1.default.Gauge({
|
|
73
|
+
name: 'leafengines_memory_usage_bytes',
|
|
74
|
+
help: 'Current memory usage in bytes',
|
|
75
|
+
labelNames: ['type']
|
|
76
|
+
}),
|
|
77
|
+
// Active connections
|
|
78
|
+
activeConnectionsGauge: new prom_client_1.default.Gauge({
|
|
79
|
+
name: 'leafengines_active_connections',
|
|
80
|
+
help: 'Number of active connections'
|
|
81
|
+
}),
|
|
82
|
+
// Business value metrics
|
|
83
|
+
revenueEstimateGauge: new prom_client_1.default.Gauge({
|
|
84
|
+
name: 'leafengines_revenue_estimate_usd',
|
|
85
|
+
help: 'Estimated revenue in USD (based on usage patterns)'
|
|
86
|
+
}),
|
|
87
|
+
// Conversion metrics
|
|
88
|
+
conversionCounter: new prom_client_1.default.Counter({
|
|
89
|
+
name: 'leafengines_conversions_total',
|
|
90
|
+
help: 'Total conversions (free to paid, etc.)',
|
|
91
|
+
labelNames: ['conversion_type', 'source']
|
|
92
|
+
})
|
|
93
|
+
};
|
|
94
|
+
// Register all metrics
|
|
95
|
+
Object.values(exports.businessMetrics).forEach(metric => {
|
|
96
|
+
register.registerMetric(metric);
|
|
97
|
+
});
|
|
98
|
+
// Metrics collection utilities
|
|
99
|
+
exports.metrics = {
|
|
100
|
+
// Record tool usage
|
|
101
|
+
recordToolUsage: (toolName, success, userType) => {
|
|
102
|
+
exports.businessMetrics.toolUsageCounter.inc({
|
|
103
|
+
tool_name: toolName,
|
|
104
|
+
status: success ? 'success' : 'error',
|
|
105
|
+
user_type: userType
|
|
106
|
+
});
|
|
107
|
+
// Also track as feature usage
|
|
108
|
+
exports.businessMetrics.featureUsageCounter.inc({
|
|
109
|
+
feature: `tool_${toolName}`,
|
|
110
|
+
user_type: userType
|
|
111
|
+
});
|
|
112
|
+
logger_js_1.logging.businessEvent('tool_usage_metric', { toolName, success, userType });
|
|
113
|
+
},
|
|
114
|
+
// Record API request
|
|
115
|
+
recordApiRequest: (endpoint, method, statusCode, durationSeconds, userType) => {
|
|
116
|
+
exports.businessMetrics.apiRequestCounter.inc({
|
|
117
|
+
endpoint,
|
|
118
|
+
method,
|
|
119
|
+
status_code: statusCode.toString(),
|
|
120
|
+
user_type: userType
|
|
121
|
+
});
|
|
122
|
+
exports.businessMetrics.apiResponseTimeHistogram.observe({
|
|
123
|
+
endpoint,
|
|
124
|
+
method
|
|
125
|
+
}, durationSeconds);
|
|
126
|
+
logger_js_1.logging.performance(`api_${endpoint}`, durationSeconds * 1000, {
|
|
127
|
+
endpoint,
|
|
128
|
+
method,
|
|
129
|
+
statusCode,
|
|
130
|
+
userType
|
|
131
|
+
});
|
|
132
|
+
},
|
|
133
|
+
// Record error
|
|
134
|
+
recordError: (errorType, context, severity) => {
|
|
135
|
+
exports.businessMetrics.errorCounter.inc({
|
|
136
|
+
error_type: errorType,
|
|
137
|
+
context,
|
|
138
|
+
severity
|
|
139
|
+
});
|
|
140
|
+
// Update error rate monitoring
|
|
141
|
+
exports.metrics.updateErrorRate();
|
|
142
|
+
},
|
|
143
|
+
// Update user type distribution
|
|
144
|
+
updateUserType: (freeUsers, paidUsers, anonymousUsers) => {
|
|
145
|
+
exports.businessMetrics.userTypeGauge.set({ user_type: 'free' }, freeUsers);
|
|
146
|
+
exports.businessMetrics.userTypeGauge.set({ user_type: 'paid' }, paidUsers);
|
|
147
|
+
exports.businessMetrics.userTypeGauge.set({ user_type: 'anonymous' }, anonymousUsers);
|
|
148
|
+
},
|
|
149
|
+
// Record performance timing
|
|
150
|
+
recordPerformance: (operation, component, durationSeconds) => {
|
|
151
|
+
exports.businessMetrics.performanceHistogram.observe({
|
|
152
|
+
operation,
|
|
153
|
+
component
|
|
154
|
+
}, durationSeconds);
|
|
155
|
+
},
|
|
156
|
+
// Update memory usage
|
|
157
|
+
updateMemoryUsage: () => {
|
|
158
|
+
const memoryUsage = process.memoryUsage();
|
|
159
|
+
exports.businessMetrics.memoryUsageGauge.set({ type: 'rss' }, memoryUsage.rss);
|
|
160
|
+
exports.businessMetrics.memoryUsageGauge.set({ type: 'heap_total' }, memoryUsage.heapTotal);
|
|
161
|
+
exports.businessMetrics.memoryUsageGauge.set({ type: 'heap_used' }, memoryUsage.heapUsed);
|
|
162
|
+
exports.businessMetrics.memoryUsageGauge.set({ type: 'external' }, memoryUsage.external);
|
|
163
|
+
},
|
|
164
|
+
// Update active connections
|
|
165
|
+
updateActiveConnections: (count) => {
|
|
166
|
+
exports.businessMetrics.activeConnectionsGauge.set(count);
|
|
167
|
+
},
|
|
168
|
+
// Update revenue estimate (simplified calculation)
|
|
169
|
+
updateRevenueEstimate: (paidUsers, averageMonthlyRate = 49) => {
|
|
170
|
+
const monthlyRevenue = paidUsers * averageMonthlyRate;
|
|
171
|
+
exports.businessMetrics.revenueEstimateGauge.set(monthlyRevenue);
|
|
172
|
+
},
|
|
173
|
+
// Record conversion
|
|
174
|
+
recordConversion: (conversionType, source) => {
|
|
175
|
+
exports.businessMetrics.conversionCounter.inc({
|
|
176
|
+
conversion_type: conversionType,
|
|
177
|
+
source
|
|
178
|
+
});
|
|
179
|
+
logger_js_1.logging.businessEvent('conversion_recorded', { conversionType, source });
|
|
180
|
+
},
|
|
181
|
+
// Calculate and update error rate
|
|
182
|
+
updateErrorRate: () => {
|
|
183
|
+
// This would typically query the metrics and calculate error rate
|
|
184
|
+
// For now, we'll just log that we're tracking it
|
|
185
|
+
logger_js_1.logging.businessEvent('error_rate_updated', {});
|
|
186
|
+
},
|
|
187
|
+
// Get metrics as string for Prometheus scraping
|
|
188
|
+
getMetrics: async () => {
|
|
189
|
+
try {
|
|
190
|
+
// Update runtime metrics
|
|
191
|
+
exports.metrics.updateMemoryUsage();
|
|
192
|
+
// Get all metrics
|
|
193
|
+
const metricsString = await register.metrics();
|
|
194
|
+
return metricsString;
|
|
195
|
+
}
|
|
196
|
+
catch (error) {
|
|
197
|
+
logger_js_1.logging.error('metrics_collection', error);
|
|
198
|
+
return '# Error collecting metrics\n';
|
|
199
|
+
}
|
|
200
|
+
},
|
|
201
|
+
// Initialize metrics collection
|
|
202
|
+
initialize: () => {
|
|
203
|
+
// Start periodic memory updates
|
|
204
|
+
const memoryUpdateInterval = setInterval(() => {
|
|
205
|
+
exports.metrics.updateMemoryUsage();
|
|
206
|
+
}, 30000); // Every 30 seconds
|
|
207
|
+
// Cleanup on shutdown
|
|
208
|
+
process.on('SIGINT', () => {
|
|
209
|
+
clearInterval(memoryUpdateInterval);
|
|
210
|
+
});
|
|
211
|
+
process.on('SIGTERM', () => {
|
|
212
|
+
clearInterval(memoryUpdateInterval);
|
|
213
|
+
});
|
|
214
|
+
logger_js_1.logging.businessEvent('metrics_initialized', {
|
|
215
|
+
default_labels: register.getDefaultLabels(),
|
|
216
|
+
metric_count: register.getMetricsAsArray().length
|
|
217
|
+
});
|
|
218
|
+
return memoryUpdateInterval;
|
|
219
|
+
}
|
|
220
|
+
};
|
|
221
|
+
// Default export
|
|
222
|
+
exports.default = exports.metrics;
|
|
223
|
+
//# sourceMappingURL=metrics.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"metrics.js","sourceRoot":"","sources":["../src/metrics.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;;;;AAEH,8DAAiC;AACjC,2CAAsC;AAEtC,wCAAwC;AACxC,MAAM,QAAQ,GAAG,IAAI,qBAAM,CAAC,QAAQ,EAAE,CAAC;AAoP9B,4BAAQ;AAlPjB,8CAA8C;AAC9C,QAAQ,CAAC,gBAAgB,CAAC;IACxB,GAAG,EAAE,wBAAwB;IAC7B,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,mBAAmB,IAAI,OAAO;IACnD,WAAW,EAAE,OAAO,CAAC,GAAG,CAAC,QAAQ,IAAI,YAAY;CAClD,CAAC,CAAC;AAEH,uCAAuC;AACvC,qBAAM,CAAC,qBAAqB,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC;AAE3C,mBAAmB;AACN,QAAA,eAAe,GAAG;IAC7B,sBAAsB;IACtB,gBAAgB,EAAE,IAAI,qBAAM,CAAC,OAAO,CAAC;QACnC,IAAI,EAAE,8BAA8B;QACpC,IAAI,EAAE,iCAAiC;QACvC,UAAU,EAAE,CAAC,WAAW,EAAE,QAAQ,EAAE,WAAW,CAAU;KAC1D,CAAC;IAEF,sBAAsB;IACtB,iBAAiB,EAAE,IAAI,qBAAM,CAAC,OAAO,CAAC;QACpC,IAAI,EAAE,gCAAgC;QACtC,IAAI,EAAE,8BAA8B;QACpC,UAAU,EAAE,CAAC,UAAU,EAAE,QAAQ,EAAE,aAAa,EAAE,WAAW,CAAU;KACxE,CAAC;IAEF,8BAA8B;IAC9B,wBAAwB,EAAE,IAAI,qBAAM,CAAC,SAAS,CAAC;QAC7C,IAAI,EAAE,uCAAuC;QAC7C,IAAI,EAAE,8BAA8B;QACpC,UAAU,EAAE,CAAC,UAAU,EAAE,Q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,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sentry error tracking for LeafEngines MCP Server
|
|
3
|
+
*
|
|
4
|
+
* Provides centralized error tracking and monitoring
|
|
5
|
+
*/
|
|
6
|
+
import * as Sentry from '@sentry/node';
|
|
7
|
+
export declare function initializeSentry(): typeof Sentry | null;
|
|
8
|
+
export declare const sentryTracking: {
|
|
9
|
+
captureError: (error: Error, context?: any) => void;
|
|
10
|
+
captureMessage: (message: string, level?: Sentry.SeverityLevel, context?: any) => void;
|
|
11
|
+
setUserContext: (userId: string, email?: string, additionalData?: any) => void;
|
|
12
|
+
clearUserContext: () => void;
|
|
13
|
+
addBreadcrumb: (message: string, category: string, data?: any) => void;
|
|
14
|
+
startTransaction: (name: string, operation: string) => any;
|
|
15
|
+
};
|
|
16
|
+
export default Sentry;
|
|
17
|
+
//# sourceMappingURL=sentry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sentry.d.ts","sourceRoot":"","sources":["../src/sentry.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,MAAM,MAAM,cAAc,CAAC;AAIvC,wBAAgB,gBAAgB,yBA4C/B;AAGD,eAAO,MAAM,cAAc;0BAEH,KAAK,YAAY,GAAG;8BAgBhB,MAAM,UAAS,MAAM,CAAC,aAAa,YAAqB,GAAG;6BAsB5D,MAAM,UAAU,MAAM,mBAAmB,GAAG;;6BAkB5C,MAAM,YAAY,MAAM,SAAS,GAAG;6BAapC,MAAM,aAAa,MAAM;CAanD,CAAC;AAGF,eAAe,MAAM,CAAC"}
|