@promster/metrics 15.5.0 → 15.5.2

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 +385 -0
  2. package/dist/index.cjs.map +1 -0
  3. package/dist/index.d.cts +144 -0
  4. package/dist/index.d.ts +144 -0
  5. package/dist/index.js +336 -0
  6. package/dist/index.js.map +1 -0
  7. package/package.json +30 -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 -410
  41. package/dist/promster-metrics.cjs.js +0 -7
  42. package/dist/promster-metrics.cjs.prod.js +0 -410
@@ -0,0 +1,144 @@
1
+ import * as Prometheus from "prom-client";
2
+ import { TDefaultedPromsterOptions, TGcMetrics, TGraphQlMetrics, THttpMetrics, TLabelValues, TOptionalPromsterOptions } from "@promster/types";
3
+ export type * from "@promster/types";
4
+
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 createGcMetrics: {
10
+ (options: TDefaultedPromsterOptions): TGcMetrics;
11
+ defaultOptions: {
12
+ getLabelValues: () => {};
13
+ labels: never[];
14
+ metricPrefix: string;
15
+ metricNames: {
16
+ up: string[];
17
+ };
18
+ gcCollectionInterval: number;
19
+ };
20
+ };
21
+ //#endregion
22
+ //#region src/create-gc-observer/create-gc-observer.d.ts
23
+ declare const createGcObserver: (_metrics: TGcMetrics, options: TDefaultedPromsterOptions) => () => void;
24
+ //#endregion
25
+ //#region src/create-graphql-metrics/create-graphql-metrics.d.ts
26
+ declare const createGraphQlMetrics: {
27
+ (options: TDefaultedPromsterOptions): TGraphQlMetrics;
28
+ defaultOptions: {
29
+ getLabelValues: () => {};
30
+ labels: never[];
31
+ metricPrefix: string;
32
+ metricTypes: string[];
33
+ metricNames: {
34
+ graphQlParseDuration: string[];
35
+ graphQlValidationDuration: string[];
36
+ graphQlResolveFieldDuration: string[];
37
+ graphQlRequestDuration: string[];
38
+ graphQlErrorsTotal: string[];
39
+ };
40
+ metricPercentiles: {
41
+ graphQlParseDuration: number[];
42
+ graphQlValidationDuration: number[];
43
+ graphQlResolveFieldDuration: number[];
44
+ graphQlRequestDuration: number[];
45
+ graphQlErrorsTotal: number[];
46
+ };
47
+ };
48
+ };
49
+ //#endregion
50
+ //#region src/create-http-metrics/create-http-metrics.d.ts
51
+ declare const createHttpMetrics: {
52
+ (options: TDefaultedPromsterOptions): THttpMetrics;
53
+ defaultOptions: {
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
+ };
75
+ //#endregion
76
+ //#region src/end-measurement-from/end-measurement-from.d.ts
77
+ declare function endMeasurementFrom(start: [number, number]): {
78
+ durationS: number;
79
+ };
80
+ //#endregion
81
+ //#region src/sort-labels/sort-labels.d.ts
82
+ declare function sortLabels(unsortedLabels: TLabelValues): TLabelValues;
83
+ //#endregion
84
+ //#region src/timing/timing.d.ts
85
+ declare class Timing {
86
+ #private;
87
+ static NS_PER_SEC: bigint;
88
+ constructor();
89
+ value(): {
90
+ seconds: undefined;
91
+ } | {
92
+ seconds: number;
93
+ };
94
+ reset(): this;
95
+ end(): this;
96
+ }
97
+ declare const timing: {
98
+ start(): Timing;
99
+ };
100
+ //#endregion
101
+ //#region src/create-request-recorder/create-request-recorder.d.ts
102
+ type TRecordingOptions = {
103
+ labels: TLabelValues;
104
+ requestContentLength?: number;
105
+ responseContentLength?: number;
106
+ };
107
+ type TLegacyTiming = [number, number];
108
+ type TRequestRecorder = (_timing: Timing | TLegacyTiming, _recordingOptions: TRecordingOptions) => void;
109
+ declare const createRequestRecorder: {
110
+ (metrics: THttpMetrics, options?: TOptionalPromsterOptions): TRequestRecorder;
111
+ defaultOptions: TOptionalPromsterOptions;
112
+ };
113
+ //#endregion
114
+ //#region src/environment/kubernetes.d.ts
115
+ declare const isRunningInKubernetes: () => boolean;
116
+ //#endregion
117
+ //#region src/environment/skip-metrics-in-environment.d.ts
118
+ type TSkipMetricsInEnvironmentOptions = {
119
+ detectKubernetes?: TOptionalPromsterOptions['detectKubernetes'];
120
+ };
121
+ declare const skipMetricsInEnvironment: (options: TSkipMetricsInEnvironmentOptions) => boolean;
122
+ //#endregion
123
+ //#region src/normalizers/method/method.d.ts
124
+ declare const normalizeMethod: (method: string) => string;
125
+ //#endregion
126
+ //#region src/normalizers/path/path.d.ts
127
+ declare const normalizePath: (path: string) => string;
128
+ //#endregion
129
+ //#region src/normalizers/status-code/status-code.d.ts
130
+ declare const normalizeStatusCode: (statusCode: number) => number;
131
+ //#endregion
132
+ //#region src/normalizers/index.d.ts
133
+ declare const defaultNormalizers: {
134
+ normalizeStatusCode: (statusCode: number) => number;
135
+ normalizePath: (path: string) => string;
136
+ normalizeMethod: (method: string) => string;
137
+ };
138
+ //#endregion
139
+ //#region src/summary/summary.d.ts
140
+ declare const getSummary: () => Promise<string>;
141
+ declare const getContentType: () => "text/plain; version=0.0.4; charset=utf-8";
142
+ //#endregion
143
+ export { Prometheus, type Timing as TPromsterTiming, type TRequestRecorder, createGcMetrics, createGcObserver, createGraphQlMetrics, createHttpMetrics, createRequestRecorder, defaultNormalizers, defaultRegister, endMeasurementFrom, getContentType, getSummary, isRunningInKubernetes, normalizeMethod, normalizePath, normalizeStatusCode, skipMetricsInEnvironment, sortLabels, timing };
144
+ //# sourceMappingURL=index.d.ts.map
package/dist/index.js ADDED
@@ -0,0 +1,336 @@
1
+ import { once } from "es-toolkit/function";
2
+ import * as Prometheus from "prom-client";
3
+ import merge from "merge-options";
4
+ import { gcStats } from "@chainsafe/prometheus-gc-stats";
5
+ import url from "node:url";
6
+ import UrlValueParser from "url-value-parser";
7
+ //#region src/environment/kubernetes.ts
8
+ const isRunningInKubernetes = () => Boolean(process.env.KUBERNETES_SERVICE_HOST);
9
+ //#endregion
10
+ //#region src/environment/skip-metrics-in-environment.ts
11
+ const skipMetricsInEnvironment = (options) => options.detectKubernetes === true && !isRunningInKubernetes();
12
+ //#endregion
13
+ //#region src/client/client.ts
14
+ const defaultRegister = Prometheus.register;
15
+ const configure = once((options) => {
16
+ if (!skipMetricsInEnvironment(options)) Prometheus.collectDefaultMetrics(options);
17
+ });
18
+ //#endregion
19
+ //#region src/create-gc-metrics/create-gc-metrics.ts
20
+ const asArray$2 = (maybeArray) => Array.isArray(maybeArray) ? maybeArray : [maybeArray];
21
+ const defaultOptions$4 = {
22
+ getLabelValues: () => ({}),
23
+ labels: [],
24
+ metricPrefix: "",
25
+ metricNames: { up: ["nodejs_up"] },
26
+ gcCollectionInterval: 6e3
27
+ };
28
+ const getMetrics$2 = (options) => ({ up: asArray$2(options.metricNames.up).map((nameOfUpMetric) => new Prometheus.Gauge({
29
+ name: `${options.metricPrefix}${nameOfUpMetric}`,
30
+ help: "1 = nodejs server is up, 0 = nodejs server is not up"
31
+ })) });
32
+ const createGcMetrics = (options) => {
33
+ const defaultedOptions = merge(defaultOptions$4, options);
34
+ configure({ prefix: defaultedOptions.metricPrefix });
35
+ return getMetrics$2(defaultedOptions);
36
+ };
37
+ createGcMetrics.defaultOptions = defaultOptions$4;
38
+ //#endregion
39
+ //#region src/create-gc-observer/create-gc-observer.ts
40
+ const defaultOptions$3 = { disableGcMetrics: false };
41
+ const createGcObserver = once((_metrics, options) => () => {
42
+ gcStats(defaultRegister, {
43
+ collectionInterval: options.gcCollectionInterval,
44
+ prefix: options.metricPrefix
45
+ });
46
+ });
47
+ createGcObserver.defaultOptions = defaultOptions$3;
48
+ //#endregion
49
+ //#region src/create-graphql-metrics/create-graphql-metrics.ts
50
+ const defaultGraphQlPercentiles = [
51
+ .5,
52
+ .9,
53
+ .95,
54
+ .98,
55
+ .99
56
+ ];
57
+ const defaultLabels$1 = ["operation_name"];
58
+ const asArray$1 = (maybeArray) => Array.isArray(maybeArray) ? maybeArray : [maybeArray];
59
+ const shouldObserveGraphQlParseDurationAsHistogram = (options) => options.metricTypes.includes("graphQlParseDurationHistogram");
60
+ const shouldObserveGraphQlValidationDurationAsHistogram = (options) => options.metricTypes.includes("graphQlValidationDurationHistogram");
61
+ const shouldObserveGraphQlResolveFieldDurationAsHistogram = (options) => options.metricTypes.includes("graphQlResolveFieldDurationHistogram");
62
+ const shouldObserveGraphQlRequestDurationAsHistogram = (options) => options.metricTypes.includes("graphQlRequestDurationHistogram");
63
+ const shouldObserveGraphQlErrorsTotalAsCounter = (options) => options.metricTypes.includes("graphQlErrorsTotal");
64
+ const defaultOptions$2 = {
65
+ getLabelValues: () => ({}),
66
+ labels: [],
67
+ metricPrefix: "",
68
+ metricTypes: [
69
+ "graphQlParseDurationHistogram",
70
+ "graphQlValidationDurationHistogram",
71
+ "graphQlResolveFieldDurationHistogram",
72
+ "graphQlRequestDurationHistogram",
73
+ "graphQlErrorsTotal"
74
+ ],
75
+ metricNames: {
76
+ graphQlParseDuration: ["graphql_parse_duration_seconds"],
77
+ graphQlValidationDuration: ["graphql_validation_duration_seconds"],
78
+ graphQlResolveFieldDuration: ["graphql_resolve_field_duration_seconds"],
79
+ graphQlRequestDuration: ["graphql_request_duration_seconds"],
80
+ graphQlErrorsTotal: ["graphql_errors_total"]
81
+ },
82
+ metricPercentiles: {
83
+ graphQlParseDuration: defaultGraphQlPercentiles,
84
+ graphQlValidationDuration: defaultGraphQlPercentiles,
85
+ graphQlResolveFieldDuration: defaultGraphQlPercentiles,
86
+ graphQlRequestDuration: defaultGraphQlPercentiles,
87
+ graphQlErrorsTotal: defaultGraphQlPercentiles
88
+ }
89
+ };
90
+ const getMetrics$1 = (options) => ({
91
+ graphQlParseDuration: shouldObserveGraphQlParseDurationAsHistogram(options) ? asArray$1(options.metricNames.graphQlParseDuration).map((nameOfGraphQlParseDuration) => new Prometheus.Histogram({
92
+ name: `${options.metricPrefix}${nameOfGraphQlParseDuration}`,
93
+ help: "The GraphQL request parse time in seconds.",
94
+ labelNames: defaultLabels$1.concat(options.labels).toSorted(),
95
+ buckets: options.metricPercentiles?.graphQlParseDuration || defaultGraphQlPercentiles
96
+ })) : void 0,
97
+ graphQlValidationDuration: shouldObserveGraphQlValidationDurationAsHistogram(options) ? asArray$1(options.metricNames.graphQlValidationDuration).map((nameOfGraphQlValidationDuration) => new Prometheus.Histogram({
98
+ name: `${options.metricPrefix}${nameOfGraphQlValidationDuration}`,
99
+ help: "The GraphQL request validation time in seconds.",
100
+ labelNames: defaultLabels$1.concat(options.labels).toSorted(),
101
+ buckets: options.metricPercentiles?.graphQlValidationDuration || defaultGraphQlPercentiles
102
+ })) : void 0,
103
+ graphQlResolveFieldDuration: shouldObserveGraphQlResolveFieldDurationAsHistogram(options) ? asArray$1(options.metricNames.graphQlResolveFieldDuration).map((nameOfGraphQlResolveFieldDuration) => new Prometheus.Histogram({
104
+ name: `${options.metricPrefix}${nameOfGraphQlResolveFieldDuration}`,
105
+ help: "The GraphQL field resolving time in seconds.",
106
+ labelNames: defaultLabels$1.concat(["field_name"]).concat(options.labels).toSorted(),
107
+ buckets: options.metricPercentiles?.graphQlResolveFieldDuration || defaultGraphQlPercentiles
108
+ })) : void 0,
109
+ graphQlRequestDuration: shouldObserveGraphQlRequestDurationAsHistogram(options) ? asArray$1(options.metricNames.graphQlRequestDuration).map((nameOfGraphQlRequestDuration) => new Prometheus.Histogram({
110
+ name: `${options.metricPrefix}${nameOfGraphQlRequestDuration}`,
111
+ help: "The GraphQL request duration time in seconds.",
112
+ labelNames: defaultLabels$1.concat(options.labels).toSorted(),
113
+ buckets: options.metricPercentiles?.graphQlRequestDuration || defaultGraphQlPercentiles
114
+ })) : void 0,
115
+ graphQlErrorsTotal: shouldObserveGraphQlErrorsTotalAsCounter(options) ? asArray$1(options.metricNames.graphQlErrorsTotal).map((nameOfGraphQlErrorsCount) => new Prometheus.Counter({
116
+ name: `${options.metricPrefix}${nameOfGraphQlErrorsCount}`,
117
+ help: "Count of errors while parsing, validating, or executing a GraphQL operation.",
118
+ labelNames: defaultLabels$1.concat(["phase"]).concat(options.labels).toSorted()
119
+ })) : void 0
120
+ });
121
+ const createGraphQlMetrics = (options) => {
122
+ const defaultedOptions = merge(defaultOptions$2, options);
123
+ configure({ prefix: defaultedOptions.metricPrefix });
124
+ return getMetrics$1(defaultedOptions);
125
+ };
126
+ createGraphQlMetrics.defaultOptions = defaultOptions$2;
127
+ //#endregion
128
+ //#region src/create-http-metrics/create-http-metrics.ts
129
+ const defaultHttpRequestDurationPercentileInSeconds = [
130
+ .5,
131
+ .9,
132
+ .95,
133
+ .98,
134
+ .99
135
+ ];
136
+ const defaultHttpRequestDurationInSeconds = [
137
+ .05,
138
+ .1,
139
+ .3,
140
+ .5,
141
+ .8,
142
+ 1,
143
+ 1.5,
144
+ 2,
145
+ 3,
146
+ 10
147
+ ];
148
+ const defaultHttpContentLengthInBytes = [
149
+ 1e5,
150
+ 2e5,
151
+ 5e5,
152
+ 1e6,
153
+ 15e5,
154
+ 2e6,
155
+ 3e6,
156
+ 5e6,
157
+ 1e7
158
+ ];
159
+ const defaultLabels = [
160
+ "path",
161
+ "status_code",
162
+ "method"
163
+ ];
164
+ const asArray = (maybeArray) => Array.isArray(maybeArray) ? maybeArray : [maybeArray];
165
+ const shouldObserveHttpRequestsAsSummary = (options) => options.metricTypes.includes("httpRequestsSummary");
166
+ const shouldObserveHttpRequestsAsHistogram = (options) => options.metricTypes.includes("httpRequestsHistogram");
167
+ const shouldObserveHttpRequestsAsCounter = (options) => options.metricTypes.includes("httpRequestsTotal");
168
+ const shouldObserveHttpContentLengthAsHistogram = (options) => options.metricTypes.includes("httpContentLengthHistogram");
169
+ const defaultOptions$1 = {
170
+ getLabelValues: () => ({}),
171
+ labels: [],
172
+ metricPrefix: "",
173
+ metricTypes: ["httpRequestsTotal", "httpRequestsHistogram"],
174
+ metricNames: {
175
+ httpRequestsTotal: ["http_requests_total"],
176
+ httpRequestDurationPerPercentileInSeconds: ["http_request_duration_per_percentile_seconds"],
177
+ httpRequestDurationInSeconds: ["http_request_duration_seconds"],
178
+ httpRequestContentLengthInBytes: ["http_request_content_length_bytes"],
179
+ httpResponseContentLengthInBytes: ["http_response_content_length_bytes"]
180
+ },
181
+ metricBuckets: {
182
+ httpRequestContentLengthInBytes: defaultHttpContentLengthInBytes,
183
+ httpRequestDurationInSeconds: defaultHttpRequestDurationInSeconds
184
+ },
185
+ metricPercentiles: {
186
+ httpRequestDurationPerPercentileInSeconds: defaultHttpRequestDurationPercentileInSeconds,
187
+ httpResponseContentLengthInBytes: defaultHttpContentLengthInBytes
188
+ }
189
+ };
190
+ const getMetrics = (options) => ({
191
+ httpRequestContentLengthInBytes: shouldObserveHttpContentLengthAsHistogram(options) ? asArray(options.metricNames.httpRequestContentLengthInBytes).map((nameOfHttpContentLengthMetric) => new Prometheus.Histogram({
192
+ name: `${options.metricPrefix}${nameOfHttpContentLengthMetric}`,
193
+ help: "The HTTP request content length in bytes.",
194
+ labelNames: defaultLabels.concat(options.labels).toSorted(),
195
+ buckets: options.metricBuckets?.httpRequestContentLengthInBytes || defaultHttpContentLengthInBytes
196
+ })) : void 0,
197
+ httpResponseContentLengthInBytes: shouldObserveHttpContentLengthAsHistogram(options) ? asArray(options.metricNames.httpResponseContentLengthInBytes).map((nameOfHttpContentLengthMetric) => new Prometheus.Histogram({
198
+ name: `${options.metricPrefix}${nameOfHttpContentLengthMetric}`,
199
+ help: "The HTTP response content length in bytes.",
200
+ labelNames: defaultLabels.concat(options.labels).toSorted(),
201
+ buckets: options.metricBuckets?.httpResponseContentLengthInBytes || defaultHttpContentLengthInBytes
202
+ })) : void 0
203
+ });
204
+ const getHttpRequestLatencyMetricsInSeconds = (options) => ({
205
+ httpRequestDurationPerPercentileInSeconds: shouldObserveHttpRequestsAsSummary(options) ? asArray(options.metricNames.httpRequestDurationPerPercentileInSeconds).map((nameOfHttpRequestDurationPerPercentileInSeconds) => new Prometheus.Summary({
206
+ name: `${options.metricPrefix}${nameOfHttpRequestDurationPerPercentileInSeconds}`,
207
+ help: "The HTTP request latencies in seconds.",
208
+ labelNames: defaultLabels.concat(options.labels).toSorted(),
209
+ percentiles: options.metricPercentiles?.httpRequestDurationPerPercentileInSeconds || defaultHttpRequestDurationPercentileInSeconds
210
+ })) : void 0,
211
+ httpRequestDurationInSeconds: shouldObserveHttpRequestsAsHistogram(options) ? asArray(options.metricNames.httpRequestDurationInSeconds).map((nameOfHttpRequestDurationInSecondsMetric) => new Prometheus.Histogram({
212
+ name: `${options.metricPrefix}${nameOfHttpRequestDurationInSecondsMetric}`,
213
+ help: "The HTTP request latencies in seconds.",
214
+ labelNames: defaultLabels.concat(options.labels).toSorted(),
215
+ buckets: options.metricBuckets?.httpRequestDurationInSeconds || defaultHttpRequestDurationInSeconds
216
+ })) : void 0
217
+ });
218
+ const getHttpRequestCounterMetric = (options) => ({ httpRequestsTotal: shouldObserveHttpRequestsAsCounter(options) ? asArray(options.metricNames.httpRequestsTotal).map((nameOfHttpRequestsTotalMetric) => new Prometheus.Counter({
219
+ name: `${options.metricPrefix}${nameOfHttpRequestsTotalMetric}`,
220
+ help: "The total HTTP requests.",
221
+ labelNames: defaultLabels.concat(options.labels).toSorted()
222
+ })) : void 0 });
223
+ const createHttpMetrics = (options) => {
224
+ const defaultedOptions = merge(defaultOptions$1, options);
225
+ configure({ prefix: defaultedOptions.metricPrefix });
226
+ const metrics = getMetrics(defaultedOptions);
227
+ const httpRequestLatencyMetricsInSeconds = getHttpRequestLatencyMetricsInSeconds(defaultedOptions);
228
+ const httpRequestCounterMetric = getHttpRequestCounterMetric(defaultedOptions);
229
+ return Object.assign({}, metrics, httpRequestLatencyMetricsInSeconds, httpRequestCounterMetric);
230
+ };
231
+ createHttpMetrics.defaultOptions = defaultOptions$1;
232
+ //#endregion
233
+ //#region src/end-measurement-from/end-measurement-from.ts
234
+ const NS_PER_SEC = 1e9;
235
+ function endMeasurementFrom(start) {
236
+ const [seconds, nanoseconds] = process.hrtime(start);
237
+ return { durationS: (seconds * NS_PER_SEC + nanoseconds) / NS_PER_SEC };
238
+ }
239
+ //#endregion
240
+ //#region src/sort-labels/sort-labels.ts
241
+ function sortLabels(unsortedLabels) {
242
+ return Object.keys(unsortedLabels).toSorted((a, b) => {
243
+ if (a < b) return -1;
244
+ if (a > b) return 1;
245
+ return 0;
246
+ }).reduce((sortedLabels, labelName) => {
247
+ sortedLabels[labelName] = unsortedLabels[labelName];
248
+ return sortedLabels;
249
+ }, {});
250
+ }
251
+ //#endregion
252
+ //#region src/create-request-recorder/create-request-recorder.ts
253
+ const defaultOptions = { detectKubernetes: false };
254
+ function isTiming(timing) {
255
+ return !Array.isArray(timing);
256
+ }
257
+ const createRequestRecorder = (metrics, options = defaultOptions) => {
258
+ const shouldSkipMetricsByEnvironment = skipMetricsInEnvironment(merge(defaultOptions, options));
259
+ return (timing, recordingOptions) => {
260
+ const durationS = isTiming(timing) ? timing.end().value().seconds : endMeasurementFrom(timing).durationS;
261
+ const labels = sortLabels(recordingOptions.labels);
262
+ if (!shouldSkipMetricsByEnvironment && durationS !== void 0) {
263
+ if (metrics.httpRequestDurationInSeconds) for (const httpRequestDurationInSecondsMetricType of metrics.httpRequestDurationInSeconds) httpRequestDurationInSecondsMetricType.observe(labels, durationS);
264
+ }
265
+ if (!shouldSkipMetricsByEnvironment && durationS !== void 0) {
266
+ if (metrics.httpRequestDurationPerPercentileInSeconds) for (const httpRequestDurationPerPercentileInSecondsMetricType of metrics.httpRequestDurationPerPercentileInSeconds) httpRequestDurationPerPercentileInSecondsMetricType.observe(labels, durationS);
267
+ }
268
+ if (!shouldSkipMetricsByEnvironment && durationS !== void 0) {
269
+ if (metrics.httpRequestsTotal) for (const httpRequestsTotalMetricType of metrics.httpRequestsTotal) httpRequestsTotalMetricType.inc(labels);
270
+ }
271
+ if (recordingOptions.requestContentLength) {
272
+ if (metrics.httpRequestContentLengthInBytes) for (const httpRequestContentLengthInBytesMetricType of metrics.httpRequestContentLengthInBytes) httpRequestContentLengthInBytesMetricType.observe(labels, recordingOptions.requestContentLength);
273
+ }
274
+ if (recordingOptions.responseContentLength) {
275
+ if (metrics.httpResponseContentLengthInBytes) for (const httpResponseContentLengthInBytesMetricType of metrics.httpResponseContentLengthInBytes) httpResponseContentLengthInBytesMetricType.observe(labels, recordingOptions.responseContentLength);
276
+ }
277
+ };
278
+ };
279
+ createRequestRecorder.defaultOptions = defaultOptions;
280
+ //#endregion
281
+ //#region src/normalizers/method/method.ts
282
+ const normalizeMethod = (method) => method.toLowerCase();
283
+ //#endregion
284
+ //#region src/normalizers/path/path.ts
285
+ const urlValueParser = new UrlValueParser();
286
+ const normalizePath = (path) => {
287
+ const parsedPathname = url.parse(path).pathname;
288
+ if (!parsedPathname) return "";
289
+ return urlValueParser.replacePathValues(parsedPathname, "#val");
290
+ };
291
+ //#endregion
292
+ //#region src/normalizers/status-code/status-code.ts
293
+ const normalizeStatusCode = (statusCode) => statusCode;
294
+ //#endregion
295
+ //#region src/normalizers/index.ts
296
+ const defaultNormalizers = {
297
+ normalizeStatusCode,
298
+ normalizePath,
299
+ normalizeMethod
300
+ };
301
+ //#endregion
302
+ //#region src/summary/summary.ts
303
+ const getSummary = async () => defaultRegister.metrics();
304
+ const getContentType = () => defaultRegister.contentType;
305
+ //#endregion
306
+ //#region src/timing/timing.ts
307
+ var Timing = class Timing {
308
+ static NS_PER_SEC = BigInt(1e9);
309
+ #startTime;
310
+ #endTime;
311
+ constructor() {
312
+ this.reset();
313
+ }
314
+ value() {
315
+ const startTime = this.#startTime;
316
+ const endTime = this.#endTime;
317
+ if (!endTime || !startTime) return { seconds: void 0 };
318
+ return { seconds: Number(endTime - startTime) / Number(Timing.NS_PER_SEC) };
319
+ }
320
+ reset() {
321
+ this.#startTime = process.hrtime.bigint();
322
+ this.#endTime = void 0;
323
+ return this;
324
+ }
325
+ end() {
326
+ this.#endTime = process.hrtime.bigint();
327
+ return this;
328
+ }
329
+ };
330
+ const timing = { start() {
331
+ return new Timing();
332
+ } };
333
+ //#endregion
334
+ export { Prometheus, createGcMetrics, createGcObserver, createGraphQlMetrics, createHttpMetrics, createRequestRecorder, defaultNormalizers, defaultRegister, endMeasurementFrom, getContentType, getSummary, isRunningInKubernetes, normalizeMethod, normalizePath, normalizeStatusCode, skipMetricsInEnvironment, sortLabels, timing };
335
+
336
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":["asArray","defaultOptions","getMetrics","defaultOptions","defaultLabels","asArray","defaultOptions","getMetrics","defaultOptions","#startTime","#endTime"],"sources":["../src/environment/kubernetes.ts","../src/environment/skip-metrics-in-environment.ts","../src/client/client.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 { TDefaultedPromsterOptions, TGcMetrics } from '@promster/types';\nimport merge from 'merge-options';\n\nimport { configure, Prometheus } from '../client';\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(\n (nameOfUpMetric: string) =>\n new Prometheus.Gauge({\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, Prometheus } from '../client';\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 new Prometheus.Histogram({\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 new Prometheus.Histogram({\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 new Prometheus.Histogram({\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 new Prometheus.Histogram({\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 new Prometheus.Counter({\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, Prometheus } from '../client';\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 new Prometheus.Histogram({\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 new Prometheus.Histogram({\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(\n (nameOfHttpRequestDurationPerPercentileInSeconds: string) =>\n new Prometheus.Summary({\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 new Prometheus.Histogram({\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 new Prometheus.Counter({\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,8BACJ,QAAQ,QAAQ,IAAI,uBAAuB;;;ACO7C,MAAM,4BAA4B,YAChC,QAAQ,qBAAqB,QAAQ,CAAC,sBAAsB;;;ACA9D,MAAM,kBAAkB,WAAW;AAOnC,MAAM,YAAY,MAAM,YAA4B;CAGlD,IAAI,CAFmC,yBAAyB,OAE9B,GAChC,WAAW,sBAAsB,OAAO;AAE5C,CAAC;;;ACjBD,MAAMA,aAAW,eACf,MAAM,QAAQ,UAAU,IAAI,aAAa,CAAC,UAAU;AAEtD,MAAMC,mBAAiB;CACrB,uBAAuB,CAAC;CACxB,QAAQ,CAAC;CACT,cAAc;CACd,aAAa,EACX,IAAI,CAAC,WAAW,EAClB;CACA,sBAAsB;AACxB;AAEA,MAAMC,gBAAc,aAAwC,EAC1D,IAAIF,UAAQ,QAAQ,YAAY,EAAE,CAAC,CAAC,KACjC,mBACC,IAAI,WAAW,MAAM;CACnB,MAAM,GAAG,QAAQ,eAAe;CAChC,MAAM;AACR,CAAC,CACL,EACF;AAEA,MAAM,mBAAmB,YAAmD;CAC1E,MAAM,mBAA8C,MAClDC,kBACA,OACF;CAEA,UAAU,EACR,QAAQ,iBAAiB,aAC3B,CAAC;CAID,OAFkBC,aAAW,gBAEd;AACjB;AAEA,gBAAgB,iBAAiBD;;;ACrCjC,MAAME,mBAAiB,EACrB,kBAAkB,MACpB;AAEA,MAAM,mBAAmB,MACtB,UAAsB,kBAA6C;CAClE,QAAQ,iBAAiB;EACvB,oBAAoB,QAAQ;EAC5B,QAAQ,QAAQ;CAClB,CAAC;AACH,CACF;AAGA,iBAAiB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{
2
2
  "name": "@promster/metrics",
3
- "version": "15.5.0",
3
+ "version": "15.5.2",
4
4
  "description": "Metrics utilities used by all other server integrations",
5
5
  "keywords": [
6
6
  "continousdelivery",
@@ -22,29 +22,42 @@
22
22
  "readme.md",
23
23
  "package.json",
24
24
  "LICENSE",
25
- "dist/**",
26
- "modules/**"
25
+ "dist/**"
27
26
  ],
28
- "main": "dist/promster-metrics.cjs.js",
29
- "types": "dist/promster-metrics.cjs.d.ts",
30
- "typings": "dist/promster-metrics.cjs.d.ts",
27
+ "type": "module",
28
+ "sideEffects": false,
29
+ "main": "./dist/index.js",
30
+ "types": "./dist/index.d.ts",
31
+ "exports": {
32
+ ".": {
33
+ "import": {
34
+ "types": "./dist/index.d.ts",
35
+ "default": "./dist/index.js"
36
+ },
37
+ "require": {
38
+ "types": "./dist/index.d.cts",
39
+ "default": "./dist/index.cjs"
40
+ }
41
+ }
42
+ },
31
43
  "publishConfig": {
32
44
  "access": "public"
33
45
  },
34
46
  "dependencies": {
35
47
  "@chainsafe/prometheus-gc-stats": "1.0.2",
36
- "lodash.memoize": "4.1.2",
37
- "lodash.once": "4.1.1",
48
+ "es-toolkit": "1.46.1",
38
49
  "merge-options": "3.0.4",
39
50
  "tslib": "2.8.1",
40
51
  "url-value-parser": "2.2.0"
41
52
  },
42
53
  "devDependencies": {
43
- "@types/lodash.once": "4.1.9",
44
54
  "@types/node": "24.12.2",
45
55
  "prom-client": "15.1.3",
56
+ "tsdown": "0.22.2",
46
57
  "typescript": "6.0.3",
47
- "@promster/types": "15.5.0"
58
+ "@promster/tsconfig": "15.5.2",
59
+ "@promster/tsdown-config": "15.5.2",
60
+ "@promster/types": "15.5.2"
48
61
  },
49
62
  "peerDependencies": {
50
63
  "prom-client": "13.x.x || 14.x || 15.x"
@@ -52,5 +65,12 @@
52
65
  "engines": {
53
66
  "node": ">=20",
54
67
  "npm": ">=8"
68
+ },
69
+ "scripts": {
70
+ "build": "tsdown",
71
+ "check-types": "tsc --noEmit",
72
+ "test": "vitest --run",
73
+ "test:watch": "vitest",
74
+ "dev": "tsdown --watch"
55
75
  }
56
76
  }
@@ -1,9 +0,0 @@
1
- import type { PrometheusContentType } from 'prom-client';
2
- import * as Prometheus from 'prom-client';
3
- declare const defaultRegister: Prometheus.Registry<"text/plain; version=0.0.4; charset=utf-8">;
4
- interface TClientOptions extends Prometheus.DefaultMetricsCollectorConfiguration<PrometheusContentType> {
5
- detectKubernetes?: boolean;
6
- prefix?: string;
7
- }
8
- declare const configure: (options: TClientOptions) => void;
9
- export { Prometheus, defaultRegister, configure };
@@ -1,2 +0,0 @@
1
- import { configure, defaultRegister, Prometheus } from "./client.js";
2
- export { Prometheus, defaultRegister, configure };
@@ -1,14 +0,0 @@
1
- import type { TDefaultedPromsterOptions, TGcMetrics } from '@promster/types';
2
- declare const createGcMetrics: {
3
- (options: TDefaultedPromsterOptions): TGcMetrics;
4
- defaultOptions: {
5
- getLabelValues: () => {};
6
- labels: never[];
7
- metricPrefix: string;
8
- metricNames: {
9
- up: string[];
10
- };
11
- gcCollectionInterval: number;
12
- };
13
- };
14
- export { createGcMetrics };
@@ -1,2 +0,0 @@
1
- import { createGcMetrics } from "./create-gc-metrics.js";
2
- export { createGcMetrics };
@@ -1,3 +0,0 @@
1
- import type { TDefaultedPromsterOptions, TGcMetrics } from '@promster/types';
2
- declare const createGcObserver: (_metrics: TGcMetrics, options: TDefaultedPromsterOptions) => () => void;
3
- export { createGcObserver };