@promster/fastify 6.0.0 → 7.0.3

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,3 +1,3 @@
1
1
  import { plugin, getRequestRecorder, signalIsUp, signalIsNotUp } from './plugin';
2
- import { getSummary, getContentType, Prometheus, defaultRegister, defaultNormalizers } from '@promster/metrics';
3
- export { plugin, getRequestRecorder, signalIsUp, signalIsNotUp, getSummary, getContentType, Prometheus, defaultRegister, defaultNormalizers, };
2
+ import { getSummary, getContentType, Prometheus, defaultRegister, defaultNormalizers, timing } from '@promster/metrics';
3
+ export { plugin, getRequestRecorder, signalIsUp, signalIsNotUp, getSummary, getContentType, Prometheus, defaultRegister, defaultNormalizers, timing, };
@@ -13,13 +13,11 @@ var merge__default = /*#__PURE__*/_interopDefault(merge);
13
13
 
14
14
  var pkg = {
15
15
  name: "@promster/fastify",
16
- version: "6.0.0",
16
+ version: "7.0.3",
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",
20
20
  types: "dist/promster-fastify.cjs.d.ts",
21
- scripts: {
22
- },
23
21
  files: [
24
22
  "readme.md",
25
23
  "package.json",
@@ -36,7 +34,8 @@ var pkg = {
36
34
  },
37
35
  repository: {
38
36
  type: "git",
39
- url: "git+https://github.com/tdeekens/promster.git"
37
+ url: "https://github.com/tdeekens/promster.git",
38
+ directory: "packages/fastify"
40
39
  },
41
40
  author: "Tobias Deekens <nerd@tdeekens.name>",
42
41
  license: "MIT",
@@ -50,12 +49,13 @@ var pkg = {
50
49
  "prometheus"
51
50
  ],
52
51
  dependencies: {
53
- "@promster/metrics": "^8.0.0",
52
+ "@promster/metrics": "^9.1.2",
54
53
  "fastify-plugin": "^3.0.0",
55
- "merge-options": "3.0.4"
54
+ "merge-options": "3.0.4",
55
+ "parse-prometheus-text-format": "1.1.1"
56
56
  },
57
57
  devDependencies: {
58
- fastify: "3.22.1"
58
+ fastify: "3.25.0"
59
59
  }
60
60
  };
61
61
 
@@ -88,12 +88,13 @@ const signalIsNotUp = () => {
88
88
  };
89
89
 
90
90
  const createPlugin = async (fastify, options) => {
91
- const defaultedOptions = merge__default["default"](metrics.createMetricTypes.defaultOptions, metrics.createRequestRecorder.defaultOptions, metrics.defaultNormalizers, options);
92
- const shouldSkipMetricsByEnvironment = defaultedOptions.detectKubernetes === true && !metrics.isRunningInKubernetes;
93
- const metricTypes = metrics.createMetricTypes(defaultedOptions);
94
- const observeGc = metrics.createGcObserver(metricTypes);
95
- recordRequest = metrics.createRequestRecorder(metricTypes, defaultedOptions);
96
- upMetric = metricTypes === null || metricTypes === void 0 ? void 0 : metricTypes.up;
91
+ const allDefaultedOptions = merge__default["default"](metrics.createHttpMetrics.defaultOptions, metrics.createGcMetrics.defaultOptions, metrics.createRequestRecorder.defaultOptions, metrics.createGcObserver.defaultOptions, metrics.defaultNormalizers, options);
92
+ const shouldSkipMetricsByEnvironment = metrics.skipMetricsInEnvironment(allDefaultedOptions);
93
+ const httpMetrics = metrics.createHttpMetrics(allDefaultedOptions);
94
+ const gcMetrics = metrics.createGcMetrics(allDefaultedOptions);
95
+ const observeGc = metrics.createGcObserver(gcMetrics, allDefaultedOptions);
96
+ recordRequest = metrics.createRequestRecorder(httpMetrics, allDefaultedOptions);
97
+ upMetric = gcMetrics === null || gcMetrics === void 0 ? void 0 : gcMetrics.up;
97
98
 
98
99
  if (!shouldSkipMetricsByEnvironment) {
99
100
  observeGc();
@@ -101,35 +102,35 @@ const createPlugin = async (fastify, options) => {
101
102
 
102
103
  fastify.decorate('Prometheus', metrics.Prometheus);
103
104
  fastify.decorate('recordRequest', recordRequest);
104
- fastify.decorateRequest('__promsterStartTime__', null);
105
+ fastify.decorateRequest('__promsterTiming__', null);
105
106
  fastify.addHook('onRequest', async (request, _) => {
106
107
  // @ts-expect-error
107
- request.__promsterStartTime__ = process.hrtime();
108
+ request.__promsterTiming__ = metrics.timing.start();
108
109
  });
109
110
  fastify.addHook('onResponse', async (request, reply) => {
110
- var _defaultedOptions$get, _request$headers$cont, _reply$getHeader, _defaultedOptions$ski;
111
+ var _request$raw$method, _allDefaultedOptions$, _request$headers$cont, _reply$getHeader, _allDefaultedOptions$2;
111
112
 
112
113
  const labels = Object.assign({}, {
113
- method: defaultedOptions.normalizeMethod(request.raw.method, {
114
- request,
115
- reply
114
+ method: allDefaultedOptions.normalizeMethod((_request$raw$method = request.raw.method) !== null && _request$raw$method !== void 0 ? _request$raw$method : '', {
115
+ req: request,
116
+ res: reply
116
117
  }),
117
- status_code: defaultedOptions.normalizeStatusCode(reply.statusCode, {
118
- request,
119
- reply
118
+ status_code: allDefaultedOptions.normalizeStatusCode(reply.statusCode, {
119
+ req: request,
120
+ res: reply
120
121
  }),
121
- path: defaultedOptions.normalizePath(extractPath(request), {
122
- request,
123
- reply
122
+ path: allDefaultedOptions.normalizePath(extractPath(request), {
123
+ req: request,
124
+ res: reply
124
125
  })
125
- }, (_defaultedOptions$get = defaultedOptions.getLabelValues) === null || _defaultedOptions$get === void 0 ? void 0 : _defaultedOptions$get.call(defaultedOptions, request, reply));
126
+ }, (_allDefaultedOptions$ = allDefaultedOptions.getLabelValues) === null || _allDefaultedOptions$ === void 0 ? void 0 : _allDefaultedOptions$.call(allDefaultedOptions, request, reply));
126
127
  const requestContentLength = Number((_request$headers$cont = request.headers['content-length']) !== null && _request$headers$cont !== void 0 ? _request$headers$cont : 0);
127
128
  const responseContentLength = Number((_reply$getHeader = reply.getHeader('content-length')) !== null && _reply$getHeader !== void 0 ? _reply$getHeader : 0);
128
- const shouldSkipByRequest = (_defaultedOptions$ski = defaultedOptions.skip) === null || _defaultedOptions$ski === void 0 ? void 0 : _defaultedOptions$ski.call(defaultedOptions, request, reply);
129
+ const shouldSkipByRequest = (_allDefaultedOptions$2 = allDefaultedOptions.skip) === null || _allDefaultedOptions$2 === void 0 ? void 0 : _allDefaultedOptions$2.call(allDefaultedOptions, request, reply, labels);
129
130
 
130
131
  if (!shouldSkipByRequest && !shouldSkipMetricsByEnvironment) {
131
132
  // @ts-expect-error
132
- recordRequest(request.__promsterStartTime__, {
133
+ recordRequest(request.__promsterTiming__, {
133
134
  labels,
134
135
  requestContentLength,
135
136
  responseContentLength
@@ -163,6 +164,10 @@ Object.defineProperty(exports, 'getSummary', {
163
164
  enumerable: true,
164
165
  get: function () { return metrics.getSummary; }
165
166
  });
167
+ Object.defineProperty(exports, 'timing', {
168
+ enumerable: true,
169
+ get: function () { return metrics.timing; }
170
+ });
166
171
  exports.getRequestRecorder = getRequestRecorder;
167
172
  exports.plugin = plugin;
168
173
  exports.signalIsNotUp = signalIsNotUp;
@@ -13,13 +13,11 @@ var merge__default = /*#__PURE__*/_interopDefault(merge);
13
13
 
14
14
  var pkg = {
15
15
  name: "@promster/fastify",
16
- version: "6.0.0",
16
+ version: "7.0.3",
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",
20
20
  types: "dist/promster-fastify.cjs.d.ts",
21
- scripts: {
22
- },
23
21
  files: [
24
22
  "readme.md",
25
23
  "package.json",
@@ -36,7 +34,8 @@ var pkg = {
36
34
  },
37
35
  repository: {
38
36
  type: "git",
39
- url: "git+https://github.com/tdeekens/promster.git"
37
+ url: "https://github.com/tdeekens/promster.git",
38
+ directory: "packages/fastify"
40
39
  },
41
40
  author: "Tobias Deekens <nerd@tdeekens.name>",
42
41
  license: "MIT",
@@ -50,12 +49,13 @@ var pkg = {
50
49
  "prometheus"
51
50
  ],
52
51
  dependencies: {
53
- "@promster/metrics": "^8.0.0",
52
+ "@promster/metrics": "^9.1.2",
54
53
  "fastify-plugin": "^3.0.0",
55
- "merge-options": "3.0.4"
54
+ "merge-options": "3.0.4",
55
+ "parse-prometheus-text-format": "1.1.1"
56
56
  },
57
57
  devDependencies: {
58
- fastify: "3.22.1"
58
+ fastify: "3.25.0"
59
59
  }
60
60
  };
61
61
 
@@ -88,12 +88,13 @@ const signalIsNotUp = () => {
88
88
  };
89
89
 
90
90
  const createPlugin = async (fastify, options) => {
91
- const defaultedOptions = merge__default["default"](metrics.createMetricTypes.defaultOptions, metrics.createRequestRecorder.defaultOptions, metrics.defaultNormalizers, options);
92
- const shouldSkipMetricsByEnvironment = defaultedOptions.detectKubernetes === true && !metrics.isRunningInKubernetes;
93
- const metricTypes = metrics.createMetricTypes(defaultedOptions);
94
- const observeGc = metrics.createGcObserver(metricTypes);
95
- recordRequest = metrics.createRequestRecorder(metricTypes, defaultedOptions);
96
- upMetric = metricTypes === null || metricTypes === void 0 ? void 0 : metricTypes.up;
91
+ const allDefaultedOptions = merge__default["default"](metrics.createHttpMetrics.defaultOptions, metrics.createGcMetrics.defaultOptions, metrics.createRequestRecorder.defaultOptions, metrics.createGcObserver.defaultOptions, metrics.defaultNormalizers, options);
92
+ const shouldSkipMetricsByEnvironment = metrics.skipMetricsInEnvironment(allDefaultedOptions);
93
+ const httpMetrics = metrics.createHttpMetrics(allDefaultedOptions);
94
+ const gcMetrics = metrics.createGcMetrics(allDefaultedOptions);
95
+ const observeGc = metrics.createGcObserver(gcMetrics, allDefaultedOptions);
96
+ recordRequest = metrics.createRequestRecorder(httpMetrics, allDefaultedOptions);
97
+ upMetric = gcMetrics === null || gcMetrics === void 0 ? void 0 : gcMetrics.up;
97
98
 
98
99
  if (!shouldSkipMetricsByEnvironment) {
99
100
  observeGc();
@@ -101,35 +102,35 @@ const createPlugin = async (fastify, options) => {
101
102
 
102
103
  fastify.decorate('Prometheus', metrics.Prometheus);
103
104
  fastify.decorate('recordRequest', recordRequest);
104
- fastify.decorateRequest('__promsterStartTime__', null);
105
+ fastify.decorateRequest('__promsterTiming__', null);
105
106
  fastify.addHook('onRequest', async (request, _) => {
106
107
  // @ts-expect-error
107
- request.__promsterStartTime__ = process.hrtime();
108
+ request.__promsterTiming__ = metrics.timing.start();
108
109
  });
109
110
  fastify.addHook('onResponse', async (request, reply) => {
110
- var _defaultedOptions$get, _request$headers$cont, _reply$getHeader, _defaultedOptions$ski;
111
+ var _request$raw$method, _allDefaultedOptions$, _request$headers$cont, _reply$getHeader, _allDefaultedOptions$2;
111
112
 
112
113
  const labels = Object.assign({}, {
113
- method: defaultedOptions.normalizeMethod(request.raw.method, {
114
- request,
115
- reply
114
+ method: allDefaultedOptions.normalizeMethod((_request$raw$method = request.raw.method) !== null && _request$raw$method !== void 0 ? _request$raw$method : '', {
115
+ req: request,
116
+ res: reply
116
117
  }),
117
- status_code: defaultedOptions.normalizeStatusCode(reply.statusCode, {
118
- request,
119
- reply
118
+ status_code: allDefaultedOptions.normalizeStatusCode(reply.statusCode, {
119
+ req: request,
120
+ res: reply
120
121
  }),
121
- path: defaultedOptions.normalizePath(extractPath(request), {
122
- request,
123
- reply
122
+ path: allDefaultedOptions.normalizePath(extractPath(request), {
123
+ req: request,
124
+ res: reply
124
125
  })
125
- }, (_defaultedOptions$get = defaultedOptions.getLabelValues) === null || _defaultedOptions$get === void 0 ? void 0 : _defaultedOptions$get.call(defaultedOptions, request, reply));
126
+ }, (_allDefaultedOptions$ = allDefaultedOptions.getLabelValues) === null || _allDefaultedOptions$ === void 0 ? void 0 : _allDefaultedOptions$.call(allDefaultedOptions, request, reply));
126
127
  const requestContentLength = Number((_request$headers$cont = request.headers['content-length']) !== null && _request$headers$cont !== void 0 ? _request$headers$cont : 0);
127
128
  const responseContentLength = Number((_reply$getHeader = reply.getHeader('content-length')) !== null && _reply$getHeader !== void 0 ? _reply$getHeader : 0);
128
- const shouldSkipByRequest = (_defaultedOptions$ski = defaultedOptions.skip) === null || _defaultedOptions$ski === void 0 ? void 0 : _defaultedOptions$ski.call(defaultedOptions, request, reply);
129
+ const shouldSkipByRequest = (_allDefaultedOptions$2 = allDefaultedOptions.skip) === null || _allDefaultedOptions$2 === void 0 ? void 0 : _allDefaultedOptions$2.call(allDefaultedOptions, request, reply, labels);
129
130
 
130
131
  if (!shouldSkipByRequest && !shouldSkipMetricsByEnvironment) {
131
132
  // @ts-expect-error
132
- recordRequest(request.__promsterStartTime__, {
133
+ recordRequest(request.__promsterTiming__, {
133
134
  labels,
134
135
  requestContentLength,
135
136
  responseContentLength
@@ -163,6 +164,10 @@ Object.defineProperty(exports, 'getSummary', {
163
164
  enumerable: true,
164
165
  get: function () { return metrics.getSummary; }
165
166
  });
167
+ Object.defineProperty(exports, 'timing', {
168
+ enumerable: true,
169
+ get: function () { return metrics.timing; }
170
+ });
166
171
  exports.getRequestRecorder = getRequestRecorder;
167
172
  exports.plugin = plugin;
168
173
  exports.signalIsNotUp = signalIsNotUp;
package/package.json CHANGED
@@ -1,11 +1,10 @@
1
1
  {
2
2
  "name": "@promster/fastify",
3
- "version": "6.0.0",
3
+ "version": "7.0.3",
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",
7
7
  "types": "dist/promster-fastify.cjs.d.ts",
8
- "scripts": {},
9
8
  "files": [
10
9
  "readme.md",
11
10
  "package.json",
@@ -22,7 +21,8 @@
22
21
  },
23
22
  "repository": {
24
23
  "type": "git",
25
- "url": "git+https://github.com/tdeekens/promster.git"
24
+ "url": "https://github.com/tdeekens/promster.git",
25
+ "directory": "packages/fastify"
26
26
  },
27
27
  "author": "Tobias Deekens <nerd@tdeekens.name>",
28
28
  "license": "MIT",
@@ -36,11 +36,12 @@
36
36
  "prometheus"
37
37
  ],
38
38
  "dependencies": {
39
- "@promster/metrics": "^8.0.0",
39
+ "@promster/metrics": "^9.1.2",
40
40
  "fastify-plugin": "^3.0.0",
41
- "merge-options": "3.0.4"
41
+ "merge-options": "3.0.4",
42
+ "parse-prometheus-text-format": "1.1.1"
42
43
  },
43
44
  "devDependencies": {
44
- "fastify": "3.22.1"
45
+ "fastify": "3.25.0"
45
46
  }
46
47
  }