@promster/fastify 7.0.5 → 7.0.7
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.
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
1
|
import type { TPromsterOptions } from '@promster/types';
|
|
3
2
|
import type { TRequestRecorder } from '@promster/metrics';
|
|
4
|
-
import { FastifyRequest } from 'fastify';
|
|
3
|
+
import type { FastifyRequest } from 'fastify';
|
|
5
4
|
declare const extractPath: (req: FastifyRequest) => string;
|
|
6
5
|
declare const getRequestRecorder: () => TRequestRecorder;
|
|
7
6
|
declare const signalIsUp: () => void;
|
|
8
7
|
declare const signalIsNotUp: () => void;
|
|
9
|
-
declare const plugin: import("fastify").FastifyPluginAsync<TPromsterOptions, import("
|
|
8
|
+
declare const plugin: import("fastify").FastifyPluginAsync<TPromsterOptions, import("fastify").RawServerDefault, import("fastify").FastifyTypeProviderDefault>;
|
|
10
9
|
export { plugin, getRequestRecorder, signalIsUp, signalIsNotUp, extractPath };
|
|
@@ -13,7 +13,7 @@ var merge__default = /*#__PURE__*/_interopDefault(merge);
|
|
|
13
13
|
|
|
14
14
|
var pkg = {
|
|
15
15
|
name: "@promster/fastify",
|
|
16
|
-
version: "7.0.
|
|
16
|
+
version: "7.0.7",
|
|
17
17
|
description: "Fastify server integrations of promster",
|
|
18
18
|
main: "dist/promster-fastify.cjs.js",
|
|
19
19
|
typings: "dist/promster-fastify.cjs.d.ts",
|
|
@@ -49,44 +49,38 @@ var pkg = {
|
|
|
49
49
|
"prometheus"
|
|
50
50
|
],
|
|
51
51
|
dependencies: {
|
|
52
|
-
"@promster/metrics": "^9.1.
|
|
53
|
-
"fastify-plugin": "^
|
|
52
|
+
"@promster/metrics": "^9.1.6",
|
|
53
|
+
"fastify-plugin": "^4.4.0",
|
|
54
54
|
"merge-options": "3.0.4",
|
|
55
55
|
"parse-prometheus-text-format": "1.1.1"
|
|
56
56
|
},
|
|
57
57
|
devDependencies: {
|
|
58
|
-
fastify: "
|
|
58
|
+
fastify: "4.10.2"
|
|
59
59
|
}
|
|
60
60
|
};
|
|
61
61
|
|
|
62
62
|
let recordRequest;
|
|
63
63
|
let upMetric;
|
|
64
|
-
|
|
65
|
-
|
|
64
|
+
const extractPath = req =>
|
|
65
|
+
// @ts-expect-error
|
|
66
66
|
req.raw.originalUrl || req.raw.url;
|
|
67
|
-
|
|
68
67
|
const getRequestRecorder = () => recordRequest;
|
|
69
|
-
|
|
70
68
|
const signalIsUp = () => {
|
|
71
69
|
if (!upMetric) {
|
|
72
70
|
return;
|
|
73
71
|
}
|
|
74
|
-
|
|
75
72
|
upMetric.forEach(upMetricType => {
|
|
76
73
|
upMetricType.set(1);
|
|
77
74
|
});
|
|
78
75
|
};
|
|
79
|
-
|
|
80
76
|
const signalIsNotUp = () => {
|
|
81
77
|
if (!upMetric) {
|
|
82
78
|
return;
|
|
83
79
|
}
|
|
84
|
-
|
|
85
80
|
upMetric.forEach(upMetricType => {
|
|
86
81
|
upMetricType.set(0);
|
|
87
82
|
});
|
|
88
83
|
};
|
|
89
|
-
|
|
90
84
|
const createPlugin = async (fastify, options) => {
|
|
91
85
|
const allDefaultedOptions = merge__default["default"](metrics.createHttpMetrics.defaultOptions, metrics.createGcMetrics.defaultOptions, metrics.createRequestRecorder.defaultOptions, metrics.createGcObserver.defaultOptions, metrics.defaultNormalizers, options);
|
|
92
86
|
const shouldSkipMetricsByEnvironment = metrics.skipMetricsInEnvironment(allDefaultedOptions);
|
|
@@ -95,14 +89,12 @@ const createPlugin = async (fastify, options) => {
|
|
|
95
89
|
const observeGc = metrics.createGcObserver(gcMetrics, allDefaultedOptions);
|
|
96
90
|
recordRequest = metrics.createRequestRecorder(httpMetrics, allDefaultedOptions);
|
|
97
91
|
upMetric = gcMetrics === null || gcMetrics === void 0 ? void 0 : gcMetrics.up;
|
|
98
|
-
|
|
99
92
|
if (!shouldSkipMetricsByEnvironment) {
|
|
100
93
|
observeGc();
|
|
101
94
|
}
|
|
102
|
-
|
|
103
95
|
fastify.decorate('Prometheus', metrics.Prometheus);
|
|
104
|
-
fastify.decorate('recordRequest', recordRequest);
|
|
105
|
-
|
|
96
|
+
fastify.decorate('recordRequest', recordRequest);
|
|
97
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
106
98
|
fastify.decorateRequest('__promsterTiming__', null);
|
|
107
99
|
fastify.addHook('onRequest', async (request, _) => {
|
|
108
100
|
// @ts-expect-error
|
|
@@ -110,7 +102,6 @@ const createPlugin = async (fastify, options) => {
|
|
|
110
102
|
});
|
|
111
103
|
fastify.addHook('onResponse', async (request, reply) => {
|
|
112
104
|
var _request$raw$method, _allDefaultedOptions$, _request$headers$cont, _reply$getHeader, _allDefaultedOptions$2;
|
|
113
|
-
|
|
114
105
|
const labels = Object.assign({}, {
|
|
115
106
|
method: allDefaultedOptions.normalizeMethod((_request$raw$method = request.raw.method) !== null && _request$raw$method !== void 0 ? _request$raw$method : '', {
|
|
116
107
|
req: request,
|
|
@@ -128,7 +119,6 @@ const createPlugin = async (fastify, options) => {
|
|
|
128
119
|
const requestContentLength = Number((_request$headers$cont = request.headers['content-length']) !== null && _request$headers$cont !== void 0 ? _request$headers$cont : 0);
|
|
129
120
|
const responseContentLength = Number((_reply$getHeader = reply.getHeader('content-length')) !== null && _reply$getHeader !== void 0 ? _reply$getHeader : 0);
|
|
130
121
|
const shouldSkipByRequest = (_allDefaultedOptions$2 = allDefaultedOptions.skip) === null || _allDefaultedOptions$2 === void 0 ? void 0 : _allDefaultedOptions$2.call(allDefaultedOptions, request, reply, labels);
|
|
131
|
-
|
|
132
122
|
if (!shouldSkipByRequest && !shouldSkipMetricsByEnvironment) {
|
|
133
123
|
// @ts-expect-error
|
|
134
124
|
recordRequest(request.__promsterTiming__, {
|
|
@@ -139,7 +129,6 @@ const createPlugin = async (fastify, options) => {
|
|
|
139
129
|
}
|
|
140
130
|
});
|
|
141
131
|
};
|
|
142
|
-
|
|
143
132
|
const plugin = fastifyPlugin__default["default"](createPlugin, {
|
|
144
133
|
fastify: '>= 1.6.0',
|
|
145
134
|
name: pkg.name
|
|
@@ -13,7 +13,7 @@ var merge__default = /*#__PURE__*/_interopDefault(merge);
|
|
|
13
13
|
|
|
14
14
|
var pkg = {
|
|
15
15
|
name: "@promster/fastify",
|
|
16
|
-
version: "7.0.
|
|
16
|
+
version: "7.0.7",
|
|
17
17
|
description: "Fastify server integrations of promster",
|
|
18
18
|
main: "dist/promster-fastify.cjs.js",
|
|
19
19
|
typings: "dist/promster-fastify.cjs.d.ts",
|
|
@@ -49,44 +49,38 @@ var pkg = {
|
|
|
49
49
|
"prometheus"
|
|
50
50
|
],
|
|
51
51
|
dependencies: {
|
|
52
|
-
"@promster/metrics": "^9.1.
|
|
53
|
-
"fastify-plugin": "^
|
|
52
|
+
"@promster/metrics": "^9.1.6",
|
|
53
|
+
"fastify-plugin": "^4.4.0",
|
|
54
54
|
"merge-options": "3.0.4",
|
|
55
55
|
"parse-prometheus-text-format": "1.1.1"
|
|
56
56
|
},
|
|
57
57
|
devDependencies: {
|
|
58
|
-
fastify: "
|
|
58
|
+
fastify: "4.10.2"
|
|
59
59
|
}
|
|
60
60
|
};
|
|
61
61
|
|
|
62
62
|
let recordRequest;
|
|
63
63
|
let upMetric;
|
|
64
|
-
|
|
65
|
-
|
|
64
|
+
const extractPath = req =>
|
|
65
|
+
// @ts-expect-error
|
|
66
66
|
req.raw.originalUrl || req.raw.url;
|
|
67
|
-
|
|
68
67
|
const getRequestRecorder = () => recordRequest;
|
|
69
|
-
|
|
70
68
|
const signalIsUp = () => {
|
|
71
69
|
if (!upMetric) {
|
|
72
70
|
return;
|
|
73
71
|
}
|
|
74
|
-
|
|
75
72
|
upMetric.forEach(upMetricType => {
|
|
76
73
|
upMetricType.set(1);
|
|
77
74
|
});
|
|
78
75
|
};
|
|
79
|
-
|
|
80
76
|
const signalIsNotUp = () => {
|
|
81
77
|
if (!upMetric) {
|
|
82
78
|
return;
|
|
83
79
|
}
|
|
84
|
-
|
|
85
80
|
upMetric.forEach(upMetricType => {
|
|
86
81
|
upMetricType.set(0);
|
|
87
82
|
});
|
|
88
83
|
};
|
|
89
|
-
|
|
90
84
|
const createPlugin = async (fastify, options) => {
|
|
91
85
|
const allDefaultedOptions = merge__default["default"](metrics.createHttpMetrics.defaultOptions, metrics.createGcMetrics.defaultOptions, metrics.createRequestRecorder.defaultOptions, metrics.createGcObserver.defaultOptions, metrics.defaultNormalizers, options);
|
|
92
86
|
const shouldSkipMetricsByEnvironment = metrics.skipMetricsInEnvironment(allDefaultedOptions);
|
|
@@ -95,14 +89,12 @@ const createPlugin = async (fastify, options) => {
|
|
|
95
89
|
const observeGc = metrics.createGcObserver(gcMetrics, allDefaultedOptions);
|
|
96
90
|
recordRequest = metrics.createRequestRecorder(httpMetrics, allDefaultedOptions);
|
|
97
91
|
upMetric = gcMetrics === null || gcMetrics === void 0 ? void 0 : gcMetrics.up;
|
|
98
|
-
|
|
99
92
|
if (!shouldSkipMetricsByEnvironment) {
|
|
100
93
|
observeGc();
|
|
101
94
|
}
|
|
102
|
-
|
|
103
95
|
fastify.decorate('Prometheus', metrics.Prometheus);
|
|
104
|
-
fastify.decorate('recordRequest', recordRequest);
|
|
105
|
-
|
|
96
|
+
fastify.decorate('recordRequest', recordRequest);
|
|
97
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
106
98
|
fastify.decorateRequest('__promsterTiming__', null);
|
|
107
99
|
fastify.addHook('onRequest', async (request, _) => {
|
|
108
100
|
// @ts-expect-error
|
|
@@ -110,7 +102,6 @@ const createPlugin = async (fastify, options) => {
|
|
|
110
102
|
});
|
|
111
103
|
fastify.addHook('onResponse', async (request, reply) => {
|
|
112
104
|
var _request$raw$method, _allDefaultedOptions$, _request$headers$cont, _reply$getHeader, _allDefaultedOptions$2;
|
|
113
|
-
|
|
114
105
|
const labels = Object.assign({}, {
|
|
115
106
|
method: allDefaultedOptions.normalizeMethod((_request$raw$method = request.raw.method) !== null && _request$raw$method !== void 0 ? _request$raw$method : '', {
|
|
116
107
|
req: request,
|
|
@@ -128,7 +119,6 @@ const createPlugin = async (fastify, options) => {
|
|
|
128
119
|
const requestContentLength = Number((_request$headers$cont = request.headers['content-length']) !== null && _request$headers$cont !== void 0 ? _request$headers$cont : 0);
|
|
129
120
|
const responseContentLength = Number((_reply$getHeader = reply.getHeader('content-length')) !== null && _reply$getHeader !== void 0 ? _reply$getHeader : 0);
|
|
130
121
|
const shouldSkipByRequest = (_allDefaultedOptions$2 = allDefaultedOptions.skip) === null || _allDefaultedOptions$2 === void 0 ? void 0 : _allDefaultedOptions$2.call(allDefaultedOptions, request, reply, labels);
|
|
131
|
-
|
|
132
122
|
if (!shouldSkipByRequest && !shouldSkipMetricsByEnvironment) {
|
|
133
123
|
// @ts-expect-error
|
|
134
124
|
recordRequest(request.__promsterTiming__, {
|
|
@@ -139,7 +129,6 @@ const createPlugin = async (fastify, options) => {
|
|
|
139
129
|
}
|
|
140
130
|
});
|
|
141
131
|
};
|
|
142
|
-
|
|
143
132
|
const plugin = fastifyPlugin__default["default"](createPlugin, {
|
|
144
133
|
fastify: '>= 1.6.0',
|
|
145
134
|
name: pkg.name
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@promster/fastify",
|
|
3
|
-
"version": "7.0.
|
|
3
|
+
"version": "7.0.7",
|
|
4
4
|
"description": "Fastify server integrations of promster",
|
|
5
5
|
"main": "dist/promster-fastify.cjs.js",
|
|
6
6
|
"typings": "dist/promster-fastify.cjs.d.ts",
|
|
@@ -36,12 +36,12 @@
|
|
|
36
36
|
"prometheus"
|
|
37
37
|
],
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@promster/metrics": "^9.1.
|
|
40
|
-
"fastify-plugin": "^
|
|
39
|
+
"@promster/metrics": "^9.1.6",
|
|
40
|
+
"fastify-plugin": "^4.4.0",
|
|
41
41
|
"merge-options": "3.0.4",
|
|
42
42
|
"parse-prometheus-text-format": "1.1.1"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"fastify": "
|
|
45
|
+
"fastify": "4.10.2"
|
|
46
46
|
}
|
|
47
47
|
}
|