@bymax-one/nest-logger 1.4.23 → 1.4.25
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/CHANGELOG.md +220 -1
- package/README.md +158 -58
- package/dist/observability/index.cjs +112 -0
- package/dist/observability/index.d.cts +55 -0
- package/dist/observability/index.d.ts +55 -0
- package/dist/observability/index.mjs +110 -0
- package/dist/server/index.cjs +416 -149
- package/dist/server/index.d.cts +82 -4
- package/dist/server/index.d.ts +82 -4
- package/dist/server/index.mjs +416 -150
- package/dist/shared/index.cjs +1 -0
- package/dist/shared/index.d.cts +1 -0
- package/dist/shared/index.d.ts +1 -0
- package/dist/shared/index.mjs +1 -0
- package/package.json +24 -1
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { IMetricsContributor, MetricsRegistry } from '@bymax-one/nest-core/metrics';
|
|
2
|
+
import { ILoggerObservability } from '@bymax-one/nest-logger';
|
|
3
|
+
import { IHealthIndicator, HealthIndicatorResult } from '@bymax-one/nest-core/health';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Provides {@link LoggerMetricsContributor} and {@link LoggerHealthIndicator}, which
|
|
7
|
+
* `@bymax-one/nest-core` finds by their markers. With `isGlobal: false` on `BymaxLoggerModule`,
|
|
8
|
+
* do not import this module: list both providers in a module of yours that imports the logger module.
|
|
9
|
+
*/
|
|
10
|
+
declare class BymaxLoggerObservabilityModule {
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Registers `bymax_logger_entries_truncated_total{reason}` and
|
|
15
|
+
* `bymax_logger_destination_errors_total` on the registry it is given.
|
|
16
|
+
*/
|
|
17
|
+
declare class LoggerMetricsContributor implements IMetricsContributor {
|
|
18
|
+
private readonly observability;
|
|
19
|
+
/**
|
|
20
|
+
* @param observability - The counts of the logger, provided by `BymaxLoggerModule`.
|
|
21
|
+
*/
|
|
22
|
+
constructor(observability: ILoggerObservability);
|
|
23
|
+
/**
|
|
24
|
+
* Create the two counters on `registry`. Each `reason` series exists from the first scrape, at
|
|
25
|
+
* zero, so a rate over it never starts from a missing series.
|
|
26
|
+
*
|
|
27
|
+
* @param registry - The registry the scrape endpoint serves.
|
|
28
|
+
*/
|
|
29
|
+
registerMetrics(registry: MetricsRegistry): void;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** The name of the indicator in the readiness response. */
|
|
33
|
+
declare const LOGGER_HEALTH_INDICATOR_NAME = "logger";
|
|
34
|
+
/**
|
|
35
|
+
* `up` when at least one log destination finished its `onInit` healthy, so an entry can still be
|
|
36
|
+
* delivered; `down` when none did, which is also the state before the first has finished. The
|
|
37
|
+
* details carry counts only: how many destinations finished their init, how many failed it and how
|
|
38
|
+
* many have refused a write or had an entry dropped.
|
|
39
|
+
*/
|
|
40
|
+
declare class LoggerHealthIndicator implements IHealthIndicator {
|
|
41
|
+
private readonly observability;
|
|
42
|
+
readonly name = "logger";
|
|
43
|
+
/**
|
|
44
|
+
* @param observability - The delivery state of the logger, provided by `BymaxLoggerModule`.
|
|
45
|
+
*/
|
|
46
|
+
constructor(observability: ILoggerObservability);
|
|
47
|
+
/**
|
|
48
|
+
* Read the delivery state of the logger.
|
|
49
|
+
*
|
|
50
|
+
* @returns `up` or `down`, with the counts of the state as details.
|
|
51
|
+
*/
|
|
52
|
+
check(): Promise<HealthIndicatorResult>;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export { BymaxLoggerObservabilityModule, LOGGER_HEALTH_INDICATOR_NAME, LoggerHealthIndicator, LoggerMetricsContributor };
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { IMetricsContributor, MetricsRegistry } from '@bymax-one/nest-core/metrics';
|
|
2
|
+
import { ILoggerObservability } from '@bymax-one/nest-logger';
|
|
3
|
+
import { IHealthIndicator, HealthIndicatorResult } from '@bymax-one/nest-core/health';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Provides {@link LoggerMetricsContributor} and {@link LoggerHealthIndicator}, which
|
|
7
|
+
* `@bymax-one/nest-core` finds by their markers. With `isGlobal: false` on `BymaxLoggerModule`,
|
|
8
|
+
* do not import this module: list both providers in a module of yours that imports the logger module.
|
|
9
|
+
*/
|
|
10
|
+
declare class BymaxLoggerObservabilityModule {
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Registers `bymax_logger_entries_truncated_total{reason}` and
|
|
15
|
+
* `bymax_logger_destination_errors_total` on the registry it is given.
|
|
16
|
+
*/
|
|
17
|
+
declare class LoggerMetricsContributor implements IMetricsContributor {
|
|
18
|
+
private readonly observability;
|
|
19
|
+
/**
|
|
20
|
+
* @param observability - The counts of the logger, provided by `BymaxLoggerModule`.
|
|
21
|
+
*/
|
|
22
|
+
constructor(observability: ILoggerObservability);
|
|
23
|
+
/**
|
|
24
|
+
* Create the two counters on `registry`. Each `reason` series exists from the first scrape, at
|
|
25
|
+
* zero, so a rate over it never starts from a missing series.
|
|
26
|
+
*
|
|
27
|
+
* @param registry - The registry the scrape endpoint serves.
|
|
28
|
+
*/
|
|
29
|
+
registerMetrics(registry: MetricsRegistry): void;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** The name of the indicator in the readiness response. */
|
|
33
|
+
declare const LOGGER_HEALTH_INDICATOR_NAME = "logger";
|
|
34
|
+
/**
|
|
35
|
+
* `up` when at least one log destination finished its `onInit` healthy, so an entry can still be
|
|
36
|
+
* delivered; `down` when none did, which is also the state before the first has finished. The
|
|
37
|
+
* details carry counts only: how many destinations finished their init, how many failed it and how
|
|
38
|
+
* many have refused a write or had an entry dropped.
|
|
39
|
+
*/
|
|
40
|
+
declare class LoggerHealthIndicator implements IHealthIndicator {
|
|
41
|
+
private readonly observability;
|
|
42
|
+
readonly name = "logger";
|
|
43
|
+
/**
|
|
44
|
+
* @param observability - The delivery state of the logger, provided by `BymaxLoggerModule`.
|
|
45
|
+
*/
|
|
46
|
+
constructor(observability: ILoggerObservability);
|
|
47
|
+
/**
|
|
48
|
+
* Read the delivery state of the logger.
|
|
49
|
+
*
|
|
50
|
+
* @returns `up` or `down`, with the counts of the state as details.
|
|
51
|
+
*/
|
|
52
|
+
check(): Promise<HealthIndicatorResult>;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export { BymaxLoggerObservabilityModule, LOGGER_HEALTH_INDICATOR_NAME, LoggerHealthIndicator, LoggerMetricsContributor };
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { Injectable, Inject, Module } from '@nestjs/common';
|
|
2
|
+
import { BymaxHealthIndicator } from '@bymax-one/nest-core/health';
|
|
3
|
+
import { LOGGER_OBSERVABILITY_TOKEN } from '@bymax-one/nest-logger';
|
|
4
|
+
import { BymaxMetricsContributor } from '@bymax-one/nest-core/metrics';
|
|
5
|
+
import { Counter } from 'prom-client';
|
|
6
|
+
|
|
7
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
8
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
9
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
10
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
11
|
+
if (decorator = decorators[i])
|
|
12
|
+
result = (decorator(result)) || result;
|
|
13
|
+
return result;
|
|
14
|
+
};
|
|
15
|
+
var __decorateParam = (index, decorator) => (target, key) => decorator(target, key, index);
|
|
16
|
+
var LOGGER_HEALTH_INDICATOR_NAME = "logger";
|
|
17
|
+
var LoggerHealthIndicator = class {
|
|
18
|
+
/**
|
|
19
|
+
* @param observability - The delivery state of the logger, provided by `BymaxLoggerModule`.
|
|
20
|
+
*/
|
|
21
|
+
constructor(observability) {
|
|
22
|
+
this.observability = observability;
|
|
23
|
+
this.name = LOGGER_HEALTH_INDICATOR_NAME;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Read the delivery state of the logger.
|
|
27
|
+
*
|
|
28
|
+
* @returns `up` or `down`, with the counts of the state as details.
|
|
29
|
+
*/
|
|
30
|
+
check() {
|
|
31
|
+
const { destinations, failedInit, writeFailing, hasHealthySink } = this.observability.deliveryState();
|
|
32
|
+
return Promise.resolve({
|
|
33
|
+
status: hasHealthySink ? "up" : "down",
|
|
34
|
+
details: { destinations, failedInit, writeFailing }
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
LoggerHealthIndicator = __decorateClass([
|
|
39
|
+
BymaxHealthIndicator(),
|
|
40
|
+
Injectable(),
|
|
41
|
+
__decorateParam(0, Inject(LOGGER_OBSERVABILITY_TOKEN))
|
|
42
|
+
], LoggerHealthIndicator);
|
|
43
|
+
var TRUNCATION_REASONS = ["max_entry_size", "max_string_length"];
|
|
44
|
+
function growthOf(read) {
|
|
45
|
+
let last = 0;
|
|
46
|
+
return () => {
|
|
47
|
+
const total = read();
|
|
48
|
+
const growth = total - last;
|
|
49
|
+
last = total;
|
|
50
|
+
return growth;
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
var LoggerMetricsContributor = class {
|
|
54
|
+
/**
|
|
55
|
+
* @param observability - The counts of the logger, provided by `BymaxLoggerModule`.
|
|
56
|
+
*/
|
|
57
|
+
constructor(observability) {
|
|
58
|
+
this.observability = observability;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Create the two counters on `registry`. Each `reason` series exists from the first scrape, at
|
|
62
|
+
* zero, so a rate over it never starts from a missing series.
|
|
63
|
+
*
|
|
64
|
+
* @param registry - The registry the scrape endpoint serves.
|
|
65
|
+
*/
|
|
66
|
+
registerMetrics(registry) {
|
|
67
|
+
const observability = this.observability;
|
|
68
|
+
const growth = new Map(
|
|
69
|
+
TRUNCATION_REASONS.map((reason) => [
|
|
70
|
+
reason,
|
|
71
|
+
growthOf(() => observability.truncatedTotal(reason))
|
|
72
|
+
])
|
|
73
|
+
);
|
|
74
|
+
new Counter({
|
|
75
|
+
name: "bymax_logger_entries_truncated_total",
|
|
76
|
+
help: "Fields of a log entry cut or replaced for a size bound, by reason.",
|
|
77
|
+
labelNames: ["reason"],
|
|
78
|
+
registers: [registry],
|
|
79
|
+
collect() {
|
|
80
|
+
for (const [reason, next] of growth) this.labels(reason).inc(next());
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
const errors = growthOf(() => observability.destinationErrorTotal());
|
|
84
|
+
new Counter({
|
|
85
|
+
name: "bymax_logger_destination_errors_total",
|
|
86
|
+
help: "Writes to a log destination that threw or rejected.",
|
|
87
|
+
registers: [registry],
|
|
88
|
+
collect() {
|
|
89
|
+
this.inc(errors());
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
LoggerMetricsContributor = __decorateClass([
|
|
95
|
+
BymaxMetricsContributor(),
|
|
96
|
+
Injectable(),
|
|
97
|
+
__decorateParam(0, Inject(LOGGER_OBSERVABILITY_TOKEN))
|
|
98
|
+
], LoggerMetricsContributor);
|
|
99
|
+
|
|
100
|
+
// src/observability/observability.module.ts
|
|
101
|
+
var BymaxLoggerObservabilityModule = class {
|
|
102
|
+
};
|
|
103
|
+
BymaxLoggerObservabilityModule = __decorateClass([
|
|
104
|
+
Module({
|
|
105
|
+
providers: [LoggerMetricsContributor, LoggerHealthIndicator],
|
|
106
|
+
exports: [LoggerMetricsContributor, LoggerHealthIndicator]
|
|
107
|
+
})
|
|
108
|
+
], BymaxLoggerObservabilityModule);
|
|
109
|
+
|
|
110
|
+
export { BymaxLoggerObservabilityModule, LOGGER_HEALTH_INDICATOR_NAME, LoggerHealthIndicator, LoggerMetricsContributor };
|