@promster/metrics 15.5.1 → 15.6.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.
Files changed (42) hide show
  1. package/dist/index.cjs +411 -0
  2. package/dist/index.cjs.map +1 -0
  3. package/dist/index.d.cts +154 -0
  4. package/dist/index.d.ts +154 -0
  5. package/dist/index.js +358 -0
  6. package/dist/index.js.map +1 -0
  7. package/package.json +32 -10
  8. package/dist/declarations/src/client/client.d.ts +0 -9
  9. package/dist/declarations/src/client/index.d.ts +0 -2
  10. package/dist/declarations/src/create-gc-metrics/create-gc-metrics.d.ts +0 -14
  11. package/dist/declarations/src/create-gc-metrics/index.d.ts +0 -2
  12. package/dist/declarations/src/create-gc-observer/create-gc-observer.d.ts +0 -3
  13. package/dist/declarations/src/create-gc-observer/index.d.ts +0 -2
  14. package/dist/declarations/src/create-graphql-metrics/create-graphql-metrics.d.ts +0 -25
  15. package/dist/declarations/src/create-graphql-metrics/index.d.ts +0 -2
  16. package/dist/declarations/src/create-http-metrics/create-http-metrics.d.ts +0 -26
  17. package/dist/declarations/src/create-http-metrics/index.d.ts +0 -2
  18. package/dist/declarations/src/create-request-recorder/create-request-recorder.d.ts +0 -16
  19. package/dist/declarations/src/create-request-recorder/index.d.ts +0 -3
  20. package/dist/declarations/src/end-measurement-from/end-measurement-from.d.ts +0 -4
  21. package/dist/declarations/src/end-measurement-from/index.d.ts +0 -2
  22. package/dist/declarations/src/environment/index.d.ts +0 -3
  23. package/dist/declarations/src/environment/kubernetes.d.ts +0 -2
  24. package/dist/declarations/src/environment/skip-metrics-in-environment.d.ts +0 -6
  25. package/dist/declarations/src/index.d.ts +0 -16
  26. package/dist/declarations/src/normalizers/index.d.ts +0 -9
  27. package/dist/declarations/src/normalizers/method/index.d.ts +0 -2
  28. package/dist/declarations/src/normalizers/method/method.d.ts +0 -2
  29. package/dist/declarations/src/normalizers/path/index.d.ts +0 -2
  30. package/dist/declarations/src/normalizers/path/path.d.ts +0 -2
  31. package/dist/declarations/src/normalizers/status-code/index.d.ts +0 -2
  32. package/dist/declarations/src/normalizers/status-code/status-code.d.ts +0 -2
  33. package/dist/declarations/src/sort-labels/index.d.ts +0 -2
  34. package/dist/declarations/src/sort-labels/sort-labels.d.ts +0 -3
  35. package/dist/declarations/src/summary/index.d.ts +0 -2
  36. package/dist/declarations/src/summary/summary.d.ts +0 -3
  37. package/dist/declarations/src/timing/index.d.ts +0 -2
  38. package/dist/declarations/src/timing/timing.d.ts +0 -17
  39. package/dist/promster-metrics.cjs.d.ts +0 -2
  40. package/dist/promster-metrics.cjs.dev.js +0 -409
  41. package/dist/promster-metrics.cjs.js +0 -7
  42. package/dist/promster-metrics.cjs.prod.js +0 -409
package/dist/index.cjs ADDED
@@ -0,0 +1,411 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ //#region \0rolldown/runtime.js
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
11
+ key = keys[i];
12
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
13
+ get: ((k) => from[k]).bind(null, key),
14
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
15
+ });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
20
+ value: mod,
21
+ enumerable: true
22
+ }) : target, mod));
23
+ //#endregion
24
+ let es_toolkit_function = require("es-toolkit/function");
25
+ let prom_client = require("prom-client");
26
+ prom_client = __toESM(prom_client, 1);
27
+ let merge_options = require("merge-options");
28
+ merge_options = __toESM(merge_options, 1);
29
+ let _chainsafe_prometheus_gc_stats = require("@chainsafe/prometheus-gc-stats");
30
+ let node_url = require("node:url");
31
+ node_url = __toESM(node_url, 1);
32
+ let url_value_parser = require("url-value-parser");
33
+ url_value_parser = __toESM(url_value_parser, 1);
34
+ //#region src/environment/kubernetes.ts
35
+ const isRunningInKubernetes = () => Boolean(process.env.KUBERNETES_SERVICE_HOST);
36
+ //#endregion
37
+ //#region src/environment/skip-metrics-in-environment.ts
38
+ const skipMetricsInEnvironment = (options) => options.detectKubernetes === true && !isRunningInKubernetes();
39
+ //#endregion
40
+ //#region src/client/client.ts
41
+ const defaultRegister = prom_client.register;
42
+ const configure = (0, es_toolkit_function.once)((options) => {
43
+ if (!skipMetricsInEnvironment(options)) prom_client.collectDefaultMetrics(options);
44
+ });
45
+ //#endregion
46
+ //#region src/create-metric/create-metric.ts
47
+ const createHistogram = (configuration) => {
48
+ const existingMetric = defaultRegister.getSingleMetric(configuration.name);
49
+ if (existingMetric instanceof prom_client.Histogram) return existingMetric;
50
+ return new prom_client.Histogram(configuration);
51
+ };
52
+ const createCounter = (configuration) => {
53
+ const existingMetric = defaultRegister.getSingleMetric(configuration.name);
54
+ if (existingMetric instanceof prom_client.Counter) return existingMetric;
55
+ return new prom_client.Counter(configuration);
56
+ };
57
+ const createGauge = (configuration) => {
58
+ const existingMetric = defaultRegister.getSingleMetric(configuration.name);
59
+ if (existingMetric instanceof prom_client.Gauge) return existingMetric;
60
+ return new prom_client.Gauge(configuration);
61
+ };
62
+ const createSummary = (configuration) => {
63
+ const existingMetric = defaultRegister.getSingleMetric(configuration.name);
64
+ if (existingMetric instanceof prom_client.Summary) return existingMetric;
65
+ return new prom_client.Summary(configuration);
66
+ };
67
+ //#endregion
68
+ //#region src/create-gc-metrics/create-gc-metrics.ts
69
+ const asArray$2 = (maybeArray) => Array.isArray(maybeArray) ? maybeArray : [maybeArray];
70
+ const defaultOptions$4 = {
71
+ getLabelValues: () => ({}),
72
+ labels: [],
73
+ metricPrefix: "",
74
+ metricNames: { up: ["nodejs_up"] },
75
+ gcCollectionInterval: 6e3
76
+ };
77
+ const getMetrics$2 = (options) => ({ up: asArray$2(options.metricNames.up).map((nameOfUpMetric) => createGauge({
78
+ name: `${options.metricPrefix}${nameOfUpMetric}`,
79
+ help: "1 = nodejs server is up, 0 = nodejs server is not up"
80
+ })) });
81
+ const createGcMetrics = (options) => {
82
+ const defaultedOptions = (0, merge_options.default)(defaultOptions$4, options);
83
+ configure({ prefix: defaultedOptions.metricPrefix });
84
+ return getMetrics$2(defaultedOptions);
85
+ };
86
+ createGcMetrics.defaultOptions = defaultOptions$4;
87
+ //#endregion
88
+ //#region src/create-gc-observer/create-gc-observer.ts
89
+ const defaultOptions$3 = { disableGcMetrics: false };
90
+ const createGcObserver = (0, es_toolkit_function.once)((_metrics, options) => () => {
91
+ (0, _chainsafe_prometheus_gc_stats.gcStats)(defaultRegister, {
92
+ collectionInterval: options.gcCollectionInterval,
93
+ prefix: options.metricPrefix
94
+ });
95
+ });
96
+ createGcObserver.defaultOptions = defaultOptions$3;
97
+ //#endregion
98
+ //#region src/create-graphql-metrics/create-graphql-metrics.ts
99
+ const defaultGraphQlPercentiles = [
100
+ .5,
101
+ .9,
102
+ .95,
103
+ .98,
104
+ .99
105
+ ];
106
+ const defaultLabels$1 = ["operation_name"];
107
+ const asArray$1 = (maybeArray) => Array.isArray(maybeArray) ? maybeArray : [maybeArray];
108
+ const shouldObserveGraphQlParseDurationAsHistogram = (options) => options.metricTypes.includes("graphQlParseDurationHistogram");
109
+ const shouldObserveGraphQlValidationDurationAsHistogram = (options) => options.metricTypes.includes("graphQlValidationDurationHistogram");
110
+ const shouldObserveGraphQlResolveFieldDurationAsHistogram = (options) => options.metricTypes.includes("graphQlResolveFieldDurationHistogram");
111
+ const shouldObserveGraphQlRequestDurationAsHistogram = (options) => options.metricTypes.includes("graphQlRequestDurationHistogram");
112
+ const shouldObserveGraphQlErrorsTotalAsCounter = (options) => options.metricTypes.includes("graphQlErrorsTotal");
113
+ const defaultOptions$2 = {
114
+ getLabelValues: () => ({}),
115
+ labels: [],
116
+ metricPrefix: "",
117
+ metricTypes: [
118
+ "graphQlParseDurationHistogram",
119
+ "graphQlValidationDurationHistogram",
120
+ "graphQlResolveFieldDurationHistogram",
121
+ "graphQlRequestDurationHistogram",
122
+ "graphQlErrorsTotal"
123
+ ],
124
+ metricNames: {
125
+ graphQlParseDuration: ["graphql_parse_duration_seconds"],
126
+ graphQlValidationDuration: ["graphql_validation_duration_seconds"],
127
+ graphQlResolveFieldDuration: ["graphql_resolve_field_duration_seconds"],
128
+ graphQlRequestDuration: ["graphql_request_duration_seconds"],
129
+ graphQlErrorsTotal: ["graphql_errors_total"]
130
+ },
131
+ metricPercentiles: {
132
+ graphQlParseDuration: defaultGraphQlPercentiles,
133
+ graphQlValidationDuration: defaultGraphQlPercentiles,
134
+ graphQlResolveFieldDuration: defaultGraphQlPercentiles,
135
+ graphQlRequestDuration: defaultGraphQlPercentiles,
136
+ graphQlErrorsTotal: defaultGraphQlPercentiles
137
+ }
138
+ };
139
+ const getMetrics$1 = (options) => ({
140
+ graphQlParseDuration: shouldObserveGraphQlParseDurationAsHistogram(options) ? asArray$1(options.metricNames.graphQlParseDuration).map((nameOfGraphQlParseDuration) => createHistogram({
141
+ name: `${options.metricPrefix}${nameOfGraphQlParseDuration}`,
142
+ help: "The GraphQL request parse time in seconds.",
143
+ labelNames: defaultLabels$1.concat(options.labels).toSorted(),
144
+ buckets: options.metricPercentiles?.graphQlParseDuration || defaultGraphQlPercentiles
145
+ })) : void 0,
146
+ graphQlValidationDuration: shouldObserveGraphQlValidationDurationAsHistogram(options) ? asArray$1(options.metricNames.graphQlValidationDuration).map((nameOfGraphQlValidationDuration) => createHistogram({
147
+ name: `${options.metricPrefix}${nameOfGraphQlValidationDuration}`,
148
+ help: "The GraphQL request validation time in seconds.",
149
+ labelNames: defaultLabels$1.concat(options.labels).toSorted(),
150
+ buckets: options.metricPercentiles?.graphQlValidationDuration || defaultGraphQlPercentiles
151
+ })) : void 0,
152
+ graphQlResolveFieldDuration: shouldObserveGraphQlResolveFieldDurationAsHistogram(options) ? asArray$1(options.metricNames.graphQlResolveFieldDuration).map((nameOfGraphQlResolveFieldDuration) => createHistogram({
153
+ name: `${options.metricPrefix}${nameOfGraphQlResolveFieldDuration}`,
154
+ help: "The GraphQL field resolving time in seconds.",
155
+ labelNames: defaultLabels$1.concat(["field_name"]).concat(options.labels).toSorted(),
156
+ buckets: options.metricPercentiles?.graphQlResolveFieldDuration || defaultGraphQlPercentiles
157
+ })) : void 0,
158
+ graphQlRequestDuration: shouldObserveGraphQlRequestDurationAsHistogram(options) ? asArray$1(options.metricNames.graphQlRequestDuration).map((nameOfGraphQlRequestDuration) => createHistogram({
159
+ name: `${options.metricPrefix}${nameOfGraphQlRequestDuration}`,
160
+ help: "The GraphQL request duration time in seconds.",
161
+ labelNames: defaultLabels$1.concat(options.labels).toSorted(),
162
+ buckets: options.metricPercentiles?.graphQlRequestDuration || defaultGraphQlPercentiles
163
+ })) : void 0,
164
+ graphQlErrorsTotal: shouldObserveGraphQlErrorsTotalAsCounter(options) ? asArray$1(options.metricNames.graphQlErrorsTotal).map((nameOfGraphQlErrorsCount) => createCounter({
165
+ name: `${options.metricPrefix}${nameOfGraphQlErrorsCount}`,
166
+ help: "Count of errors while parsing, validating, or executing a GraphQL operation.",
167
+ labelNames: defaultLabels$1.concat(["phase"]).concat(options.labels).toSorted()
168
+ })) : void 0
169
+ });
170
+ const createGraphQlMetrics = (options) => {
171
+ const defaultedOptions = (0, merge_options.default)(defaultOptions$2, options);
172
+ configure({ prefix: defaultedOptions.metricPrefix });
173
+ return getMetrics$1(defaultedOptions);
174
+ };
175
+ createGraphQlMetrics.defaultOptions = defaultOptions$2;
176
+ //#endregion
177
+ //#region src/create-http-metrics/create-http-metrics.ts
178
+ const defaultHttpRequestDurationPercentileInSeconds = [
179
+ .5,
180
+ .9,
181
+ .95,
182
+ .98,
183
+ .99
184
+ ];
185
+ const defaultHttpRequestDurationInSeconds = [
186
+ .05,
187
+ .1,
188
+ .3,
189
+ .5,
190
+ .8,
191
+ 1,
192
+ 1.5,
193
+ 2,
194
+ 3,
195
+ 10
196
+ ];
197
+ const defaultHttpContentLengthInBytes = [
198
+ 1e5,
199
+ 2e5,
200
+ 5e5,
201
+ 1e6,
202
+ 15e5,
203
+ 2e6,
204
+ 3e6,
205
+ 5e6,
206
+ 1e7
207
+ ];
208
+ const defaultLabels = [
209
+ "path",
210
+ "status_code",
211
+ "method"
212
+ ];
213
+ const asArray = (maybeArray) => Array.isArray(maybeArray) ? maybeArray : [maybeArray];
214
+ const shouldObserveHttpRequestsAsSummary = (options) => options.metricTypes.includes("httpRequestsSummary");
215
+ const shouldObserveHttpRequestsAsHistogram = (options) => options.metricTypes.includes("httpRequestsHistogram");
216
+ const shouldObserveHttpRequestsAsCounter = (options) => options.metricTypes.includes("httpRequestsTotal");
217
+ const shouldObserveHttpContentLengthAsHistogram = (options) => options.metricTypes.includes("httpContentLengthHistogram");
218
+ const defaultOptions$1 = {
219
+ getLabelValues: () => ({}),
220
+ labels: [],
221
+ metricPrefix: "",
222
+ metricTypes: ["httpRequestsTotal", "httpRequestsHistogram"],
223
+ metricNames: {
224
+ httpRequestsTotal: ["http_requests_total"],
225
+ httpRequestDurationPerPercentileInSeconds: ["http_request_duration_per_percentile_seconds"],
226
+ httpRequestDurationInSeconds: ["http_request_duration_seconds"],
227
+ httpRequestContentLengthInBytes: ["http_request_content_length_bytes"],
228
+ httpResponseContentLengthInBytes: ["http_response_content_length_bytes"]
229
+ },
230
+ metricBuckets: {
231
+ httpRequestContentLengthInBytes: defaultHttpContentLengthInBytes,
232
+ httpRequestDurationInSeconds: defaultHttpRequestDurationInSeconds
233
+ },
234
+ metricPercentiles: {
235
+ httpRequestDurationPerPercentileInSeconds: defaultHttpRequestDurationPercentileInSeconds,
236
+ httpResponseContentLengthInBytes: defaultHttpContentLengthInBytes
237
+ }
238
+ };
239
+ const getMetrics = (options) => ({
240
+ httpRequestContentLengthInBytes: shouldObserveHttpContentLengthAsHistogram(options) ? asArray(options.metricNames.httpRequestContentLengthInBytes).map((nameOfHttpContentLengthMetric) => createHistogram({
241
+ name: `${options.metricPrefix}${nameOfHttpContentLengthMetric}`,
242
+ help: "The HTTP request content length in bytes.",
243
+ labelNames: defaultLabels.concat(options.labels).toSorted(),
244
+ buckets: options.metricBuckets?.httpRequestContentLengthInBytes || defaultHttpContentLengthInBytes
245
+ })) : void 0,
246
+ httpResponseContentLengthInBytes: shouldObserveHttpContentLengthAsHistogram(options) ? asArray(options.metricNames.httpResponseContentLengthInBytes).map((nameOfHttpContentLengthMetric) => createHistogram({
247
+ name: `${options.metricPrefix}${nameOfHttpContentLengthMetric}`,
248
+ help: "The HTTP response content length in bytes.",
249
+ labelNames: defaultLabels.concat(options.labels).toSorted(),
250
+ buckets: options.metricBuckets?.httpResponseContentLengthInBytes || defaultHttpContentLengthInBytes
251
+ })) : void 0
252
+ });
253
+ const getHttpRequestLatencyMetricsInSeconds = (options) => ({
254
+ httpRequestDurationPerPercentileInSeconds: shouldObserveHttpRequestsAsSummary(options) ? asArray(options.metricNames.httpRequestDurationPerPercentileInSeconds).map((nameOfHttpRequestDurationPerPercentileInSeconds) => createSummary({
255
+ name: `${options.metricPrefix}${nameOfHttpRequestDurationPerPercentileInSeconds}`,
256
+ help: "The HTTP request latencies in seconds.",
257
+ labelNames: defaultLabels.concat(options.labels).toSorted(),
258
+ percentiles: options.metricPercentiles?.httpRequestDurationPerPercentileInSeconds || defaultHttpRequestDurationPercentileInSeconds
259
+ })) : void 0,
260
+ httpRequestDurationInSeconds: shouldObserveHttpRequestsAsHistogram(options) ? asArray(options.metricNames.httpRequestDurationInSeconds).map((nameOfHttpRequestDurationInSecondsMetric) => createHistogram({
261
+ name: `${options.metricPrefix}${nameOfHttpRequestDurationInSecondsMetric}`,
262
+ help: "The HTTP request latencies in seconds.",
263
+ labelNames: defaultLabels.concat(options.labels).toSorted(),
264
+ buckets: options.metricBuckets?.httpRequestDurationInSeconds || defaultHttpRequestDurationInSeconds
265
+ })) : void 0
266
+ });
267
+ const getHttpRequestCounterMetric = (options) => ({ httpRequestsTotal: shouldObserveHttpRequestsAsCounter(options) ? asArray(options.metricNames.httpRequestsTotal).map((nameOfHttpRequestsTotalMetric) => createCounter({
268
+ name: `${options.metricPrefix}${nameOfHttpRequestsTotalMetric}`,
269
+ help: "The total HTTP requests.",
270
+ labelNames: defaultLabels.concat(options.labels).toSorted()
271
+ })) : void 0 });
272
+ const createHttpMetrics = (options) => {
273
+ const defaultedOptions = (0, merge_options.default)(defaultOptions$1, options);
274
+ configure({ prefix: defaultedOptions.metricPrefix });
275
+ const metrics = getMetrics(defaultedOptions);
276
+ const httpRequestLatencyMetricsInSeconds = getHttpRequestLatencyMetricsInSeconds(defaultedOptions);
277
+ const httpRequestCounterMetric = getHttpRequestCounterMetric(defaultedOptions);
278
+ return Object.assign({}, metrics, httpRequestLatencyMetricsInSeconds, httpRequestCounterMetric);
279
+ };
280
+ createHttpMetrics.defaultOptions = defaultOptions$1;
281
+ //#endregion
282
+ //#region src/end-measurement-from/end-measurement-from.ts
283
+ const NS_PER_SEC = 1e9;
284
+ function endMeasurementFrom(start) {
285
+ const [seconds, nanoseconds] = process.hrtime(start);
286
+ return { durationS: (seconds * NS_PER_SEC + nanoseconds) / NS_PER_SEC };
287
+ }
288
+ //#endregion
289
+ //#region src/sort-labels/sort-labels.ts
290
+ function sortLabels(unsortedLabels) {
291
+ return Object.keys(unsortedLabels).toSorted((a, b) => {
292
+ if (a < b) return -1;
293
+ if (a > b) return 1;
294
+ return 0;
295
+ }).reduce((sortedLabels, labelName) => {
296
+ sortedLabels[labelName] = unsortedLabels[labelName];
297
+ return sortedLabels;
298
+ }, {});
299
+ }
300
+ //#endregion
301
+ //#region src/create-request-recorder/create-request-recorder.ts
302
+ const defaultOptions = { detectKubernetes: false };
303
+ function isTiming(timing) {
304
+ return !Array.isArray(timing);
305
+ }
306
+ const createRequestRecorder = (metrics, options = defaultOptions) => {
307
+ const shouldSkipMetricsByEnvironment = skipMetricsInEnvironment((0, merge_options.default)(defaultOptions, options));
308
+ return (timing, recordingOptions) => {
309
+ const durationS = isTiming(timing) ? timing.end().value().seconds : endMeasurementFrom(timing).durationS;
310
+ const labels = sortLabels(recordingOptions.labels);
311
+ if (!shouldSkipMetricsByEnvironment && durationS !== void 0) {
312
+ if (metrics.httpRequestDurationInSeconds) for (const httpRequestDurationInSecondsMetricType of metrics.httpRequestDurationInSeconds) httpRequestDurationInSecondsMetricType.observe(labels, durationS);
313
+ }
314
+ if (!shouldSkipMetricsByEnvironment && durationS !== void 0) {
315
+ if (metrics.httpRequestDurationPerPercentileInSeconds) for (const httpRequestDurationPerPercentileInSecondsMetricType of metrics.httpRequestDurationPerPercentileInSeconds) httpRequestDurationPerPercentileInSecondsMetricType.observe(labels, durationS);
316
+ }
317
+ if (!shouldSkipMetricsByEnvironment && durationS !== void 0) {
318
+ if (metrics.httpRequestsTotal) for (const httpRequestsTotalMetricType of metrics.httpRequestsTotal) httpRequestsTotalMetricType.inc(labels);
319
+ }
320
+ if (recordingOptions.requestContentLength) {
321
+ if (metrics.httpRequestContentLengthInBytes) for (const httpRequestContentLengthInBytesMetricType of metrics.httpRequestContentLengthInBytes) httpRequestContentLengthInBytesMetricType.observe(labels, recordingOptions.requestContentLength);
322
+ }
323
+ if (recordingOptions.responseContentLength) {
324
+ if (metrics.httpResponseContentLengthInBytes) for (const httpResponseContentLengthInBytesMetricType of metrics.httpResponseContentLengthInBytes) httpResponseContentLengthInBytesMetricType.observe(labels, recordingOptions.responseContentLength);
325
+ }
326
+ };
327
+ };
328
+ createRequestRecorder.defaultOptions = defaultOptions;
329
+ //#endregion
330
+ //#region src/normalizers/method/method.ts
331
+ const normalizeMethod = (method) => method.toLowerCase();
332
+ //#endregion
333
+ //#region src/normalizers/path/path.ts
334
+ const urlValueParser = new url_value_parser.default();
335
+ const normalizePath = (path) => {
336
+ const parsedPathname = node_url.default.parse(path).pathname;
337
+ if (!parsedPathname) return "";
338
+ return urlValueParser.replacePathValues(parsedPathname, "#val");
339
+ };
340
+ //#endregion
341
+ //#region src/normalizers/status-code/status-code.ts
342
+ const normalizeStatusCode = (statusCode) => statusCode;
343
+ //#endregion
344
+ //#region src/normalizers/index.ts
345
+ const defaultNormalizers = {
346
+ normalizeStatusCode,
347
+ normalizePath,
348
+ normalizeMethod
349
+ };
350
+ //#endregion
351
+ //#region src/summary/summary.ts
352
+ const getSummary = async () => defaultRegister.metrics();
353
+ const getContentType = () => defaultRegister.contentType;
354
+ //#endregion
355
+ //#region src/timing/timing.ts
356
+ var Timing = class Timing {
357
+ static NS_PER_SEC = BigInt(1e9);
358
+ #startTime;
359
+ #endTime;
360
+ constructor() {
361
+ this.reset();
362
+ }
363
+ value() {
364
+ const startTime = this.#startTime;
365
+ const endTime = this.#endTime;
366
+ if (!endTime || !startTime) return { seconds: void 0 };
367
+ return { seconds: Number(endTime - startTime) / Number(Timing.NS_PER_SEC) };
368
+ }
369
+ reset() {
370
+ this.#startTime = process.hrtime.bigint();
371
+ this.#endTime = void 0;
372
+ return this;
373
+ }
374
+ end() {
375
+ this.#endTime = process.hrtime.bigint();
376
+ return this;
377
+ }
378
+ };
379
+ const timing = { start() {
380
+ return new Timing();
381
+ } };
382
+ //#endregion
383
+ Object.defineProperty(exports, "Prometheus", {
384
+ enumerable: true,
385
+ get: function() {
386
+ return prom_client;
387
+ }
388
+ });
389
+ exports.createCounter = createCounter;
390
+ exports.createGauge = createGauge;
391
+ exports.createGcMetrics = createGcMetrics;
392
+ exports.createGcObserver = createGcObserver;
393
+ exports.createGraphQlMetrics = createGraphQlMetrics;
394
+ exports.createHistogram = createHistogram;
395
+ exports.createHttpMetrics = createHttpMetrics;
396
+ exports.createRequestRecorder = createRequestRecorder;
397
+ exports.createSummary = createSummary;
398
+ exports.defaultNormalizers = defaultNormalizers;
399
+ exports.defaultRegister = defaultRegister;
400
+ exports.endMeasurementFrom = endMeasurementFrom;
401
+ exports.getContentType = getContentType;
402
+ exports.getSummary = getSummary;
403
+ exports.isRunningInKubernetes = isRunningInKubernetes;
404
+ exports.normalizeMethod = normalizeMethod;
405
+ exports.normalizePath = normalizePath;
406
+ exports.normalizeStatusCode = normalizeStatusCode;
407
+ exports.skipMetricsInEnvironment = skipMetricsInEnvironment;
408
+ exports.sortLabels = sortLabels;
409
+ exports.timing = timing;
410
+
411
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","names":["Prometheus","Prometheus","asArray","defaultOptions","getMetrics","defaultOptions","defaultLabels","asArray","defaultOptions","getMetrics","defaultOptions","UrlValueParser","url","#startTime","#endTime"],"sources":["../src/environment/kubernetes.ts","../src/environment/skip-metrics-in-environment.ts","../src/client/client.ts","../src/create-metric/create-metric.ts","../src/create-gc-metrics/create-gc-metrics.ts","../src/create-gc-observer/create-gc-observer.ts","../src/create-graphql-metrics/create-graphql-metrics.ts","../src/create-http-metrics/create-http-metrics.ts","../src/end-measurement-from/end-measurement-from.ts","../src/sort-labels/sort-labels.ts","../src/create-request-recorder/create-request-recorder.ts","../src/normalizers/method/method.ts","../src/normalizers/path/path.ts","../src/normalizers/status-code/status-code.ts","../src/normalizers/index.ts","../src/summary/summary.ts","../src/timing/timing.ts"],"sourcesContent":["const isRunningInKubernetes = () =>\n Boolean(process.env.KUBERNETES_SERVICE_HOST);\n\nexport { isRunningInKubernetes };\n","import type { TOptionalPromsterOptions } from '@promster/types';\n\nimport { isRunningInKubernetes } from './kubernetes';\n\ntype TSkipMetricsInEnvironmentOptions = {\n detectKubernetes?: TOptionalPromsterOptions['detectKubernetes'];\n};\n\nconst skipMetricsInEnvironment = (options: TSkipMetricsInEnvironmentOptions) =>\n options.detectKubernetes === true && !isRunningInKubernetes();\n\nexport { skipMetricsInEnvironment };\n","import { once } from 'es-toolkit/function';\nimport type { PrometheusContentType } from 'prom-client';\nimport * as Prometheus from 'prom-client';\n\nimport { skipMetricsInEnvironment } from '../environment';\n\n// NOTE:\n// This is the `globalRegistry` provided by the `prom-client`\n// We could create multiple registries with `new Prometheus.registry()`.\nconst defaultRegister = Prometheus.register;\n\ninterface TClientOptions extends Prometheus.DefaultMetricsCollectorConfiguration<PrometheusContentType> {\n detectKubernetes?: boolean;\n prefix?: string;\n}\n\nconst configure = once((options: TClientOptions) => {\n const shouldSkipMetricsInEnvironment = skipMetricsInEnvironment(options);\n\n if (!shouldSkipMetricsInEnvironment) {\n Prometheus.collectDefaultMetrics(options);\n }\n});\n\nexport { Prometheus, defaultRegister, configure };\n","import type {\n Counter,\n CounterConfiguration,\n Gauge,\n GaugeConfiguration,\n Histogram,\n HistogramConfiguration,\n Summary,\n SummaryConfiguration,\n} from 'prom-client';\n\nimport { defaultRegister, Prometheus } from '../client';\n\n// NOTE:\n// All metrics share the `prom-client` global registry (see `../client`).\n// Registering a metric whose name already exists throws. This happens when\n// a metric-defining module is evaluated more than once, for instance when a\n// bundler or package manager ships duplicate physical copies of a package.\n// These helpers make registration idempotent: an already registered metric\n// of the same name and type is returned instead of re-created. The first\n// registration wins, so a later differing configuration is ignored. A name\n// already taken by a different metric type falls through to `prom-client`,\n// which rejects it with the clear \"already registered\" error.\n\nconst createHistogram = (\n configuration: HistogramConfiguration<string>,\n): Histogram<string> => {\n const existingMetric = defaultRegister.getSingleMetric(configuration.name);\n\n if (existingMetric instanceof Prometheus.Histogram) {\n return existingMetric;\n }\n\n return new Prometheus.Histogram(configuration);\n};\n\nconst createCounter = (\n configuration: CounterConfiguration<string>,\n): Counter<string> => {\n const existingMetric = defaultRegister.getSingleMetric(configuration.name);\n\n if (existingMetric instanceof Prometheus.Counter) {\n return existingMetric;\n }\n\n return new Prometheus.Counter(configuration);\n};\n\nconst createGauge = (\n configuration: GaugeConfiguration<string>,\n): Gauge<string> => {\n const existingMetric = defaultRegister.getSingleMetric(configuration.name);\n\n if (existingMetric instanceof Prometheus.Gauge) {\n return existingMetric;\n }\n\n return new Prometheus.Gauge(configuration);\n};\n\nconst createSummary = (\n configuration: SummaryConfiguration<string>,\n): Summary<string> => {\n const existingMetric = defaultRegister.getSingleMetric(configuration.name);\n\n if (existingMetric instanceof Prometheus.Summary) {\n return existingMetric;\n }\n\n return new Prometheus.Summary(configuration);\n};\n\nexport { createCounter, createGauge, createHistogram, createSummary };\n","import type { TDefaultedPromsterOptions, TGcMetrics } from '@promster/types';\nimport merge from 'merge-options';\n\nimport { configure } from '../client';\nimport { createGauge } from '../create-metric';\n\nconst asArray = (maybeArray: Readonly<string[] | string>) =>\n Array.isArray(maybeArray) ? maybeArray : [maybeArray];\n\nconst defaultOptions = {\n getLabelValues: () => ({}),\n labels: [],\n metricPrefix: '',\n metricNames: {\n up: ['nodejs_up'],\n },\n gcCollectionInterval: 6000,\n};\n\nconst getMetrics = (options: TDefaultedPromsterOptions) => ({\n up: asArray(options.metricNames.up).map((nameOfUpMetric: string) =>\n createGauge({\n name: `${options.metricPrefix}${nameOfUpMetric}`,\n help: '1 = nodejs server is up, 0 = nodejs server is not up',\n }),\n ),\n});\n\nconst createGcMetrics = (options: TDefaultedPromsterOptions): TGcMetrics => {\n const defaultedOptions: TDefaultedPromsterOptions = merge(\n defaultOptions,\n options,\n );\n\n configure({\n prefix: defaultedOptions.metricPrefix,\n });\n\n const gcMetrics = getMetrics(defaultedOptions);\n\n return gcMetrics;\n};\n\ncreateGcMetrics.defaultOptions = defaultOptions;\n\nexport { createGcMetrics };\n","import { gcStats } from '@chainsafe/prometheus-gc-stats';\nimport type { TDefaultedPromsterOptions, TGcMetrics } from '@promster/types';\nimport { once } from 'es-toolkit/function';\n\nimport { defaultRegister } from '../client/client';\n\nconst defaultOptions = {\n disableGcMetrics: false,\n};\n\nconst createGcObserver = once(\n (_metrics: TGcMetrics, options: TDefaultedPromsterOptions) => () => {\n gcStats(defaultRegister, {\n collectionInterval: options.gcCollectionInterval,\n prefix: options.metricPrefix,\n });\n },\n);\n\n// @ts-expect-error\ncreateGcObserver.defaultOptions = defaultOptions;\n\nexport { createGcObserver };\n","import type {\n TDefaultedPromsterOptions,\n TGraphQlMetrics,\n} from '@promster/types';\nimport merge from 'merge-options';\n\nimport { configure } from '../client';\nimport { createCounter, createHistogram } from '../create-metric';\n\nconst defaultGraphQlPercentiles = [0.5, 0.9, 0.95, 0.98, 0.99];\n\nconst defaultLabels = ['operation_name'];\nconst asArray = (maybeArray: Readonly<string[] | string>) =>\n Array.isArray(maybeArray) ? maybeArray : [maybeArray];\n\nconst shouldObserveGraphQlParseDurationAsHistogram = (\n options: TDefaultedPromsterOptions,\n) => options.metricTypes.includes('graphQlParseDurationHistogram');\nconst shouldObserveGraphQlValidationDurationAsHistogram = (\n options: TDefaultedPromsterOptions,\n) => options.metricTypes.includes('graphQlValidationDurationHistogram');\nconst shouldObserveGraphQlResolveFieldDurationAsHistogram = (\n options: TDefaultedPromsterOptions,\n) => options.metricTypes.includes('graphQlResolveFieldDurationHistogram');\nconst shouldObserveGraphQlRequestDurationAsHistogram = (\n options: TDefaultedPromsterOptions,\n) => options.metricTypes.includes('graphQlRequestDurationHistogram');\nconst shouldObserveGraphQlErrorsTotalAsCounter = (\n options: TDefaultedPromsterOptions,\n) => options.metricTypes.includes('graphQlErrorsTotal');\n\nconst defaultOptions = {\n getLabelValues: () => ({}),\n labels: [],\n metricPrefix: '',\n metricTypes: [\n 'graphQlParseDurationHistogram',\n 'graphQlValidationDurationHistogram',\n 'graphQlResolveFieldDurationHistogram',\n 'graphQlRequestDurationHistogram',\n 'graphQlErrorsTotal',\n ],\n metricNames: {\n graphQlParseDuration: ['graphql_parse_duration_seconds'],\n graphQlValidationDuration: ['graphql_validation_duration_seconds'],\n graphQlResolveFieldDuration: ['graphql_resolve_field_duration_seconds'],\n graphQlRequestDuration: ['graphql_request_duration_seconds'],\n graphQlErrorsTotal: ['graphql_errors_total'],\n },\n metricPercentiles: {\n graphQlParseDuration: defaultGraphQlPercentiles,\n graphQlValidationDuration: defaultGraphQlPercentiles,\n graphQlResolveFieldDuration: defaultGraphQlPercentiles,\n graphQlRequestDuration: defaultGraphQlPercentiles,\n graphQlErrorsTotal: defaultGraphQlPercentiles,\n },\n};\n\nconst getMetrics = (options: TDefaultedPromsterOptions) => ({\n graphQlParseDuration: shouldObserveGraphQlParseDurationAsHistogram(options)\n ? asArray(options.metricNames.graphQlParseDuration).map(\n (nameOfGraphQlParseDuration: string) =>\n createHistogram({\n name: `${options.metricPrefix}${nameOfGraphQlParseDuration}`,\n help: 'The GraphQL request parse time in seconds.',\n labelNames: defaultLabels.concat(options.labels).toSorted(),\n buckets:\n options.metricPercentiles?.graphQlParseDuration ||\n defaultGraphQlPercentiles,\n }),\n )\n : undefined,\n\n graphQlValidationDuration: shouldObserveGraphQlValidationDurationAsHistogram(\n options,\n )\n ? asArray(options.metricNames.graphQlValidationDuration).map(\n (nameOfGraphQlValidationDuration: string) =>\n createHistogram({\n name: `${options.metricPrefix}${nameOfGraphQlValidationDuration}`,\n help: 'The GraphQL request validation time in seconds.',\n labelNames: defaultLabels.concat(options.labels).toSorted(),\n buckets:\n options.metricPercentiles?.graphQlValidationDuration ||\n defaultGraphQlPercentiles,\n }),\n )\n : undefined,\n\n graphQlResolveFieldDuration:\n shouldObserveGraphQlResolveFieldDurationAsHistogram(options)\n ? asArray(options.metricNames.graphQlResolveFieldDuration).map(\n (nameOfGraphQlResolveFieldDuration: string) =>\n createHistogram({\n name: `${options.metricPrefix}${nameOfGraphQlResolveFieldDuration}`,\n help: 'The GraphQL field resolving time in seconds.',\n labelNames: defaultLabels\n .concat(['field_name'])\n .concat(options.labels)\n .toSorted(),\n buckets:\n options.metricPercentiles?.graphQlResolveFieldDuration ||\n defaultGraphQlPercentiles,\n }),\n )\n : undefined,\n\n graphQlRequestDuration: shouldObserveGraphQlRequestDurationAsHistogram(\n options,\n )\n ? asArray(options.metricNames.graphQlRequestDuration).map(\n (nameOfGraphQlRequestDuration: string) =>\n createHistogram({\n name: `${options.metricPrefix}${nameOfGraphQlRequestDuration}`,\n help: 'The GraphQL request duration time in seconds.',\n labelNames: defaultLabels.concat(options.labels).toSorted(),\n buckets:\n options.metricPercentiles?.graphQlRequestDuration ||\n defaultGraphQlPercentiles,\n }),\n )\n : undefined,\n\n graphQlErrorsTotal: shouldObserveGraphQlErrorsTotalAsCounter(options)\n ? asArray(options.metricNames.graphQlErrorsTotal).map(\n (nameOfGraphQlErrorsCount: string) =>\n createCounter({\n name: `${options.metricPrefix}${nameOfGraphQlErrorsCount}`,\n help: 'Count of errors while parsing, validating, or executing a GraphQL operation.',\n labelNames: defaultLabels\n .concat(['phase'])\n .concat(options.labels)\n .toSorted(),\n }),\n )\n : undefined,\n});\n\nconst createGraphQlMetrics = (\n options: TDefaultedPromsterOptions,\n): TGraphQlMetrics => {\n const defaultedOptions: TDefaultedPromsterOptions = merge(\n defaultOptions,\n options,\n );\n\n configure({\n prefix: defaultedOptions.metricPrefix,\n });\n\n const metrics = getMetrics(defaultedOptions);\n\n return metrics;\n};\n\ncreateGraphQlMetrics.defaultOptions = defaultOptions;\n\nexport { createGraphQlMetrics };\n","import type { TDefaultedPromsterOptions, THttpMetrics } from '@promster/types';\nimport merge from 'merge-options';\n\nimport { configure } from '../client';\nimport {\n createCounter,\n createHistogram,\n createSummary,\n} from '../create-metric';\n\nconst defaultHttpRequestDurationPercentileInSeconds = [\n 0.5, 0.9, 0.95, 0.98, 0.99,\n];\nconst defaultHttpRequestDurationInSeconds = [\n 0.05, 0.1, 0.3, 0.5, 0.8, 1, 1.5, 2, 3, 10,\n];\nconst defaultHttpContentLengthInBytes = [\n 100000, 200000, 500000, 1000000, 1500000, 2000000, 3000000, 5000000, 10000000,\n];\n\nconst defaultLabels = ['path', 'status_code', 'method'];\nconst asArray = (maybeArray: Readonly<string[] | string>) =>\n Array.isArray(maybeArray) ? maybeArray : [maybeArray];\n\nconst shouldObserveHttpRequestsAsSummary = (\n options: TDefaultedPromsterOptions,\n) => options.metricTypes.includes('httpRequestsSummary');\nconst shouldObserveHttpRequestsAsHistogram = (\n options: TDefaultedPromsterOptions,\n) => options.metricTypes.includes('httpRequestsHistogram');\nconst shouldObserveHttpRequestsAsCounter = (\n options: TDefaultedPromsterOptions,\n) => options.metricTypes.includes('httpRequestsTotal');\nconst shouldObserveHttpContentLengthAsHistogram = (\n options: TDefaultedPromsterOptions,\n) => options.metricTypes.includes('httpContentLengthHistogram');\n\nconst defaultOptions = {\n getLabelValues: () => ({}),\n labels: [],\n metricPrefix: '',\n metricTypes: ['httpRequestsTotal', 'httpRequestsHistogram'],\n metricNames: {\n httpRequestsTotal: ['http_requests_total'],\n httpRequestDurationPerPercentileInSeconds: [\n 'http_request_duration_per_percentile_seconds',\n ],\n httpRequestDurationInSeconds: ['http_request_duration_seconds'],\n httpRequestContentLengthInBytes: ['http_request_content_length_bytes'],\n httpResponseContentLengthInBytes: ['http_response_content_length_bytes'],\n },\n metricBuckets: {\n httpRequestContentLengthInBytes: defaultHttpContentLengthInBytes,\n httpRequestDurationInSeconds: defaultHttpRequestDurationInSeconds,\n },\n metricPercentiles: {\n httpRequestDurationPerPercentileInSeconds:\n defaultHttpRequestDurationPercentileInSeconds,\n httpResponseContentLengthInBytes: defaultHttpContentLengthInBytes,\n },\n};\n\nconst getMetrics = (options: TDefaultedPromsterOptions) => ({\n httpRequestContentLengthInBytes: shouldObserveHttpContentLengthAsHistogram(\n options,\n )\n ? asArray(options.metricNames.httpRequestContentLengthInBytes).map(\n (nameOfHttpContentLengthMetric: string) =>\n createHistogram({\n name: `${options.metricPrefix}${nameOfHttpContentLengthMetric}`,\n help: 'The HTTP request content length in bytes.',\n labelNames: defaultLabels.concat(options.labels).toSorted(),\n buckets:\n options.metricBuckets?.httpRequestContentLengthInBytes ||\n defaultHttpContentLengthInBytes,\n }),\n )\n : undefined,\n\n httpResponseContentLengthInBytes: shouldObserveHttpContentLengthAsHistogram(\n options,\n )\n ? asArray(options.metricNames.httpResponseContentLengthInBytes).map(\n (nameOfHttpContentLengthMetric: string) =>\n createHistogram({\n name: `${options.metricPrefix}${nameOfHttpContentLengthMetric}`,\n help: 'The HTTP response content length in bytes.',\n labelNames: defaultLabels.concat(options.labels).toSorted(),\n buckets:\n options.metricBuckets?.httpResponseContentLengthInBytes ||\n defaultHttpContentLengthInBytes,\n }),\n )\n : undefined,\n});\n\nconst getHttpRequestLatencyMetricsInSeconds = (\n options: TDefaultedPromsterOptions,\n) => ({\n httpRequestDurationPerPercentileInSeconds: shouldObserveHttpRequestsAsSummary(\n options,\n )\n ? asArray(\n options.metricNames.httpRequestDurationPerPercentileInSeconds,\n ).map((nameOfHttpRequestDurationPerPercentileInSeconds: string) =>\n createSummary({\n name: `${options.metricPrefix}${nameOfHttpRequestDurationPerPercentileInSeconds}`,\n help: 'The HTTP request latencies in seconds.',\n labelNames: defaultLabels.concat(options.labels).toSorted(),\n percentiles:\n options.metricPercentiles\n ?.httpRequestDurationPerPercentileInSeconds ||\n defaultHttpRequestDurationPercentileInSeconds,\n }),\n )\n : undefined,\n\n httpRequestDurationInSeconds: shouldObserveHttpRequestsAsHistogram(options)\n ? asArray(options.metricNames.httpRequestDurationInSeconds).map(\n (nameOfHttpRequestDurationInSecondsMetric: string) =>\n createHistogram({\n name: `${options.metricPrefix}${nameOfHttpRequestDurationInSecondsMetric}`,\n help: 'The HTTP request latencies in seconds.',\n labelNames: defaultLabels.concat(options.labels).toSorted(),\n buckets:\n options.metricBuckets?.httpRequestDurationInSeconds ||\n defaultHttpRequestDurationInSeconds,\n }),\n )\n : undefined,\n});\n\nconst getHttpRequestCounterMetric = (options: TDefaultedPromsterOptions) => ({\n httpRequestsTotal: shouldObserveHttpRequestsAsCounter(options)\n ? asArray(options.metricNames.httpRequestsTotal).map(\n (nameOfHttpRequestsTotalMetric: string) =>\n createCounter({\n name: `${options.metricPrefix}${nameOfHttpRequestsTotalMetric}`,\n help: 'The total HTTP requests.',\n labelNames: defaultLabels.concat(options.labels).toSorted(),\n }),\n )\n : undefined,\n});\n\nconst createHttpMetrics = (\n options: TDefaultedPromsterOptions,\n): THttpMetrics => {\n const defaultedOptions: TDefaultedPromsterOptions = merge(\n defaultOptions,\n options,\n );\n\n configure({\n prefix: defaultedOptions.metricPrefix,\n });\n\n const metrics = getMetrics(defaultedOptions);\n\n const httpRequestLatencyMetricsInSeconds =\n getHttpRequestLatencyMetricsInSeconds(defaultedOptions);\n const httpRequestCounterMetric =\n getHttpRequestCounterMetric(defaultedOptions);\n\n return Object.assign(\n {},\n metrics,\n httpRequestLatencyMetricsInSeconds,\n httpRequestCounterMetric,\n );\n};\n\ncreateHttpMetrics.defaultOptions = defaultOptions;\n\nexport { createHttpMetrics };\n","const NS_PER_SEC = 1e9;\n\nfunction endMeasurementFrom(start: [number, number]) {\n const [seconds, nanoseconds] = process.hrtime(start);\n\n return {\n durationS: (seconds * NS_PER_SEC + nanoseconds) / NS_PER_SEC,\n };\n}\n\nexport { endMeasurementFrom };\n","import type { TLabelValues } from '@promster/types';\n\nfunction sortLabels(unsortedLabels: TLabelValues): TLabelValues {\n return Object.keys(unsortedLabels)\n .toSorted((a, b) => {\n if (a < b) {\n return -1;\n }\n\n if (a > b) {\n return 1;\n }\n\n return 0;\n })\n .reduce<TLabelValues>((sortedLabels, labelName) => {\n sortedLabels[labelName] = unsortedLabels[labelName];\n return sortedLabels;\n }, {});\n}\n\nexport { sortLabels };\n","import type {\n TDefaultedPromsterOptions,\n THttpMetrics,\n TLabelValues,\n TOptionalPromsterOptions,\n} from '@promster/types';\nimport merge from 'merge-options';\n\nimport { endMeasurementFrom } from '../end-measurement-from';\nimport { skipMetricsInEnvironment } from '../environment';\nimport { sortLabels } from '../sort-labels';\nimport type { Timing } from '../timing';\n\ntype TRecordingOptions = {\n labels: TLabelValues;\n requestContentLength?: number;\n responseContentLength?: number;\n};\n\ntype TLegacyTiming = [number, number];\nexport type TRequestRecorder = (\n _timing: Timing | TLegacyTiming,\n _recordingOptions: TRecordingOptions,\n) => void;\n\nconst defaultOptions: TOptionalPromsterOptions = {\n detectKubernetes: false,\n};\n\nfunction isTiming(timing: Timing | TLegacyTiming): timing is Timing {\n return !Array.isArray(timing);\n}\n\nconst createRequestRecorder = (\n metrics: THttpMetrics,\n options: TOptionalPromsterOptions = defaultOptions,\n): TRequestRecorder => {\n const defaultedRecorderOptions: TDefaultedPromsterOptions = merge(\n defaultOptions,\n options,\n );\n const shouldSkipMetricsByEnvironment = skipMetricsInEnvironment(\n defaultedRecorderOptions,\n );\n\n return (\n timing: Timing | TLegacyTiming,\n recordingOptions: TRecordingOptions,\n ) => {\n const durationS = isTiming(timing)\n ? timing.end().value().seconds\n : endMeasurementFrom(timing).durationS;\n\n const labels = sortLabels(recordingOptions.labels);\n\n if (!shouldSkipMetricsByEnvironment && durationS !== undefined) {\n if (metrics.httpRequestDurationInSeconds) {\n for (const httpRequestDurationInSecondsMetricType of metrics.httpRequestDurationInSeconds) {\n httpRequestDurationInSecondsMetricType.observe(labels, durationS);\n }\n }\n }\n\n if (!shouldSkipMetricsByEnvironment && durationS !== undefined) {\n if (metrics.httpRequestDurationPerPercentileInSeconds) {\n for (const httpRequestDurationPerPercentileInSecondsMetricType of metrics.httpRequestDurationPerPercentileInSeconds) {\n httpRequestDurationPerPercentileInSecondsMetricType.observe(\n labels,\n durationS,\n );\n }\n }\n }\n\n if (!shouldSkipMetricsByEnvironment && durationS !== undefined) {\n if (metrics.httpRequestsTotal) {\n for (const httpRequestsTotalMetricType of metrics.httpRequestsTotal) {\n httpRequestsTotalMetricType.inc(labels);\n }\n }\n }\n\n if (recordingOptions.requestContentLength) {\n if (metrics.httpRequestContentLengthInBytes) {\n for (const httpRequestContentLengthInBytesMetricType of metrics.httpRequestContentLengthInBytes) {\n httpRequestContentLengthInBytesMetricType.observe(\n labels,\n recordingOptions.requestContentLength,\n );\n }\n }\n }\n\n if (recordingOptions.responseContentLength) {\n if (metrics.httpResponseContentLengthInBytes) {\n for (const httpResponseContentLengthInBytesMetricType of metrics.httpResponseContentLengthInBytes) {\n httpResponseContentLengthInBytesMetricType.observe(\n labels,\n recordingOptions.responseContentLength,\n );\n }\n }\n }\n };\n};\n\ncreateRequestRecorder.defaultOptions = defaultOptions;\n\nexport { createRequestRecorder, sortLabels, endMeasurementFrom };\n","const normalizeMethod = (method: string): string => method.toLowerCase();\n\nexport { normalizeMethod };\n","import url from 'node:url';\n\nimport UrlValueParser from 'url-value-parser';\n\nconst urlValueParser = new UrlValueParser();\n\nconst normalizePath = (path: string): string => {\n const parsedPathname = url.parse(path).pathname;\n\n if (!parsedPathname) {\n return '';\n }\n\n return urlValueParser.replacePathValues(parsedPathname, '#val');\n};\n\nexport { normalizePath };\n","const normalizeStatusCode = (statusCode: number): number => statusCode;\n\nexport { normalizeStatusCode };\n","import { normalizeMethod } from './method';\nimport { normalizePath } from './path';\nimport { normalizeStatusCode } from './status-code';\n\nconst defaultNormalizers = {\n normalizeStatusCode,\n normalizePath,\n normalizeMethod,\n};\n\nexport {\n normalizeStatusCode,\n normalizePath,\n normalizeMethod,\n defaultNormalizers,\n};\n","import { defaultRegister } from '../client';\n\nconst getSummary = async () => defaultRegister.metrics();\nconst getContentType = () => defaultRegister.contentType;\n\nexport { getSummary, getContentType };\n","class Timing {\n static NS_PER_SEC = BigInt(1e9);\n\n #startTime?: bigint;\n #endTime?: bigint;\n\n constructor() {\n this.reset();\n }\n\n value() {\n const startTime = this.#startTime;\n const endTime = this.#endTime;\n\n if (!endTime || !startTime) {\n return { seconds: undefined };\n }\n\n return { seconds: Number(endTime - startTime) / Number(Timing.NS_PER_SEC) };\n }\n\n reset() {\n this.#startTime = process.hrtime.bigint();\n this.#endTime = undefined;\n\n return this;\n }\n\n end() {\n this.#endTime = process.hrtime.bigint();\n\n return this;\n }\n}\n\nconst timing = {\n start() {\n return new Timing();\n },\n};\n\nexport default timing;\nexport { Timing };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,MAAM,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AAI,CAAC,WAAW,CAAC,WACf,OAAO,EAAE,SAAS,KAAA,EAAU;EAG9B,OAAO,EAAE,SAAS,OAAO,UAAU,SAAS,IAAI,OAAO,OAAO,UAAU,EAAE;CAC5E;CAEA,QAAQ;EACN,KAAKD,aAAa,QAAQ,OAAO,OAAO;EACxC,KAAKC,WAAW,KAAA;EAEhB,OAAO;CACT;CAEA,MAAM;EACJ,KAAKA,WAAW,QAAQ,OAAO,OAAO;EAEtC,OAAO;CACT;AACF;AAEA,MAAM,SAAS,EACb,QAAQ;CACN,OAAO,IAAI,OAAO;AACpB,EACF"}
@@ -0,0 +1,154 @@
1
+ import * as Prometheus from "prom-client";
2
+ import { Counter, CounterConfiguration, Gauge, GaugeConfiguration, Histogram, HistogramConfiguration, Summary, SummaryConfiguration } from "prom-client";
3
+ import { TDefaultedPromsterOptions, TGcMetrics, TGraphQlMetrics, THttpMetrics, TLabelValues, TOptionalPromsterOptions } from "@promster/types";
4
+ export type * from "@promster/types";
5
+ //#region src/client/client.d.ts
6
+ declare const defaultRegister: Prometheus.Registry<"text/plain; version=0.0.4; charset=utf-8">;
7
+ //#endregion
8
+ //#region src/create-gc-metrics/create-gc-metrics.d.ts
9
+ declare const defaultOptions$3: {
10
+ getLabelValues: () => {};
11
+ labels: never[];
12
+ metricPrefix: string;
13
+ metricNames: {
14
+ up: string[];
15
+ };
16
+ gcCollectionInterval: number;
17
+ };
18
+ declare function createGcMetrics(options: TDefaultedPromsterOptions): TGcMetrics;
19
+ declare namespace createGcMetrics {
20
+ export { defaultOptions$3 as defaultOptions };
21
+ }
22
+ //#endregion
23
+ //#region src/create-gc-observer/create-gc-observer.d.ts
24
+ declare const createGcObserver: (_metrics: TGcMetrics, options: TDefaultedPromsterOptions) => () => void;
25
+ //#endregion
26
+ //#region src/create-graphql-metrics/create-graphql-metrics.d.ts
27
+ declare const defaultOptions$2: {
28
+ getLabelValues: () => {};
29
+ labels: never[];
30
+ metricPrefix: string;
31
+ metricTypes: string[];
32
+ metricNames: {
33
+ graphQlParseDuration: string[];
34
+ graphQlValidationDuration: string[];
35
+ graphQlResolveFieldDuration: string[];
36
+ graphQlRequestDuration: string[];
37
+ graphQlErrorsTotal: string[];
38
+ };
39
+ metricPercentiles: {
40
+ graphQlParseDuration: number[];
41
+ graphQlValidationDuration: number[];
42
+ graphQlResolveFieldDuration: number[];
43
+ graphQlRequestDuration: number[];
44
+ graphQlErrorsTotal: number[];
45
+ };
46
+ };
47
+ declare function createGraphQlMetrics(options: TDefaultedPromsterOptions): TGraphQlMetrics;
48
+ declare namespace createGraphQlMetrics {
49
+ export { defaultOptions$2 as defaultOptions };
50
+ }
51
+ //#endregion
52
+ //#region src/create-http-metrics/create-http-metrics.d.ts
53
+ declare const defaultOptions$1: {
54
+ getLabelValues: () => {};
55
+ labels: never[];
56
+ metricPrefix: string;
57
+ metricTypes: string[];
58
+ metricNames: {
59
+ httpRequestsTotal: string[];
60
+ httpRequestDurationPerPercentileInSeconds: string[];
61
+ httpRequestDurationInSeconds: string[];
62
+ httpRequestContentLengthInBytes: string[];
63
+ httpResponseContentLengthInBytes: string[];
64
+ };
65
+ metricBuckets: {
66
+ httpRequestContentLengthInBytes: number[];
67
+ httpRequestDurationInSeconds: number[];
68
+ };
69
+ metricPercentiles: {
70
+ httpRequestDurationPerPercentileInSeconds: number[];
71
+ httpResponseContentLengthInBytes: number[];
72
+ };
73
+ };
74
+ declare function createHttpMetrics(options: TDefaultedPromsterOptions): THttpMetrics;
75
+ declare namespace createHttpMetrics {
76
+ export { defaultOptions$1 as defaultOptions };
77
+ }
78
+ //#endregion
79
+ //#region src/create-metric/create-metric.d.ts
80
+ declare const createHistogram: (configuration: HistogramConfiguration<string>) => Histogram<string>;
81
+ declare const createCounter: (configuration: CounterConfiguration<string>) => Counter<string>;
82
+ declare const createGauge: (configuration: GaugeConfiguration<string>) => Gauge<string>;
83
+ declare const createSummary: (configuration: SummaryConfiguration<string>) => Summary<string>;
84
+ //#endregion
85
+ //#region src/end-measurement-from/end-measurement-from.d.ts
86
+ declare function endMeasurementFrom(start: [number, number]): {
87
+ durationS: number;
88
+ };
89
+ //#endregion
90
+ //#region src/sort-labels/sort-labels.d.ts
91
+ declare function sortLabels(unsortedLabels: TLabelValues): TLabelValues;
92
+ //#endregion
93
+ //#region src/timing/timing.d.ts
94
+ declare class Timing {
95
+ #private;
96
+ static NS_PER_SEC: bigint;
97
+ constructor();
98
+ value(): {
99
+ seconds: undefined;
100
+ } | {
101
+ seconds: number;
102
+ };
103
+ reset(): this;
104
+ end(): this;
105
+ }
106
+ declare const timing: {
107
+ start(): Timing;
108
+ };
109
+ //#endregion
110
+ //#region src/create-request-recorder/create-request-recorder.d.ts
111
+ type TRecordingOptions = {
112
+ labels: TLabelValues;
113
+ requestContentLength?: number;
114
+ responseContentLength?: number;
115
+ };
116
+ type TLegacyTiming = [number, number];
117
+ type TRequestRecorder = (_timing: Timing | TLegacyTiming, _recordingOptions: TRecordingOptions) => void;
118
+ declare const defaultOptions: TOptionalPromsterOptions;
119
+ declare function createRequestRecorder(metrics: THttpMetrics, options?: TOptionalPromsterOptions): TRequestRecorder;
120
+ declare namespace createRequestRecorder {
121
+ export { defaultOptions };
122
+ }
123
+ //#endregion
124
+ //#region src/environment/kubernetes.d.ts
125
+ declare const isRunningInKubernetes: () => boolean;
126
+ //#endregion
127
+ //#region src/environment/skip-metrics-in-environment.d.ts
128
+ type TSkipMetricsInEnvironmentOptions = {
129
+ detectKubernetes?: TOptionalPromsterOptions['detectKubernetes'];
130
+ };
131
+ declare const skipMetricsInEnvironment: (options: TSkipMetricsInEnvironmentOptions) => boolean;
132
+ //#endregion
133
+ //#region src/normalizers/method/method.d.ts
134
+ declare const normalizeMethod: (method: string) => string;
135
+ //#endregion
136
+ //#region src/normalizers/path/path.d.ts
137
+ declare const normalizePath: (path: string) => string;
138
+ //#endregion
139
+ //#region src/normalizers/status-code/status-code.d.ts
140
+ declare const normalizeStatusCode: (statusCode: number) => number;
141
+ //#endregion
142
+ //#region src/normalizers/index.d.ts
143
+ declare const defaultNormalizers: {
144
+ normalizeStatusCode: typeof normalizeStatusCode;
145
+ normalizePath: typeof normalizePath;
146
+ normalizeMethod: typeof normalizeMethod;
147
+ };
148
+ //#endregion
149
+ //#region src/summary/summary.d.ts
150
+ declare const getSummary: () => Promise<string>;
151
+ declare const getContentType: () => "text/plain; version=0.0.4; charset=utf-8";
152
+ //#endregion
153
+ export { Prometheus, type Timing as TPromsterTiming, type TRequestRecorder, createCounter, createGauge, createGcMetrics, createGcObserver, createGraphQlMetrics, createHistogram, createHttpMetrics, createRequestRecorder, createSummary, defaultNormalizers, defaultRegister, endMeasurementFrom, getContentType, getSummary, isRunningInKubernetes, normalizeMethod, normalizePath, normalizeStatusCode, skipMetricsInEnvironment, sortLabels, timing };
154
+ //# sourceMappingURL=index.d.cts.map