plutin 1.7.7 → 1.7.11
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/dist/index.cjs +2564 -10077
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +338 -162
- package/dist/index.d.ts +338 -162
- package/dist/index.mjs +2529 -10077
- package/dist/index.mjs.map +1 -1
- package/package.json +19 -16
- package/readme.md +36 -30
package/dist/index.d.cts
CHANGED
|
@@ -1,9 +1,71 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import winston from 'winston';
|
|
2
|
+
import { FastifyInstance } from 'fastify';
|
|
3
|
+
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
4
|
+
import { LoggerProvider } from '@opentelemetry/sdk-logs';
|
|
6
5
|
import { NodeSDK } from '@opentelemetry/sdk-node';
|
|
6
|
+
import { Span, trace } from '@opentelemetry/api';
|
|
7
|
+
|
|
8
|
+
declare const baseEnvSchema: z.ZodObject<{
|
|
9
|
+
NODE_ENV: z.ZodDefault<z.ZodEnum<["test", "development", "production"]>>;
|
|
10
|
+
ENVIRONMENT: z.ZodDefault<z.ZodEnum<["test", "development", "staging", "production"]>>;
|
|
11
|
+
PORT: z.ZodDefault<z.ZodNumber>;
|
|
12
|
+
DISCORD_WEBHOOK_URL: z.ZodOptional<z.ZodString>;
|
|
13
|
+
OTEL_ENABLE: z.ZodDefault<z.ZodEffects<z.ZodString, boolean, string>>;
|
|
14
|
+
OTEL_EXPORTER_OTLP_ENDPOINT: z.ZodOptional<z.ZodString>;
|
|
15
|
+
OTEL_SERVICE_NAME: z.ZodOptional<z.ZodString>;
|
|
16
|
+
OTEL_SERVICE_VERSION: z.ZodOptional<z.ZodString>;
|
|
17
|
+
}, "strip", z.ZodTypeAny, {
|
|
18
|
+
NODE_ENV: "test" | "development" | "production";
|
|
19
|
+
ENVIRONMENT: "test" | "development" | "production" | "staging";
|
|
20
|
+
PORT: number;
|
|
21
|
+
OTEL_ENABLE: boolean;
|
|
22
|
+
DISCORD_WEBHOOK_URL?: string | undefined;
|
|
23
|
+
OTEL_EXPORTER_OTLP_ENDPOINT?: string | undefined;
|
|
24
|
+
OTEL_SERVICE_NAME?: string | undefined;
|
|
25
|
+
OTEL_SERVICE_VERSION?: string | undefined;
|
|
26
|
+
}, {
|
|
27
|
+
NODE_ENV?: "test" | "development" | "production" | undefined;
|
|
28
|
+
ENVIRONMENT?: "test" | "development" | "production" | "staging" | undefined;
|
|
29
|
+
PORT?: number | undefined;
|
|
30
|
+
DISCORD_WEBHOOK_URL?: string | undefined;
|
|
31
|
+
OTEL_ENABLE?: string | undefined;
|
|
32
|
+
OTEL_EXPORTER_OTLP_ENDPOINT?: string | undefined;
|
|
33
|
+
OTEL_SERVICE_NAME?: string | undefined;
|
|
34
|
+
OTEL_SERVICE_VERSION?: string | undefined;
|
|
35
|
+
}>;
|
|
36
|
+
|
|
37
|
+
type LogParams = {
|
|
38
|
+
msg: string;
|
|
39
|
+
data?: {
|
|
40
|
+
correlationId?: string;
|
|
41
|
+
[key: string]: any;
|
|
42
|
+
};
|
|
43
|
+
error?: Error;
|
|
44
|
+
};
|
|
45
|
+
interface ILogger {
|
|
46
|
+
info(data: LogParams): void;
|
|
47
|
+
error(data: LogParams): void;
|
|
48
|
+
debug(data: LogParams): void;
|
|
49
|
+
fatal(data: LogParams): void;
|
|
50
|
+
warn(data: LogParams): void;
|
|
51
|
+
}
|
|
52
|
+
type OptionsNotifications = 'console' | 'discord' | 'otel';
|
|
53
|
+
type Props$1 = {
|
|
54
|
+
development?: OptionsNotifications;
|
|
55
|
+
staging?: OptionsNotifications;
|
|
56
|
+
production?: OptionsNotifications;
|
|
57
|
+
};
|
|
58
|
+
declare class Logger {
|
|
59
|
+
static define(env: z.infer<typeof baseEnvSchema>, definitions?: Props$1): any;
|
|
60
|
+
private static defineProvider;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
declare class GlobalListener {
|
|
64
|
+
private readonly callback;
|
|
65
|
+
protected readonly logger: ILogger;
|
|
66
|
+
constructor(callback: () => Promise<void>);
|
|
67
|
+
register(): void;
|
|
68
|
+
}
|
|
7
69
|
|
|
8
70
|
type AnyObject = Record<string, any>;
|
|
9
71
|
type Request = {
|
|
@@ -34,7 +96,7 @@ type ContextError = {
|
|
|
34
96
|
};
|
|
35
97
|
};
|
|
36
98
|
declare abstract class BaseController {
|
|
37
|
-
protected readonly
|
|
99
|
+
protected readonly logger: ILogger;
|
|
38
100
|
abstract handle<T>(request: T | Request): Promise<Response>;
|
|
39
101
|
constructor();
|
|
40
102
|
protected success<T>(dto?: T): Response;
|
|
@@ -46,17 +108,6 @@ declare abstract class BaseController {
|
|
|
46
108
|
execute(request: Request): Promise<Response>;
|
|
47
109
|
}
|
|
48
110
|
|
|
49
|
-
interface IErrorNotifier {
|
|
50
|
-
notify(error: Error, context: ContextError): Promise<void>;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
declare class GlobalErrorHandler {
|
|
54
|
-
readonly env: Record<string, any>;
|
|
55
|
-
protected readonly errorNotifier: IErrorNotifier;
|
|
56
|
-
constructor(env: Record<string, any>);
|
|
57
|
-
register(): void;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
111
|
type ZodSchema = z.ZodObject<{
|
|
61
112
|
headers: z.ZodObject<Record<string, any>>;
|
|
62
113
|
params: z.ZodObject<Record<string, any>>;
|
|
@@ -73,12 +124,12 @@ interface IHttp {
|
|
|
73
124
|
closeServer(): Promise<void>;
|
|
74
125
|
}
|
|
75
126
|
|
|
76
|
-
type Props
|
|
127
|
+
type Props = {
|
|
77
128
|
method: MethodType;
|
|
78
129
|
path: string;
|
|
79
130
|
middlewares?: MiddlewareFunction[];
|
|
80
131
|
};
|
|
81
|
-
declare function Controller({ method, path, middlewares, }: Props
|
|
132
|
+
declare function Controller({ method, path, middlewares, }: Props): ClassDecorator;
|
|
82
133
|
|
|
83
134
|
type Class<T = any> = new (...args: any[]) => T;
|
|
84
135
|
type Registration = {
|
|
@@ -230,170 +281,295 @@ type RequestHttp = {
|
|
|
230
281
|
query: Record<string, any>;
|
|
231
282
|
};
|
|
232
283
|
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
284
|
+
interface IMetricsManager {
|
|
285
|
+
recordHttpRequest(params: {
|
|
286
|
+
method: string;
|
|
287
|
+
route: string;
|
|
288
|
+
statusCode: number;
|
|
289
|
+
durationSeconds: number;
|
|
290
|
+
responseSizeBytes?: number;
|
|
291
|
+
}): void;
|
|
292
|
+
recordDbQueryError(params: {
|
|
293
|
+
operation: string;
|
|
294
|
+
repository: string;
|
|
295
|
+
errorMessage: string;
|
|
296
|
+
}): void;
|
|
297
|
+
recordDbQuery(params: {
|
|
298
|
+
operation: string;
|
|
299
|
+
repository: string;
|
|
300
|
+
durationSeconds: number;
|
|
301
|
+
}): void;
|
|
302
|
+
recordDbTransaction(params: {
|
|
303
|
+
operation: string;
|
|
304
|
+
repository: string;
|
|
305
|
+
durationSeconds: number;
|
|
306
|
+
}): void;
|
|
307
|
+
recordDbDeadlock(params: {
|
|
308
|
+
operation: string;
|
|
309
|
+
repository: string;
|
|
310
|
+
errorMessage: string;
|
|
311
|
+
}): void;
|
|
312
|
+
recordHttpRequestBytes(bytes: number, attributes: {
|
|
313
|
+
method: string;
|
|
314
|
+
route: string;
|
|
315
|
+
statusCode: number;
|
|
316
|
+
}): void;
|
|
317
|
+
recordProcessingDuration(params: {
|
|
318
|
+
operation: string;
|
|
319
|
+
durationSeconds: number;
|
|
320
|
+
}): void;
|
|
321
|
+
recordProcessingError(params: {
|
|
322
|
+
operation: string;
|
|
323
|
+
errorType: string;
|
|
324
|
+
}): void;
|
|
325
|
+
recordHttpClientRequest(params: {
|
|
326
|
+
method: string;
|
|
327
|
+
url: string;
|
|
328
|
+
statusCode?: number;
|
|
329
|
+
durationSeconds: number;
|
|
330
|
+
error?: boolean;
|
|
331
|
+
timeout?: boolean;
|
|
332
|
+
}): void;
|
|
333
|
+
recordValidationError(params: {
|
|
334
|
+
field?: string;
|
|
335
|
+
errorType: string;
|
|
336
|
+
}): void;
|
|
337
|
+
startSystemMetricsCollection(intervalMs?: number): void;
|
|
338
|
+
stopSystemMetricsCollection(): void;
|
|
339
|
+
}
|
|
340
|
+
declare class MetricsManager implements IMetricsManager {
|
|
341
|
+
private meter;
|
|
342
|
+
private httpRequestsTotal;
|
|
343
|
+
private httpRequestDuration;
|
|
344
|
+
private httpRequestsErrors;
|
|
345
|
+
private httpResponseSize;
|
|
346
|
+
private dbQueryDuration;
|
|
347
|
+
private dbQueryErrors;
|
|
348
|
+
private dbTransactionsTotal;
|
|
349
|
+
private dbTransactionDuration;
|
|
350
|
+
private dbDeadlocksTotal;
|
|
351
|
+
private httpRequestBytesTotal;
|
|
352
|
+
private processingDuration;
|
|
353
|
+
private processingErrors;
|
|
354
|
+
private httpClientRequestsTotal;
|
|
355
|
+
private httpClientRequestDuration;
|
|
356
|
+
private httpClientErrors;
|
|
357
|
+
private httpClientTimeouts;
|
|
358
|
+
private validationErrors;
|
|
359
|
+
private processCpuSecondsTotal;
|
|
360
|
+
private processMemoryBytes;
|
|
361
|
+
private nodejsHeapSizeTotalBytes;
|
|
362
|
+
private nodejsHeapSizeUsedBytes;
|
|
363
|
+
private nodejsEventloopLagSeconds;
|
|
364
|
+
private nodejsEventloopDurationSeconds;
|
|
365
|
+
private nodejsGcDurationSeconds;
|
|
366
|
+
private processOpenFds;
|
|
367
|
+
private processUptimeSeconds;
|
|
368
|
+
private eventLoopMonitor;
|
|
369
|
+
private previousCpuUsage;
|
|
370
|
+
private collectionInterval?;
|
|
371
|
+
private gcObserver?;
|
|
372
|
+
recordHttpRequest(params: {
|
|
373
|
+
method: string;
|
|
374
|
+
route: string;
|
|
375
|
+
statusCode: number;
|
|
376
|
+
durationSeconds: number;
|
|
377
|
+
responseSizeBytes?: number;
|
|
378
|
+
}): void;
|
|
379
|
+
recordDbQueryError(params: {
|
|
380
|
+
operation: string;
|
|
381
|
+
repository: string;
|
|
382
|
+
errorMessage: string;
|
|
383
|
+
}): void;
|
|
384
|
+
recordDbQuery(params: {
|
|
385
|
+
operation: string;
|
|
386
|
+
repository: string;
|
|
387
|
+
durationSeconds: number;
|
|
388
|
+
}): void;
|
|
389
|
+
private isValidDbQueryErrorParams;
|
|
390
|
+
private isValidDbQueryParams;
|
|
391
|
+
recordDbTransaction(params: {
|
|
392
|
+
operation: string;
|
|
393
|
+
repository: string;
|
|
394
|
+
durationSeconds: number;
|
|
395
|
+
}): void;
|
|
396
|
+
recordDbDeadlock(params: {
|
|
397
|
+
operation: string;
|
|
398
|
+
repository: string;
|
|
399
|
+
errorMessage: string;
|
|
400
|
+
}): void;
|
|
401
|
+
recordHttpRequestBytes(bytes: number, attributes: {
|
|
402
|
+
method: string;
|
|
403
|
+
route: string;
|
|
404
|
+
statusCode: number;
|
|
405
|
+
}): void;
|
|
406
|
+
recordProcessingDuration(params: {
|
|
407
|
+
operation: string;
|
|
408
|
+
durationSeconds: number;
|
|
409
|
+
}): void;
|
|
410
|
+
recordProcessingError(params: {
|
|
411
|
+
operation: string;
|
|
412
|
+
errorType: string;
|
|
413
|
+
}): void;
|
|
414
|
+
recordHttpClientRequest(params: {
|
|
415
|
+
method: string;
|
|
416
|
+
url: string;
|
|
417
|
+
statusCode?: number;
|
|
418
|
+
durationSeconds: number;
|
|
419
|
+
error?: boolean;
|
|
420
|
+
timeout?: boolean;
|
|
421
|
+
}): void;
|
|
422
|
+
recordValidationError(params: {
|
|
423
|
+
field?: string;
|
|
424
|
+
errorType: string;
|
|
425
|
+
}): void;
|
|
426
|
+
startSystemMetricsCollection(intervalMs?: number): void;
|
|
427
|
+
stopSystemMetricsCollection(): void;
|
|
428
|
+
private collectSystemMetrics;
|
|
429
|
+
private collectPeriodicMetrics;
|
|
430
|
+
private setupGCObserver;
|
|
431
|
+
private getGCKindName;
|
|
432
|
+
private normalizeUrl;
|
|
433
|
+
private getStatusClass;
|
|
242
434
|
}
|
|
243
435
|
|
|
244
436
|
declare class FastifyAdapter implements IHttp {
|
|
245
|
-
|
|
246
|
-
|
|
437
|
+
private logger;
|
|
438
|
+
private metrics?;
|
|
247
439
|
readonly instance: FastifyInstance;
|
|
248
|
-
constructor(
|
|
440
|
+
constructor(logger: ILogger, metrics?: IMetricsManager | undefined);
|
|
249
441
|
registerRoute(controllerClass: BaseController): void;
|
|
250
442
|
startServer(port: number): Promise<void>;
|
|
251
443
|
closeServer(): Promise<void>;
|
|
444
|
+
private getNormalizedRoute;
|
|
252
445
|
}
|
|
253
446
|
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
447
|
+
declare const context: AsyncLocalStorage<unknown>;
|
|
448
|
+
type Context = {
|
|
449
|
+
traceId: string;
|
|
257
450
|
};
|
|
258
|
-
declare
|
|
259
|
-
private readonly options;
|
|
260
|
-
private webhook;
|
|
261
|
-
constructor(options: DiscordOptions);
|
|
262
|
-
notify(error: Error, context: ContextError): Promise<void>;
|
|
263
|
-
}
|
|
451
|
+
declare function getContext(): Context;
|
|
264
452
|
|
|
265
|
-
declare class
|
|
266
|
-
|
|
267
|
-
|
|
453
|
+
declare class OtelManager {
|
|
454
|
+
private readonly env;
|
|
455
|
+
private readonly resource;
|
|
456
|
+
private readonly loggerProvider;
|
|
457
|
+
private readonly sdk;
|
|
458
|
+
private readonly otlpLogExporter;
|
|
459
|
+
private readonly traceExporter;
|
|
460
|
+
private readonly metricExporter;
|
|
461
|
+
private readonly metricReader;
|
|
462
|
+
private readonly sampler;
|
|
463
|
+
constructor(env: Record<string, any>);
|
|
464
|
+
private createResource;
|
|
465
|
+
private createOtlpLogExporter;
|
|
466
|
+
private createLoggerProvider;
|
|
467
|
+
private configureLogProcessors;
|
|
468
|
+
private createTraceExporter;
|
|
469
|
+
private createSampler;
|
|
470
|
+
private createMetricExporter;
|
|
471
|
+
private createMetricReader;
|
|
472
|
+
private createSdk;
|
|
473
|
+
initialize(): void;
|
|
474
|
+
shutdown(): Promise<void>;
|
|
475
|
+
getLoggerProvider(): LoggerProvider;
|
|
476
|
+
getSdk(): NodeSDK;
|
|
268
477
|
}
|
|
269
478
|
|
|
270
|
-
declare
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
OTEL_SERVICE_NAME: z.ZodOptional<z.ZodString>;
|
|
280
|
-
OTEL_SERVICE_VERSION: z.ZodOptional<z.ZodString>;
|
|
281
|
-
OTEL_OTLP_TRACES_EXPORTER_URL: z.ZodOptional<z.ZodString>;
|
|
282
|
-
OTEL_OTLP_LOGS_EXPORTER_URL: z.ZodOptional<z.ZodString>;
|
|
283
|
-
OTEL_OTLP_METRICS_EXPORTER_URL: z.ZodOptional<z.ZodString>;
|
|
284
|
-
}, "strip", z.ZodTypeAny, {
|
|
285
|
-
ENVIRONMENT: "test" | "development" | "production" | "staging";
|
|
286
|
-
SHOULD_NOTIFY_ERROR: boolean;
|
|
287
|
-
NODE_ENV: "test" | "development" | "production";
|
|
288
|
-
PORT: number;
|
|
289
|
-
LOG_LEVEL: "error" | "fatal" | "warn" | "info" | "debug";
|
|
290
|
-
OTEL_ENABLE: boolean;
|
|
291
|
-
SENTRY_DSN?: string | undefined;
|
|
292
|
-
DISCORD_WEBHOOK_URL?: string | undefined;
|
|
293
|
-
OTEL_SERVICE_NAME?: string | undefined;
|
|
294
|
-
OTEL_SERVICE_VERSION?: string | undefined;
|
|
295
|
-
OTEL_OTLP_TRACES_EXPORTER_URL?: string | undefined;
|
|
296
|
-
OTEL_OTLP_LOGS_EXPORTER_URL?: string | undefined;
|
|
297
|
-
OTEL_OTLP_METRICS_EXPORTER_URL?: string | undefined;
|
|
298
|
-
}, {
|
|
299
|
-
ENVIRONMENT?: "test" | "development" | "production" | "staging" | undefined;
|
|
300
|
-
SHOULD_NOTIFY_ERROR?: boolean | undefined;
|
|
301
|
-
NODE_ENV?: "test" | "development" | "production" | undefined;
|
|
302
|
-
PORT?: number | undefined;
|
|
303
|
-
SENTRY_DSN?: string | undefined;
|
|
304
|
-
DISCORD_WEBHOOK_URL?: string | undefined;
|
|
305
|
-
LOG_LEVEL?: "error" | "fatal" | "warn" | "info" | "debug" | undefined;
|
|
306
|
-
OTEL_ENABLE?: boolean | undefined;
|
|
307
|
-
OTEL_SERVICE_NAME?: string | undefined;
|
|
308
|
-
OTEL_SERVICE_VERSION?: string | undefined;
|
|
309
|
-
OTEL_OTLP_TRACES_EXPORTER_URL?: string | undefined;
|
|
310
|
-
OTEL_OTLP_LOGS_EXPORTER_URL?: string | undefined;
|
|
311
|
-
OTEL_OTLP_METRICS_EXPORTER_URL?: string | undefined;
|
|
312
|
-
}>;
|
|
313
|
-
|
|
314
|
-
type OptionsNotifications = 'console' | 'discord' | 'sentry';
|
|
315
|
-
type EnvironmentEnum = z.infer<typeof baseEnvSchema>['ENVIRONMENT'];
|
|
316
|
-
type Props = {
|
|
317
|
-
test?: OptionsNotifications;
|
|
318
|
-
development?: OptionsNotifications;
|
|
319
|
-
staging?: OptionsNotifications;
|
|
320
|
-
production?: OptionsNotifications;
|
|
321
|
-
};
|
|
322
|
-
declare class NotificationFactory {
|
|
323
|
-
static define(env: EnvironmentEnum, definitions?: Props): any;
|
|
324
|
-
private static defineProvider;
|
|
479
|
+
declare class NullSpan {
|
|
480
|
+
setAttributes(): void;
|
|
481
|
+
setAttribute(): void;
|
|
482
|
+
setStatus(): void;
|
|
483
|
+
recordException(): void;
|
|
484
|
+
}
|
|
485
|
+
declare class SpanManager {
|
|
486
|
+
static getActiveSpan(): Span | NullSpan;
|
|
487
|
+
static isEnabled(): boolean;
|
|
325
488
|
}
|
|
326
489
|
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
490
|
+
declare const TRACER_NAME: string;
|
|
491
|
+
declare const TRACER_VERSION: string;
|
|
492
|
+
declare const OTEL_ENABLED: boolean;
|
|
493
|
+
type Timer = {
|
|
494
|
+
getDurationSeconds(): number;
|
|
330
495
|
};
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
496
|
+
type BaseExecutionContext = {
|
|
497
|
+
operation: string;
|
|
498
|
+
logger?: any;
|
|
499
|
+
};
|
|
500
|
+
interface IMetricsRecorder {
|
|
501
|
+
recordSuccess(context: BaseExecutionContext, durationSeconds: number): void;
|
|
502
|
+
recordError(context: BaseExecutionContext, error: Error): void;
|
|
335
503
|
}
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
fatal(data: any): void;
|
|
342
|
-
warn(data: any): void;
|
|
504
|
+
interface ISpanBuilder {
|
|
505
|
+
createSpan(tracer: ReturnType<typeof trace.getTracer>, context: BaseExecutionContext): Span | undefined;
|
|
506
|
+
buildSpanName(context: BaseExecutionContext): string;
|
|
507
|
+
finalizeSpanSuccess(span: Span, durationSeconds: number): void;
|
|
508
|
+
finalizeSpanError(span: Span, durationSeconds: number, error: Error): void;
|
|
343
509
|
}
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
private bodyIsFastifyRequest;
|
|
352
|
-
private bodyIsFastifyReply;
|
|
353
|
-
private buildMessage;
|
|
354
|
-
private logMessage;
|
|
355
|
-
info(body: string | {
|
|
356
|
-
req?: FastifyRequest;
|
|
357
|
-
res?: FastifyReply;
|
|
358
|
-
}): void;
|
|
359
|
-
error(body: string | {
|
|
360
|
-
req?: FastifyRequest;
|
|
361
|
-
res?: FastifyReply;
|
|
362
|
-
}): void;
|
|
363
|
-
debug(body: string | {
|
|
364
|
-
req?: FastifyRequest;
|
|
365
|
-
res?: FastifyReply;
|
|
366
|
-
}): void;
|
|
367
|
-
fatal(body: string | {
|
|
368
|
-
req?: FastifyRequest;
|
|
369
|
-
res?: FastifyReply;
|
|
370
|
-
}): void;
|
|
371
|
-
warn(body: string | {
|
|
372
|
-
req?: FastifyRequest;
|
|
373
|
-
res?: FastifyReply;
|
|
374
|
-
}): void;
|
|
375
|
-
trace(message: string): void;
|
|
376
|
-
child(): WinstonOtelFastify;
|
|
510
|
+
interface ILogBuilder {
|
|
511
|
+
buildStartMessage(context: BaseExecutionContext): string;
|
|
512
|
+
buildStartLogData(context: BaseExecutionContext, args: any[]): Record<string, any>;
|
|
513
|
+
buildSuccessMessage(context: BaseExecutionContext): string;
|
|
514
|
+
buildSuccessLogData(context: BaseExecutionContext, durationMs: number): Record<string, any>;
|
|
515
|
+
buildErrorMessage(context: BaseExecutionContext): string;
|
|
516
|
+
buildErrorLogData(context: BaseExecutionContext, durationMs: number, error: Error): Record<string, any>;
|
|
377
517
|
}
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
private readonly env;
|
|
381
|
-
sdk: NodeSDK;
|
|
382
|
-
constructor(env: Record<string, any>);
|
|
383
|
-
startSdk(): void;
|
|
384
|
-
shutdown(): Promise<void>;
|
|
518
|
+
interface IInstrumentationStrategy {
|
|
519
|
+
instrumentMethod(originalMethod: (...args: any[]) => any, instance: any, context: BaseExecutionContext): (...args: any[]) => any;
|
|
385
520
|
}
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
interface ITracerGateway {
|
|
390
|
-
addEvent(name: string, attributes?: Record<string, any>): void;
|
|
391
|
-
setAttribute(key: string, value: string | number | boolean): void;
|
|
521
|
+
declare class Tracer {
|
|
522
|
+
private static instance;
|
|
523
|
+
static getTracer(): ReturnType<typeof trace.getTracer>;
|
|
392
524
|
}
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
525
|
+
declare class Metrics {
|
|
526
|
+
private static instance;
|
|
527
|
+
static getMetrics(): IMetricsManager;
|
|
528
|
+
}
|
|
529
|
+
declare abstract class BaseFullInstrumentationStrategy implements IInstrumentationStrategy {
|
|
530
|
+
protected readonly tracer: ReturnType<typeof trace.getTracer>;
|
|
531
|
+
protected readonly metrics: IMetricsManager;
|
|
532
|
+
protected readonly metricsRecorder: IMetricsRecorder;
|
|
533
|
+
protected readonly spanBuilder: ISpanBuilder;
|
|
534
|
+
protected readonly logBuilder: ILogBuilder;
|
|
535
|
+
constructor(tracer: ReturnType<typeof trace.getTracer>, metrics: IMetricsManager, metricsRecorder: IMetricsRecorder, spanBuilder: ISpanBuilder, logBuilder: ILogBuilder);
|
|
536
|
+
instrumentMethod(originalMethod: (...args: any[]) => any, instance: any, context: BaseExecutionContext): (...args: any[]) => any;
|
|
537
|
+
private recordSuccess;
|
|
538
|
+
private logSuccess;
|
|
539
|
+
private recordFailure;
|
|
540
|
+
private logError;
|
|
541
|
+
private logOperationStart;
|
|
397
542
|
}
|
|
543
|
+
declare abstract class BaseLogsOnlyInstrumentationStrategy implements IInstrumentationStrategy {
|
|
544
|
+
protected readonly logBuilder: ILogBuilder;
|
|
545
|
+
constructor(logBuilder: ILogBuilder);
|
|
546
|
+
instrumentMethod(originalMethod: (...args: any[]) => any, instance: any, context: BaseExecutionContext): (...args: any[]) => any;
|
|
547
|
+
private logOperationStart;
|
|
548
|
+
private logSuccess;
|
|
549
|
+
private logError;
|
|
550
|
+
}
|
|
551
|
+
declare function createTimer(): Timer;
|
|
552
|
+
declare function normalizeError(error: unknown): Error;
|
|
553
|
+
declare function roundDuration(durationMs: number): number;
|
|
554
|
+
declare function sanitizeArgs(args: any[]): any[];
|
|
555
|
+
declare function resolveLogger(): any;
|
|
556
|
+
declare function copyReflectMetadata(source: any, target: any): void;
|
|
557
|
+
declare function preserveClassName(target: any, className: string): void;
|
|
558
|
+
declare function getInstrumentableMethods(instance: object): string[];
|
|
559
|
+
declare function instrumentInstanceMethods(instance: object, contextName: string, logger: any, strategy: IInstrumentationStrategy, createContext: (operation: string, logger?: any) => BaseExecutionContext): void;
|
|
560
|
+
|
|
561
|
+
type InstrumentationOptions = {
|
|
562
|
+
serviceName?: string;
|
|
563
|
+
};
|
|
564
|
+
declare function Instrumentation(options?: InstrumentationOptions): <T extends {
|
|
565
|
+
new (...args: any[]): object;
|
|
566
|
+
}>(constructor: T) => T;
|
|
567
|
+
|
|
568
|
+
type RepositoryOtelOptions = {
|
|
569
|
+
dbSystem?: string;
|
|
570
|
+
};
|
|
571
|
+
declare function RepositoryInstrumentation(options?: RepositoryOtelOptions): <T extends {
|
|
572
|
+
new (...args: any[]): object;
|
|
573
|
+
}>(constructor: T) => T;
|
|
398
574
|
|
|
399
|
-
export { AggregateObjectRoot, AggregateRoot, BaseController, CommonDTO, ContextError, Controller, CreateCommonDTO, DependencyContainer,
|
|
575
|
+
export { AggregateObjectRoot, AggregateRoot, BaseController, BaseExecutionContext, BaseFullInstrumentationStrategy, BaseLogsOnlyInstrumentationStrategy, CommonDTO, ContextError, Controller, CreateCommonDTO, DependencyContainer, DtoResponsePagination, Entity, EntityObject, FastifyAdapter, GlobalListener, IHealthCheckDB, IHttp, IInstrumentationStrategy, ILogBuilder, ILogger, IMetricsManager, IMetricsRecorder, ISpanBuilder, Inject, Instrumentation, LogParams, Logger, MethodType, Metrics, MetricsManager, MiddlewareFunction, NotPagination, NullSpan, OTEL_ENABLED, Optional, OtelManager, Pagination, Replace, RepositoryInstrumentation, Request, RequestHttp, Response, SpanManager, TRACER_NAME, TRACER_VERSION, Timer, Tracer, UniqueEntityId, UniqueObjectId, ValueObject, WatchedList, ZodSchema, baseEnvSchema, context, copyReflectMetadata, createTimer, getContext, getInstrumentableMethods, getTakeAndSkip, instrumentInstanceMethods, normalizeError, preserveClassName, resolveLogger, roundDuration, sanitizeArgs, zodValidator };
|