nestjs-profiler 1.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/README.md +123 -0
- package/dist/libs/nestjs-profiler/package.json +34 -0
- package/dist/libs/nestjs-profiler/src/analyzers/explain-analyzer.d.ts +5 -0
- package/dist/libs/nestjs-profiler/src/analyzers/explain-analyzer.js +39 -0
- package/dist/libs/nestjs-profiler/src/analyzers/explain-analyzer.js.map +1 -0
- package/dist/libs/nestjs-profiler/src/assets/favicon.ico +0 -0
- package/dist/libs/nestjs-profiler/src/assets/logo.png +0 -0
- package/dist/libs/nestjs-profiler/src/collectors/cache-collector.d.ts +18 -0
- package/dist/libs/nestjs-profiler/src/collectors/cache-collector.js +178 -0
- package/dist/libs/nestjs-profiler/src/collectors/cache-collector.js.map +1 -0
- package/dist/libs/nestjs-profiler/src/collectors/log-collector.d.ts +12 -0
- package/dist/libs/nestjs-profiler/src/collectors/log-collector.js +68 -0
- package/dist/libs/nestjs-profiler/src/collectors/log-collector.js.map +1 -0
- package/dist/libs/nestjs-profiler/src/collectors/mongo-collector.d.ts +19 -0
- package/dist/libs/nestjs-profiler/src/collectors/mongo-collector.js +203 -0
- package/dist/libs/nestjs-profiler/src/collectors/mongo-collector.js.map +1 -0
- package/dist/libs/nestjs-profiler/src/collectors/mysql-collector.d.ts +12 -0
- package/dist/libs/nestjs-profiler/src/collectors/mysql-collector.js +131 -0
- package/dist/libs/nestjs-profiler/src/collectors/mysql-collector.js.map +1 -0
- package/dist/libs/nestjs-profiler/src/collectors/postgres-collector.d.ts +15 -0
- package/dist/libs/nestjs-profiler/src/collectors/postgres-collector.js +205 -0
- package/dist/libs/nestjs-profiler/src/collectors/postgres-collector.js.map +1 -0
- package/dist/libs/nestjs-profiler/src/common/profiler-options.interface.d.ts +20 -0
- package/dist/libs/nestjs-profiler/src/common/profiler-options.interface.js +3 -0
- package/dist/libs/nestjs-profiler/src/common/profiler-options.interface.js.map +1 -0
- package/dist/libs/nestjs-profiler/src/common/profiler.model.d.ts +67 -0
- package/dist/libs/nestjs-profiler/src/common/profiler.model.js +3 -0
- package/dist/libs/nestjs-profiler/src/common/profiler.model.js.map +1 -0
- package/dist/libs/nestjs-profiler/src/controllers/profiler.controller.d.ts +33 -0
- package/dist/libs/nestjs-profiler/src/controllers/profiler.controller.js +237 -0
- package/dist/libs/nestjs-profiler/src/controllers/profiler.controller.js.map +1 -0
- package/dist/libs/nestjs-profiler/src/index.d.ts +5 -0
- package/dist/libs/nestjs-profiler/src/index.js +22 -0
- package/dist/libs/nestjs-profiler/src/index.js.map +1 -0
- package/dist/libs/nestjs-profiler/src/interceptors/request-profiler.interceptor.d.ts +11 -0
- package/dist/libs/nestjs-profiler/src/interceptors/request-profiler.interceptor.js +104 -0
- package/dist/libs/nestjs-profiler/src/interceptors/request-profiler.interceptor.js.map +1 -0
- package/dist/libs/nestjs-profiler/src/middleware/profiler.middleware.d.ts +4 -0
- package/dist/libs/nestjs-profiler/src/middleware/profiler.middleware.js +21 -0
- package/dist/libs/nestjs-profiler/src/middleware/profiler.middleware.js.map +1 -0
- package/dist/libs/nestjs-profiler/src/profiler-logger.d.ts +12 -0
- package/dist/libs/nestjs-profiler/src/profiler-logger.js +61 -0
- package/dist/libs/nestjs-profiler/src/profiler-logger.js.map +1 -0
- package/dist/libs/nestjs-profiler/src/profiler.module.d.ts +7 -0
- package/dist/libs/nestjs-profiler/src/profiler.module.js +105 -0
- package/dist/libs/nestjs-profiler/src/profiler.module.js.map +1 -0
- package/dist/libs/nestjs-profiler/src/services/entity-explorer.service.d.ts +19 -0
- package/dist/libs/nestjs-profiler/src/services/entity-explorer.service.js +110 -0
- package/dist/libs/nestjs-profiler/src/services/entity-explorer.service.js.map +1 -0
- package/dist/libs/nestjs-profiler/src/services/profiler.service.d.ts +31 -0
- package/dist/libs/nestjs-profiler/src/services/profiler.service.js +218 -0
- package/dist/libs/nestjs-profiler/src/services/profiler.service.js.map +1 -0
- package/dist/libs/nestjs-profiler/src/services/route-explorer.service.d.ts +15 -0
- package/dist/libs/nestjs-profiler/src/services/route-explorer.service.js +93 -0
- package/dist/libs/nestjs-profiler/src/services/route-explorer.service.js.map +1 -0
- package/dist/libs/nestjs-profiler/src/services/template-builder.service.d.ts +27 -0
- package/dist/libs/nestjs-profiler/src/services/template-builder.service.js +349 -0
- package/dist/libs/nestjs-profiler/src/services/template-builder.service.js.map +1 -0
- package/dist/libs/nestjs-profiler/src/services/view.service.d.ts +17 -0
- package/dist/libs/nestjs-profiler/src/services/view.service.js +197 -0
- package/dist/libs/nestjs-profiler/src/services/view.service.js.map +1 -0
- package/dist/libs/nestjs-profiler/src/storage/in-memory-profiler-storage.d.ts +9 -0
- package/dist/libs/nestjs-profiler/src/storage/in-memory-profiler-storage.js +27 -0
- package/dist/libs/nestjs-profiler/src/storage/in-memory-profiler-storage.js.map +1 -0
- package/dist/libs/nestjs-profiler/src/storage/profiler-storage.interface.d.ts +6 -0
- package/dist/libs/nestjs-profiler/src/storage/profiler-storage.interface.js +3 -0
- package/dist/libs/nestjs-profiler/src/storage/profiler-storage.interface.js.map +1 -0
- package/dist/libs/nestjs-profiler/src/views/cache.html +50 -0
- package/dist/libs/nestjs-profiler/src/views/dashboard.html +73 -0
- package/dist/libs/nestjs-profiler/src/views/detail.html +66 -0
- package/dist/libs/nestjs-profiler/src/views/entities.html +76 -0
- package/dist/libs/nestjs-profiler/src/views/js/dashboard.js +24 -0
- package/dist/libs/nestjs-profiler/src/views/js/entities.js +37 -0
- package/dist/libs/nestjs-profiler/src/views/js/layout-config.js +15 -0
- package/dist/libs/nestjs-profiler/src/views/js/layout.js +143 -0
- package/dist/libs/nestjs-profiler/src/views/js/queries.js +28 -0
- package/dist/libs/nestjs-profiler/src/views/layout.html +252 -0
- package/dist/libs/nestjs-profiler/src/views/logs.html +37 -0
- package/dist/libs/nestjs-profiler/src/views/not_found.html +15 -0
- package/dist/libs/nestjs-profiler/src/views/partials/cache_row.html +20 -0
- package/dist/libs/nestjs-profiler/src/views/partials/detail_query_row.html +33 -0
- package/dist/libs/nestjs-profiler/src/views/partials/entity_row.html +39 -0
- package/dist/libs/nestjs-profiler/src/views/partials/log_row.html +19 -0
- package/dist/libs/nestjs-profiler/src/views/partials/metadata_sidebar.html +27 -0
- package/dist/libs/nestjs-profiler/src/views/partials/pagination.html +9 -0
- package/dist/libs/nestjs-profiler/src/views/partials/query_row.html +34 -0
- package/dist/libs/nestjs-profiler/src/views/partials/request_row.html +25 -0
- package/dist/libs/nestjs-profiler/src/views/partials/route_row.html +12 -0
- package/dist/libs/nestjs-profiler/src/views/queries.html +65 -0
- package/dist/libs/nestjs-profiler/src/views/routes.html +41 -0
- package/package.json +125 -0
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
export interface QueryProfile {
|
|
2
|
+
sql: string;
|
|
3
|
+
query?: string;
|
|
4
|
+
database?: 'postgres' | 'mongodb' | 'mysql';
|
|
5
|
+
operation?: string;
|
|
6
|
+
filter?: any;
|
|
7
|
+
params?: any[];
|
|
8
|
+
duration: number;
|
|
9
|
+
startTime: number;
|
|
10
|
+
rowCount?: number;
|
|
11
|
+
error?: string;
|
|
12
|
+
explainPlan?: any;
|
|
13
|
+
connection?: string;
|
|
14
|
+
tags?: string[];
|
|
15
|
+
duplicatedCount?: number;
|
|
16
|
+
planType?: string;
|
|
17
|
+
}
|
|
18
|
+
export interface LogProfile {
|
|
19
|
+
level: string;
|
|
20
|
+
message: string;
|
|
21
|
+
context?: string;
|
|
22
|
+
timestamp: number;
|
|
23
|
+
}
|
|
24
|
+
export interface CacheProfile {
|
|
25
|
+
key: string;
|
|
26
|
+
store: string;
|
|
27
|
+
operation: 'get' | 'set' | 'del' | 'reset' | 'unknown';
|
|
28
|
+
result: 'hit' | 'miss' | 'success' | 'fail' | null;
|
|
29
|
+
ttl?: number;
|
|
30
|
+
duration: number;
|
|
31
|
+
startTime: number;
|
|
32
|
+
value?: any;
|
|
33
|
+
}
|
|
34
|
+
export interface RequestProfile {
|
|
35
|
+
id: string;
|
|
36
|
+
method: string;
|
|
37
|
+
url: string;
|
|
38
|
+
route?: string;
|
|
39
|
+
controller?: string;
|
|
40
|
+
handler?: string;
|
|
41
|
+
startTime: number;
|
|
42
|
+
endTime?: number;
|
|
43
|
+
duration?: number;
|
|
44
|
+
statusCode?: number;
|
|
45
|
+
memory?: {
|
|
46
|
+
rss: number;
|
|
47
|
+
heapTotal: number;
|
|
48
|
+
heapUsed: number;
|
|
49
|
+
external: number;
|
|
50
|
+
arrayBuffers: number;
|
|
51
|
+
};
|
|
52
|
+
queries: QueryProfile[];
|
|
53
|
+
logs: LogProfile[];
|
|
54
|
+
cache?: CacheProfile[];
|
|
55
|
+
timestamp: number;
|
|
56
|
+
requestHeaders?: Record<string, any>;
|
|
57
|
+
requestBody?: any;
|
|
58
|
+
exception?: {
|
|
59
|
+
message: string;
|
|
60
|
+
stack: string;
|
|
61
|
+
};
|
|
62
|
+
timings?: {
|
|
63
|
+
total: number;
|
|
64
|
+
middleware: number;
|
|
65
|
+
handler: number;
|
|
66
|
+
};
|
|
67
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"profiler.model.js","sourceRoot":"","sources":["../../../../../libs/nestjs-profiler/src/common/profiler.model.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { Response } from 'express';
|
|
2
|
+
import { ProfilerService } from '../services/profiler.service';
|
|
3
|
+
import { ViewService } from '../services/view.service';
|
|
4
|
+
import { TemplateBuilderService } from '../services/template-builder.service';
|
|
5
|
+
import { EntityExplorerService } from '../services/entity-explorer.service';
|
|
6
|
+
import { RouteExplorerService } from '../services/route-explorer.service';
|
|
7
|
+
export declare class ProfilerController {
|
|
8
|
+
private readonly profilerService;
|
|
9
|
+
private readonly viewService;
|
|
10
|
+
private readonly templateBuilder;
|
|
11
|
+
private readonly entityExplorer;
|
|
12
|
+
private readonly routeExplorer;
|
|
13
|
+
constructor(profilerService: ProfilerService, viewService: ViewService, templateBuilder: TemplateBuilderService, entityExplorer: EntityExplorerService, routeExplorer: RouteExplorerService);
|
|
14
|
+
dashboard(res: Response): Promise<void>;
|
|
15
|
+
listJson(): Promise<import("..").RequestProfile[]>;
|
|
16
|
+
debugQuery(): Promise<{
|
|
17
|
+
status: string;
|
|
18
|
+
message: string;
|
|
19
|
+
tip?: undefined;
|
|
20
|
+
} | {
|
|
21
|
+
status: string;
|
|
22
|
+
message: string;
|
|
23
|
+
tip: string;
|
|
24
|
+
}>;
|
|
25
|
+
detail(id: string, res: Response): Promise<void>;
|
|
26
|
+
detailJson(id: string): Promise<import("..").RequestProfile>;
|
|
27
|
+
listQueries(res: Response): Promise<void>;
|
|
28
|
+
listLogs(res: Response, page?: number): Promise<void>;
|
|
29
|
+
listEntities(res: Response): Promise<void>;
|
|
30
|
+
listRoutes(res: Response): Promise<void>;
|
|
31
|
+
listCache(res: Response): Promise<void>;
|
|
32
|
+
serveAsset(file: string, res: Response): Promise<void>;
|
|
33
|
+
}
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.ProfilerController = void 0;
|
|
16
|
+
const common_1 = require("@nestjs/common");
|
|
17
|
+
const profiler_service_1 = require("../services/profiler.service");
|
|
18
|
+
const view_service_1 = require("../services/view.service");
|
|
19
|
+
const template_builder_service_1 = require("../services/template-builder.service");
|
|
20
|
+
const entity_explorer_service_1 = require("../services/entity-explorer.service");
|
|
21
|
+
const route_explorer_service_1 = require("../services/route-explorer.service");
|
|
22
|
+
let ProfilerController = class ProfilerController {
|
|
23
|
+
profilerService;
|
|
24
|
+
viewService;
|
|
25
|
+
templateBuilder;
|
|
26
|
+
entityExplorer;
|
|
27
|
+
routeExplorer;
|
|
28
|
+
constructor(profilerService, viewService, templateBuilder, entityExplorer, routeExplorer) {
|
|
29
|
+
this.profilerService = profilerService;
|
|
30
|
+
this.viewService = viewService;
|
|
31
|
+
this.templateBuilder = templateBuilder;
|
|
32
|
+
this.entityExplorer = entityExplorer;
|
|
33
|
+
this.routeExplorer = routeExplorer;
|
|
34
|
+
}
|
|
35
|
+
async dashboard(res) {
|
|
36
|
+
const profiles = await this.profilerService.getDashboardData();
|
|
37
|
+
const content = this.templateBuilder.buildDashboard(profiles);
|
|
38
|
+
const html = this.viewService.renderWithLayout('Requests', content, 'requests');
|
|
39
|
+
res.header('Content-Type', 'text/html');
|
|
40
|
+
res.send(html);
|
|
41
|
+
}
|
|
42
|
+
async listJson() {
|
|
43
|
+
return this.profilerService.getAllProfilesJson();
|
|
44
|
+
}
|
|
45
|
+
async debugQuery() {
|
|
46
|
+
const { Client } = require('pg');
|
|
47
|
+
const client = new Client({
|
|
48
|
+
host: process.env.DB_HOST || 'localhost',
|
|
49
|
+
port: 5432,
|
|
50
|
+
user: process.env.DB_USER || 'postgres',
|
|
51
|
+
password: process.env.DB_PASSWORD || 'postgres',
|
|
52
|
+
database: process.env.DB_NAME || 'postgres',
|
|
53
|
+
});
|
|
54
|
+
try {
|
|
55
|
+
await client.connect();
|
|
56
|
+
await client.query('SELECT 1 as test_query');
|
|
57
|
+
await client.end();
|
|
58
|
+
return { status: 'success', message: 'Query executed. Check profiler.' };
|
|
59
|
+
}
|
|
60
|
+
catch (e) {
|
|
61
|
+
return {
|
|
62
|
+
status: 'error',
|
|
63
|
+
message: `Connection failed: ${e.message}`,
|
|
64
|
+
tip: 'Pass correct credentials in URL: ?user=YOUR_USER&password=YOUR_PASS&database=YOUR_DB'
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
async detail(id, res) {
|
|
69
|
+
const profile = await this.profilerService.getProfileDetail(id);
|
|
70
|
+
if (!profile) {
|
|
71
|
+
const content = this.templateBuilder.buildNotFound(id);
|
|
72
|
+
const html = this.viewService.renderWithLayout('Profile Not Found', content);
|
|
73
|
+
res.header('Content-Type', 'text/html');
|
|
74
|
+
res.status(404).send(html);
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
const content = this.templateBuilder.buildDetail(profile);
|
|
78
|
+
const html = this.viewService.renderWithLayout(`Request ${profile.id}`, content);
|
|
79
|
+
res.header('Content-Type', 'text/html');
|
|
80
|
+
res.send(html);
|
|
81
|
+
}
|
|
82
|
+
async detailJson(id) {
|
|
83
|
+
const profile = await this.profilerService.getProfileJson(id);
|
|
84
|
+
if (!profile)
|
|
85
|
+
throw new common_1.NotFoundException('Profile not found');
|
|
86
|
+
return profile;
|
|
87
|
+
}
|
|
88
|
+
async listQueries(res) {
|
|
89
|
+
const queries = await this.profilerService.getQueriesList();
|
|
90
|
+
const content = this.templateBuilder.buildQueriesList(queries);
|
|
91
|
+
const html = this.viewService.renderWithLayout('Database Queries', content, 'queries');
|
|
92
|
+
res.header('Content-Type', 'text/html');
|
|
93
|
+
res.send(html);
|
|
94
|
+
}
|
|
95
|
+
async listLogs(res, page = 1) {
|
|
96
|
+
const { logs, currentPage, totalPages, totalLogs } = await this.profilerService.getLogsList(page);
|
|
97
|
+
const content = this.templateBuilder.buildLogsList(logs, currentPage, totalPages, totalLogs);
|
|
98
|
+
const html = this.viewService.renderWithLayout('Application Logs', content, 'logs');
|
|
99
|
+
res.header('Content-Type', 'text/html');
|
|
100
|
+
res.send(html);
|
|
101
|
+
}
|
|
102
|
+
async listEntities(res) {
|
|
103
|
+
const entities = this.entityExplorer.getEntities();
|
|
104
|
+
const content = this.templateBuilder.buildEntitiesList(entities);
|
|
105
|
+
const html = this.viewService.renderWithLayout('Entity Explorer', content, 'entities');
|
|
106
|
+
res.header('Content-Type', 'text/html');
|
|
107
|
+
res.send(html);
|
|
108
|
+
}
|
|
109
|
+
async listRoutes(res) {
|
|
110
|
+
const routes = this.routeExplorer.getRoutes();
|
|
111
|
+
const content = this.templateBuilder.buildRoutesList(routes);
|
|
112
|
+
const html = this.viewService.renderWithLayout('Routes Explorer', content, 'routes');
|
|
113
|
+
res.header('Content-Type', 'text/html');
|
|
114
|
+
res.send(html);
|
|
115
|
+
}
|
|
116
|
+
async listCache(res) {
|
|
117
|
+
const cacheOps = await this.profilerService.getCacheList();
|
|
118
|
+
const content = this.templateBuilder.buildCacheList(cacheOps);
|
|
119
|
+
const html = this.viewService.renderWithLayout('Cache Operations', content, 'cache');
|
|
120
|
+
res.header('Content-Type', 'text/html');
|
|
121
|
+
res.send(html);
|
|
122
|
+
}
|
|
123
|
+
async serveAsset(file, res) {
|
|
124
|
+
const fs = require('fs');
|
|
125
|
+
const path = require('path');
|
|
126
|
+
const assetsPath = path.join(__dirname, '..', 'assets');
|
|
127
|
+
const filePath = path.join(assetsPath, file);
|
|
128
|
+
if (fs.existsSync(filePath)) {
|
|
129
|
+
const ext = path.extname(file);
|
|
130
|
+
let contentType = 'text/plain';
|
|
131
|
+
if (ext === '.png')
|
|
132
|
+
contentType = 'image/png';
|
|
133
|
+
if (ext === '.ico')
|
|
134
|
+
contentType = 'image/x-icon';
|
|
135
|
+
if (ext === '.svg')
|
|
136
|
+
contentType = 'image/svg+xml';
|
|
137
|
+
if (ext === '.css')
|
|
138
|
+
contentType = 'text/css';
|
|
139
|
+
if (ext === '.js')
|
|
140
|
+
contentType = 'text/javascript';
|
|
141
|
+
res.header('Content-Type', contentType);
|
|
142
|
+
res.header('Cache-Control', 'public, max-age=86400');
|
|
143
|
+
fs.createReadStream(filePath).pipe(res);
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
res.status(404).send('Asset not found');
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
exports.ProfilerController = ProfilerController;
|
|
151
|
+
__decorate([
|
|
152
|
+
(0, common_1.Get)(),
|
|
153
|
+
__param(0, (0, common_1.Res)()),
|
|
154
|
+
__metadata("design:type", Function),
|
|
155
|
+
__metadata("design:paramtypes", [Object]),
|
|
156
|
+
__metadata("design:returntype", Promise)
|
|
157
|
+
], ProfilerController.prototype, "dashboard", null);
|
|
158
|
+
__decorate([
|
|
159
|
+
(0, common_1.Get)('json'),
|
|
160
|
+
__metadata("design:type", Function),
|
|
161
|
+
__metadata("design:paramtypes", []),
|
|
162
|
+
__metadata("design:returntype", Promise)
|
|
163
|
+
], ProfilerController.prototype, "listJson", null);
|
|
164
|
+
__decorate([
|
|
165
|
+
(0, common_1.Get)('debug/test-query'),
|
|
166
|
+
__metadata("design:type", Function),
|
|
167
|
+
__metadata("design:paramtypes", []),
|
|
168
|
+
__metadata("design:returntype", Promise)
|
|
169
|
+
], ProfilerController.prototype, "debugQuery", null);
|
|
170
|
+
__decorate([
|
|
171
|
+
(0, common_1.Get)(':id'),
|
|
172
|
+
__param(0, (0, common_1.Param)('id')),
|
|
173
|
+
__param(1, (0, common_1.Res)()),
|
|
174
|
+
__metadata("design:type", Function),
|
|
175
|
+
__metadata("design:paramtypes", [String, Object]),
|
|
176
|
+
__metadata("design:returntype", Promise)
|
|
177
|
+
], ProfilerController.prototype, "detail", null);
|
|
178
|
+
__decorate([
|
|
179
|
+
(0, common_1.Get)(':id/json'),
|
|
180
|
+
__param(0, (0, common_1.Param)('id')),
|
|
181
|
+
__metadata("design:type", Function),
|
|
182
|
+
__metadata("design:paramtypes", [String]),
|
|
183
|
+
__metadata("design:returntype", Promise)
|
|
184
|
+
], ProfilerController.prototype, "detailJson", null);
|
|
185
|
+
__decorate([
|
|
186
|
+
(0, common_1.Get)('view/queries'),
|
|
187
|
+
__param(0, (0, common_1.Res)()),
|
|
188
|
+
__metadata("design:type", Function),
|
|
189
|
+
__metadata("design:paramtypes", [Object]),
|
|
190
|
+
__metadata("design:returntype", Promise)
|
|
191
|
+
], ProfilerController.prototype, "listQueries", null);
|
|
192
|
+
__decorate([
|
|
193
|
+
(0, common_1.Get)('view/logs'),
|
|
194
|
+
__param(0, (0, common_1.Res)()),
|
|
195
|
+
__param(1, (0, common_1.Query)('page')),
|
|
196
|
+
__metadata("design:type", Function),
|
|
197
|
+
__metadata("design:paramtypes", [Object, Number]),
|
|
198
|
+
__metadata("design:returntype", Promise)
|
|
199
|
+
], ProfilerController.prototype, "listLogs", null);
|
|
200
|
+
__decorate([
|
|
201
|
+
(0, common_1.Get)('view/entities'),
|
|
202
|
+
__param(0, (0, common_1.Res)()),
|
|
203
|
+
__metadata("design:type", Function),
|
|
204
|
+
__metadata("design:paramtypes", [Object]),
|
|
205
|
+
__metadata("design:returntype", Promise)
|
|
206
|
+
], ProfilerController.prototype, "listEntities", null);
|
|
207
|
+
__decorate([
|
|
208
|
+
(0, common_1.Get)('view/routes'),
|
|
209
|
+
__param(0, (0, common_1.Res)()),
|
|
210
|
+
__metadata("design:type", Function),
|
|
211
|
+
__metadata("design:paramtypes", [Object]),
|
|
212
|
+
__metadata("design:returntype", Promise)
|
|
213
|
+
], ProfilerController.prototype, "listRoutes", null);
|
|
214
|
+
__decorate([
|
|
215
|
+
(0, common_1.Get)('view/cache'),
|
|
216
|
+
__param(0, (0, common_1.Res)()),
|
|
217
|
+
__metadata("design:type", Function),
|
|
218
|
+
__metadata("design:paramtypes", [Object]),
|
|
219
|
+
__metadata("design:returntype", Promise)
|
|
220
|
+
], ProfilerController.prototype, "listCache", null);
|
|
221
|
+
__decorate([
|
|
222
|
+
(0, common_1.Get)('assets/:file'),
|
|
223
|
+
__param(0, (0, common_1.Param)('file')),
|
|
224
|
+
__param(1, (0, common_1.Res)()),
|
|
225
|
+
__metadata("design:type", Function),
|
|
226
|
+
__metadata("design:paramtypes", [String, Object]),
|
|
227
|
+
__metadata("design:returntype", Promise)
|
|
228
|
+
], ProfilerController.prototype, "serveAsset", null);
|
|
229
|
+
exports.ProfilerController = ProfilerController = __decorate([
|
|
230
|
+
(0, common_1.Controller)('__profiler'),
|
|
231
|
+
__metadata("design:paramtypes", [profiler_service_1.ProfilerService,
|
|
232
|
+
view_service_1.ViewService,
|
|
233
|
+
template_builder_service_1.TemplateBuilderService,
|
|
234
|
+
entity_explorer_service_1.EntityExplorerService,
|
|
235
|
+
route_explorer_service_1.RouteExplorerService])
|
|
236
|
+
], ProfilerController);
|
|
237
|
+
//# sourceMappingURL=profiler.controller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"profiler.controller.js","sourceRoot":"","sources":["../../../../../libs/nestjs-profiler/src/controllers/profiler.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAA+F;AAE/F,mEAA+D;AAC/D,2DAAuD;AACvD,mFAA8E;AAC9E,iFAA4E;AAE5E,+EAA0E;AAGnE,IAAM,kBAAkB,GAAxB,MAAM,kBAAkB;IAEN;IACA;IACA;IACA;IACA;IALrB,YACqB,eAAgC,EAChC,WAAwB,EACxB,eAAuC,EACvC,cAAqC,EACrC,aAAmC;QAJnC,oBAAe,GAAf,eAAe,CAAiB;QAChC,gBAAW,GAAX,WAAW,CAAa;QACxB,oBAAe,GAAf,eAAe,CAAwB;QACvC,mBAAc,GAAd,cAAc,CAAuB;QACrC,kBAAa,GAAb,aAAa,CAAsB;IACpD,CAAC;IAGC,AAAN,KAAK,CAAC,SAAS,CAAQ,GAAa;QACh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,EAAC,UAAU,CAAC;IACE,WAAA,IAAA,cAAK,EAAC,IAAI,CAAC,CAAA;;;;oDAI5B;AAGK;IADL,IAAA,YAAG,EAAC,cAAc,CAAC;IACD,WAAA,IAAA,YAAG,GAAE,CAAA;;;;qDAOvB;AAGK;IADL,IAAA,YAAG,EAAC,WAAW,CAAC;IACD,WAAA,IAAA,YAAG,GAAE,CAAA;IAAiB,WAAA,IAAA,cAAK,EAAC,MAAM,CAAC,CAAA;;;;kDAOlD;AAGK;IADL,IAAA,YAAG,EAAC,eAAe,CAAC;IACD,WAAA,IAAA,YAAG,GAAE,CAAA;;;;sDAOxB;AAGK;IADL,IAAA,YAAG,EAAC,aAAa,CAAC;IACD,WAAA,IAAA,YAAG,GAAE,CAAA;;;;oDAOtB;AAGK;IADL,IAAA,YAAG,EAAC,YAAY,CAAC;IACD,WAAA,IAAA,YAAG,GAAE,CAAA;;;;mDAOrB;AAGK;IADL,IAAA,YAAG,EAAC,cAAc,CAAC;IACF,WAAA,IAAA,cAAK,EAAC,MAAM,CAAC,CAAA;IAAgB,WAAA,IAAA,YAAG,GAAE,CAAA;;;;oDAsBnD;6BArJQ,kBAAkB;IAD9B,IAAA,mBAAU,EAAC,YAAY,CAAC;qCAGiB,kCAAe;QACnB,0BAAW;QACP,iDAAsB;QACvB,+CAAqB;QACtB,6CAAoB;GAN/C,kBAAkB,CAsJ9B"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./profiler.module"), exports);
|
|
18
|
+
__exportStar(require("./services/profiler.service"), exports);
|
|
19
|
+
__exportStar(require("./profiler-logger"), exports);
|
|
20
|
+
__exportStar(require("./common/profiler.model"), exports);
|
|
21
|
+
__exportStar(require("./services/entity-explorer.service"), exports);
|
|
22
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../libs/nestjs-profiler/src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oDAAkC;AAClC,8DAA4C;AAC5C,oDAAkC;AAClC,0DAAwC;AACxC,qEAAmD"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { CallHandler, ExecutionContext, NestInterceptor } from '@nestjs/common';
|
|
2
|
+
import { Observable } from 'rxjs';
|
|
3
|
+
import { ProfilerService } from '../services/profiler.service';
|
|
4
|
+
export declare class RequestProfilerInterceptor implements NestInterceptor {
|
|
5
|
+
private profiler;
|
|
6
|
+
private logger;
|
|
7
|
+
constructor(profiler: ProfilerService);
|
|
8
|
+
intercept(context: ExecutionContext, next: CallHandler): Observable<any>;
|
|
9
|
+
private finishProfile;
|
|
10
|
+
private sanitizeHeaders;
|
|
11
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var RequestProfilerInterceptor_1;
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.RequestProfilerInterceptor = void 0;
|
|
14
|
+
const common_1 = require("@nestjs/common");
|
|
15
|
+
const operators_1 = require("rxjs/operators");
|
|
16
|
+
const profiler_service_1 = require("../services/profiler.service");
|
|
17
|
+
let RequestProfilerInterceptor = RequestProfilerInterceptor_1 = class RequestProfilerInterceptor {
|
|
18
|
+
profiler;
|
|
19
|
+
logger = new common_1.Logger(RequestProfilerInterceptor_1.name);
|
|
20
|
+
constructor(profiler) {
|
|
21
|
+
this.profiler = profiler;
|
|
22
|
+
}
|
|
23
|
+
intercept(context, next) {
|
|
24
|
+
const http = context.switchToHttp();
|
|
25
|
+
const req = http.getRequest();
|
|
26
|
+
const res = http.getResponse();
|
|
27
|
+
if (process.env.PROFILER_DEBUG) {
|
|
28
|
+
this.logger.debug(`Starting profile for ${req.method} ${req.url}`);
|
|
29
|
+
}
|
|
30
|
+
if (!req || !res || req.url.startsWith('/__profiler') || req.url.includes('favicon.ico') || req.method === 'OPTIONS') {
|
|
31
|
+
return next.handle();
|
|
32
|
+
}
|
|
33
|
+
if (req._profilerAttached) {
|
|
34
|
+
return next.handle();
|
|
35
|
+
}
|
|
36
|
+
req._profilerAttached = true;
|
|
37
|
+
const interceptorStartTime = Date.now();
|
|
38
|
+
const middlewareStartTime = req._profilerT0 || interceptorStartTime;
|
|
39
|
+
const profile = this.profiler.startRequest();
|
|
40
|
+
if (profile) {
|
|
41
|
+
profile.method = req.method;
|
|
42
|
+
profile.url = req.originalUrl || req.url;
|
|
43
|
+
profile.controller = context.getClass().name;
|
|
44
|
+
profile.handler = context.getHandler().name;
|
|
45
|
+
profile.requestHeaders = this.sanitizeHeaders(req.headers);
|
|
46
|
+
profile.requestBody = req.body;
|
|
47
|
+
}
|
|
48
|
+
return next.handle().pipe((0, operators_1.tap)({
|
|
49
|
+
next: () => {
|
|
50
|
+
if (profile) {
|
|
51
|
+
profile.statusCode = res.statusCode;
|
|
52
|
+
this.finishProfile(profile, interceptorStartTime, middlewareStartTime);
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
error: (err) => {
|
|
56
|
+
if (profile) {
|
|
57
|
+
const status = err.status || err.statusCode || 500;
|
|
58
|
+
profile.statusCode = status;
|
|
59
|
+
profile.exception = {
|
|
60
|
+
message: err.message,
|
|
61
|
+
stack: err.stack
|
|
62
|
+
};
|
|
63
|
+
profile.queries.push({
|
|
64
|
+
sql: 'ERROR_CONTEXT',
|
|
65
|
+
duration: 0,
|
|
66
|
+
startTime: Date.now(),
|
|
67
|
+
error: err.message,
|
|
68
|
+
database: 'postgres',
|
|
69
|
+
});
|
|
70
|
+
this.finishProfile(profile, interceptorStartTime, middlewareStartTime);
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
}));
|
|
74
|
+
}
|
|
75
|
+
finishProfile(profile, interceptorStartTime, middlewareStartTime) {
|
|
76
|
+
const endTime = Date.now();
|
|
77
|
+
const totalDuration = endTime - middlewareStartTime;
|
|
78
|
+
const middlewareDuration = interceptorStartTime - middlewareStartTime;
|
|
79
|
+
const handlerDuration = endTime - interceptorStartTime;
|
|
80
|
+
profile.timings = {
|
|
81
|
+
total: totalDuration,
|
|
82
|
+
middleware: Math.max(0, middlewareDuration),
|
|
83
|
+
handler: Math.max(0, handlerDuration)
|
|
84
|
+
};
|
|
85
|
+
profile.duration = totalDuration;
|
|
86
|
+
this.profiler.endRequest(profile);
|
|
87
|
+
}
|
|
88
|
+
sanitizeHeaders(headers) {
|
|
89
|
+
const sanitized = { ...headers };
|
|
90
|
+
const sensitive = ['authorization', 'cookie', 'set-cookie', 'x-api-key'];
|
|
91
|
+
sensitive.forEach(key => {
|
|
92
|
+
if (sanitized[key]) {
|
|
93
|
+
sanitized[key] = '*** MASKED ***';
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
return sanitized;
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
exports.RequestProfilerInterceptor = RequestProfilerInterceptor;
|
|
100
|
+
exports.RequestProfilerInterceptor = RequestProfilerInterceptor = RequestProfilerInterceptor_1 = __decorate([
|
|
101
|
+
(0, common_1.Injectable)(),
|
|
102
|
+
__metadata("design:paramtypes", [profiler_service_1.ProfilerService])
|
|
103
|
+
], RequestProfilerInterceptor);
|
|
104
|
+
//# sourceMappingURL=request-profiler.interceptor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request-profiler.interceptor.js","sourceRoot":"","sources":["../../../../../libs/nestjs-profiler/src/interceptors/request-profiler.interceptor.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,2CAAoG;AAEpG,8CAAiD;AACjD,mEAA+D;AAGxD,IAAM,0BAA0B,kCAAhC,MAAM,0BAA0B;IAGf;IAFZ,MAAM,GAAG,IAAI,eAAM,CAAC,4BAA0B,CAAC,IAAI,CAAC,CAAC;IAE7D,YAAoB,QAAyB;QAAzB,aAAQ,GAAR,QAAQ,CAAiB;IAAI,CAAC;IAElD,SAAS,CAAC,OAAyB,EAAE,IAAiB;QAClD,MAAM,IAAI,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC;QACpC,MAAM,GAAG,GAAG,IAAI,CAAC,UAAU,EAAE,CAAC;QAC9B,MAAM,GAAG,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;QAE/B,IAAI,OAAO,CAAC,G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,KAAK,EAAE,aAAa;YACpB,UAAU,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,kBAAkB,CAAC;YAC3C,OAAO,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,eAAe,CAAC;SACxC,CAAC;QAEF,OAAO,CAAC,QAAQ,GAAG,aAAa,CAAC;QAEjC,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;IACtC,CAAC;IAEO,eAAe,CAAC,OAAY;QAChC,MAAM,SAAS,GAAG,EAAE,GAAG,OAAO,EAAE,CAAC;QACjC,MAAM,SAAS,GAAG,CAAC,eAAe,EAAE,QAAQ,EAAE,YAAY,EAAE,WAAW,CAAC,CAAC;QAEzE,SAAS,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;YACpB,IAAI,SAAS,CAAC,GAAG,CAAC,EAAE,CAAC;gBACjB,SAAS,CAAC,GAAG,CAAC,GAAG,gBAAgB,CAAC;YACtC,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,OAAO,SAAS,CAAC;IACrB,CAAC;CACJ,CAAA;AAnGY,gEAA0B;qCAA1B,0BAA0B;IADtC,IAAA,mBAAU,GAAE;qCAIqB,kCAAe;GAHpC,0BAA0B,CAmGtC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.ProfilerMiddleware = void 0;
|
|
10
|
+
const common_1 = require("@nestjs/common");
|
|
11
|
+
let ProfilerMiddleware = class ProfilerMiddleware {
|
|
12
|
+
use(req, res, next) {
|
|
13
|
+
req._profilerT0 = Date.now();
|
|
14
|
+
next();
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
exports.ProfilerMiddleware = ProfilerMiddleware;
|
|
18
|
+
exports.ProfilerMiddleware = ProfilerMiddleware = __decorate([
|
|
19
|
+
(0, common_1.Injectable)()
|
|
20
|
+
], ProfilerMiddleware);
|
|
21
|
+
//# sourceMappingURL=profiler.middleware.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"profiler.middleware.js","sourceRoot":"","sources":["../../../../../libs/nestjs-profiler/src/middleware/profiler.middleware.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAA4D;AAGrD,IAAM,kBAAkB,GAAxB,MAAM,kBAAkB;IAC3B,GAAG,CAAC,GAAQ,EAAE,GAAQ,EAAE,IAAgB;QACpC,GAAG,CAAC,WAAW,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QAC7B,IAAI,EAAE,CAAC;IACX,CAAC;CACJ,CAAA;AALY,gDAAkB;6BAAlB,kBAAkB;IAD9B,IAAA,mBAAU,GAAE;GACA,kBAAkB,CAK9B"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ConsoleLogger } from '@nestjs/common';
|
|
2
|
+
import { ProfilerService } from './services/profiler.service';
|
|
3
|
+
export declare class ProfilerLogger extends ConsoleLogger {
|
|
4
|
+
private profiler;
|
|
5
|
+
constructor(profiler: ProfilerService);
|
|
6
|
+
log(message: any, ...optionalParams: any[]): void;
|
|
7
|
+
error(message: any, ...optionalParams: any[]): void;
|
|
8
|
+
warn(message: any, ...optionalParams: any[]): void;
|
|
9
|
+
debug(message: any, ...optionalParams: any[]): void;
|
|
10
|
+
verbose(message: any, ...optionalParams: any[]): void;
|
|
11
|
+
private captureLog;
|
|
12
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.ProfilerLogger = void 0;
|
|
13
|
+
const common_1 = require("@nestjs/common");
|
|
14
|
+
const profiler_service_1 = require("./services/profiler.service");
|
|
15
|
+
let ProfilerLogger = class ProfilerLogger extends common_1.ConsoleLogger {
|
|
16
|
+
profiler;
|
|
17
|
+
constructor(profiler) {
|
|
18
|
+
super();
|
|
19
|
+
this.profiler = profiler;
|
|
20
|
+
}
|
|
21
|
+
log(message, ...optionalParams) {
|
|
22
|
+
super.log(message, ...optionalParams);
|
|
23
|
+
this.captureLog('log', message, optionalParams);
|
|
24
|
+
}
|
|
25
|
+
error(message, ...optionalParams) {
|
|
26
|
+
super.error(message, ...optionalParams);
|
|
27
|
+
this.captureLog('error', message, optionalParams);
|
|
28
|
+
}
|
|
29
|
+
warn(message, ...optionalParams) {
|
|
30
|
+
super.warn(message, ...optionalParams);
|
|
31
|
+
this.captureLog('warn', message, optionalParams);
|
|
32
|
+
}
|
|
33
|
+
debug(message, ...optionalParams) {
|
|
34
|
+
super.debug(message, ...optionalParams);
|
|
35
|
+
this.captureLog('debug', message, optionalParams);
|
|
36
|
+
}
|
|
37
|
+
verbose(message, ...optionalParams) {
|
|
38
|
+
super.verbose(message, ...optionalParams);
|
|
39
|
+
this.captureLog('verbose', message, optionalParams);
|
|
40
|
+
}
|
|
41
|
+
captureLog(level, message, params) {
|
|
42
|
+
try {
|
|
43
|
+
const context = params.length > 0 ? params[params.length - 1] : undefined;
|
|
44
|
+
const msgStr = typeof message === 'object' ? JSON.stringify(message) : String(message);
|
|
45
|
+
this.profiler.addLog({
|
|
46
|
+
level,
|
|
47
|
+
message: msgStr,
|
|
48
|
+
context: typeof context === 'string' ? context : undefined,
|
|
49
|
+
timestamp: Date.now()
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
catch (e) {
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
exports.ProfilerLogger = ProfilerLogger;
|
|
57
|
+
exports.ProfilerLogger = ProfilerLogger = __decorate([
|
|
58
|
+
(0, common_1.Injectable)({ scope: common_1.Scope.TRANSIENT }),
|
|
59
|
+
__metadata("design:paramtypes", [profiler_service_1.ProfilerService])
|
|
60
|
+
], ProfilerLogger);
|
|
61
|
+
//# sourceMappingURL=profiler-logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"profiler-logger.js","sourceRoot":"","sources":["../../../../libs/nestjs-profiler/src/profiler-logger.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAAkE;AAClE,kEAA8D;AAGvD,IAAM,cAAc,GAApB,MAAM,cAAe,SAAQ,sBAAa;IACzB;IAApB,YAAoB,QAAyB;QACzC,KAAK,EAAE,CAAC;QADQ,aAAQ,GAAR,QAAQ,CAAiB;IAE7C,CAAC;IAED,GAAG,CAAC,OAAY,EAAE,GAAG,cAAqB;QACtC,KAAK,CAAC,GAAG,CAAC,OAAO,EAAE,GAAG,cAAc,CAAC,CAAC;QACtC,IAAI,CAAC,UAAU,CA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AAM,CAAC;gBACjB,KAAK;gBACL,OAAO,EAAE,MAAM;gBACf,OAAO,EAAE,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS;gBAC1D,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;aACxB,CAAC,CAAC;QACP,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;QAEb,CAAC;IACL,CAAC;CACJ,CAAA;AA9CY,wCAAc;yBAAd,cAAc;IAD1B,IAAA,mBAAU,EAAC,EAAE,KAAK,EAAE,cAAK,CAAC,SAAS,EAAE,CAAC;qCAEL,kCAAe;GADpC,cAAc,CA8C1B"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { DynamicModule, MiddlewareConsumer, NestModule } from '@nestjs/common';
|
|
2
|
+
import { ProfilerOptions } from './common/profiler-options.interface';
|
|
3
|
+
export declare class ProfilerModule implements NestModule {
|
|
4
|
+
configure(consumer: MiddlewareConsumer): void;
|
|
5
|
+
static forRoot(options?: ProfilerOptions): DynamicModule;
|
|
6
|
+
static initialize(app: any): void;
|
|
7
|
+
}
|