Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@promster/metrics

Package Overview
Dependencies
Maintainers
1
Versions
79
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@promster/metrics - npm Package Compare versions

Comparing version 9.1.5 to 9.1.6

8

dist/declarations/src/create-request-recorder/create-request-recorder.d.ts
import type { TPromsterOptions, TLabelValues, THttpMetrics } from '@promster/types';
import type { Timing } from '../timing';
import { sortLabels } from '../sort-labels';
import { endMeasurementFrom } from '../end-measurement-from';
import { Timing } from '../timing';
declare type TRecordingOptions = {
type TRecordingOptions = {
labels: TLabelValues;

@@ -10,4 +10,4 @@ requestContentLength?: number;

};
declare type TLegacyTiming = [number, number];
export declare type TRequestRecorder = (timing: Timing | TLegacyTiming, recordingOptions: TRecordingOptions) => void;
type TLegacyTiming = [number, number];
export type TRequestRecorder = (timing: Timing | TLegacyTiming, recordingOptions: TRecordingOptions) => void;
declare const createRequestRecorder: {

@@ -14,0 +14,0 @@ (metrics: THttpMetrics, options?: TPromsterOptions): TRequestRecorder;

import type { TPromsterOptions } from '@promster/types';
declare type TSkipMetricsInEnvironmentOptions = {
type TSkipMetricsInEnvironmentOptions = {
detectKubernetes?: TPromsterOptions['detectKubernetes'];

@@ -4,0 +4,0 @@ };

@@ -43,9 +43,11 @@ 'use strict';

// NOTE:
// This is the `globalRegistry` provided by the `prom-client`
// We could create multiple registries with `new Prometheus.registry()`.
const defaultRegister = Prometheus__namespace.register;
const defaultRegister = Prometheus__namespace.register;
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
const configure = once__default["default"](options => {
const shouldSkipMetricsInEnvironment = skipMetricsInEnvironment(options);
if (!shouldSkipMetricsInEnvironment) {

@@ -60,13 +62,7 @@ Prometheus__namespace.collectDefaultMetrics(options);

const defaultLabels$2 = ['path', 'status_code', 'method'];
const asArray$2 = maybeArray => Array.isArray(maybeArray) ? maybeArray : [maybeArray];
const shouldObserveHttpRequestsAsSummary = options => options.metricTypes.includes('httpRequestsSummary');
const shouldObserveHttpRequestsAsHistogram = options => options.metricTypes.includes('httpRequestsHistogram');
const shouldObserveHttpRequestsAsCounter = options => options.metricTypes.includes('httpRequestsTotal');
const shouldObserveHttpContentLengthAsHistogram = options => options.metricTypes.includes('httpContentLengthHistogram');
const defaultOptions$4 = {

@@ -85,3 +81,2 @@ getLabelValues: () => ({}),

};
const getMetrics$2 = options => ({

@@ -101,3 +96,2 @@ httpRequestContentLengthInBytes: shouldObserveHttpContentLengthAsHistogram(options) ? asArray$2(options.metricNames.httpRequestContentLengthInBytes).map(nameOfHttpContentLengthMetric => new Prometheus__namespace.Histogram({

});
const getHttpRequestLatencyMetricsInSeconds = options => ({

@@ -117,3 +111,2 @@ httpRequestDurationPerPercentileInSeconds: shouldObserveHttpRequestsAsSummary(options) ? asArray$2(options.metricNames.httpRequestDurationPerPercentileInSeconds).map(nameOfHttpRequestDurationPerPercentileInSeconds => new Prometheus__namespace.Summary({

});
const getHttpRequestCounterMetric = options => ({

@@ -126,3 +119,2 @@ httpRequestsTotal: shouldObserveHttpRequestsAsCounter(options) ? asArray$2(options.metricNames.httpRequestsTotal).map(nameOfHttpRequestsTotalMetric => new Prometheus__namespace.Counter({

});
const createHttpMetrics = options => {

@@ -138,3 +130,2 @@ const defaultedOptions = merge__default["default"](defaultOptions$4, options);

};
createHttpMetrics.defaultOptions = defaultOptions$4;

@@ -144,15 +135,8 @@

const defaultLabels$1 = ['operation_name'];
const asArray$1 = maybeArray => Array.isArray(maybeArray) ? maybeArray : [maybeArray];
const shouldObserveGraphQlParseDurationAsHistogram = options => options.metricTypes.includes('graphQlParseDurationHistogram');
const shouldObserveGraphQlValidationDurationAsHistogram = options => options.metricTypes.includes('graphQlValidationDurationHistogram');
const shouldObserveGraphQlResolveFieldDurationAsHistogram = options => options.metricTypes.includes('graphQlResolveFieldDurationHistogram');
const shouldObserveGraphQlRequestDurationAsHistogram = options => options.metricTypes.includes('graphQlRequestDurationHistogram');
const shouldObserveGraphQlErrorsTotalAsCounter = options => options.metricTypes.includes('graphQlErrorsTotal');
const defaultOptions$3 = {

@@ -171,3 +155,2 @@ getLabelValues: () => ({}),

};
const getMetrics$1 = options => ({

@@ -204,3 +187,2 @@ graphQlParseDuration: shouldObserveGraphQlParseDurationAsHistogram(options) ? asArray$1(options.metricNames.graphQlParseDuration).map(nameOfGraphQlParseDuration => new Prometheus__namespace.Histogram({

});
const createGraphQlMetrics = options => {

@@ -214,9 +196,6 @@ const defaultedOptions = merge__default["default"](defaultOptions$3, options);

};
createGraphQlMetrics.defaultOptions = defaultOptions$3;
const defaultLabels = ['gc_type'];
const asArray = maybeArray => Array.isArray(maybeArray) ? maybeArray : [maybeArray];
const defaultOptions$2 = {

@@ -233,3 +212,2 @@ getLabelValues: () => ({}),

};
const getMetrics = options => ({

@@ -256,3 +234,2 @@ up: asArray(options.metricNames.up).map(nameOfUpMetric => new Prometheus__namespace.Gauge({

});
const createGcMetrics = options => {

@@ -266,7 +243,5 @@ const defaultedOptions = merge__default["default"](defaultOptions$2, options);

};
createGcMetrics.defaultOptions = defaultOptions$2;
const getSummary = async () => defaultRegister.metrics();
const getContentType = () => defaultRegister.contentType;

@@ -279,7 +254,5 @@

}
if (a > b) {
return 1;
}
return 0;

@@ -293,3 +266,2 @@ }).reduce((sortedLabels, labelName) => {

const NS_PER_SEC = 1e9;
function endMeasurementFrom(start) {

@@ -306,7 +278,5 @@ const [seconds, nanoseconds] = process.hrtime(start);

};
function isTiming(timing) {
return !Array.isArray(timing);
}
const createRequestRecorder = (metrics, options = defaultOptions$1) => {

@@ -318,6 +288,4 @@ const defaultedRecorderOptions = merge__default["default"](defaultOptions$1, options);

const labels = sortLabels(recordingOptions.labels);
if (!shouldSkipMetricsByEnvironment && durationS !== undefined) {
var _metrics$httpRequestD;
(_metrics$httpRequestD = metrics.httpRequestDurationInSeconds) === null || _metrics$httpRequestD === void 0 ? void 0 : _metrics$httpRequestD.forEach(httpRequestDurationInSecondsMetricType => {

@@ -327,6 +295,4 @@ httpRequestDurationInSecondsMetricType.observe(labels, durationS);

}
if (!shouldSkipMetricsByEnvironment && durationS !== undefined) {
var _metrics$httpRequestD2;
(_metrics$httpRequestD2 = metrics.httpRequestDurationPerPercentileInSeconds) === null || _metrics$httpRequestD2 === void 0 ? void 0 : _metrics$httpRequestD2.forEach(httpRequestDurationPerPercentileInSecondsMetricType => {

@@ -336,6 +302,4 @@ httpRequestDurationPerPercentileInSecondsMetricType.observe(labels, durationS);

}
if (!shouldSkipMetricsByEnvironment && durationS !== undefined) {
var _metrics$httpRequests;
(_metrics$httpRequests = metrics.httpRequestsTotal) === null || _metrics$httpRequests === void 0 ? void 0 : _metrics$httpRequests.forEach(httpRequestsTotalMetricType => {

@@ -345,17 +309,15 @@ httpRequestsTotalMetricType.inc(labels);

}
if (recordingOptions.requestContentLength) {
var _metrics$httpRequestC;
(_metrics$httpRequestC = metrics.httpRequestContentLengthInBytes) === null || _metrics$httpRequestC === void 0 ? void 0 : _metrics$httpRequestC.forEach(httpRequestContentLengthInBytesMetricType => {
httpRequestContentLengthInBytesMetricType.observe(labels, // @ts-expect-error
httpRequestContentLengthInBytesMetricType.observe(labels,
// @ts-expect-error
recordingOptions.requestContentLength);
});
}
if (recordingOptions.responseContentLength) {
var _metrics$httpResponse;
(_metrics$httpResponse = metrics.httpResponseContentLengthInBytes) === null || _metrics$httpResponse === void 0 ? void 0 : _metrics$httpResponse.forEach(httpResponseContentLengthInBytesMetricType => {
httpResponseContentLengthInBytesMetricType.observe(labels, // @ts-expect-error
httpResponseContentLengthInBytesMetricType.observe(labels,
// @ts-expect-error
recordingOptions.responseContentLength);

@@ -366,3 +328,2 @@ });

};
createRequestRecorder.defaultOptions = defaultOptions$1;

@@ -387,3 +348,2 @@

}
if (options.disableGcMetrics) return;

@@ -398,3 +358,2 @@ gc().on('stats', stats => {

});
if (stats.diff.usedHeapSize < 0) {

@@ -412,3 +371,2 @@ metrics.reclaimedInGc.forEach(reclaimedInGcMetricType => {

const urlValueParser = new UrlValueParser__default["default"]();
const normalizePath = path => urlValueParser.replacePathValues(url__default["default"].parse(path).pathname, '#val');

@@ -428,7 +386,5 @@

#endTime;
constructor() {
this.reset();
}
value() {

@@ -444,3 +400,2 @@ const startTime = this.#startTime;

}
reset() {

@@ -451,3 +406,2 @@ this.#startTime = process.hrtime.bigint();

}
end() {

@@ -457,5 +411,3 @@ this.#endTime = process.hrtime.bigint();

}
}
const timing = {

@@ -465,3 +417,2 @@ start() {

}
};

@@ -468,0 +419,0 @@

@@ -43,9 +43,11 @@ 'use strict';

// NOTE:
// This is the `globalRegistry` provided by the `prom-client`
// We could create multiple registries with `new Prometheus.registry()`.
const defaultRegister = Prometheus__namespace.register;
const defaultRegister = Prometheus__namespace.register;
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
const configure = once__default["default"](options => {
const shouldSkipMetricsInEnvironment = skipMetricsInEnvironment(options);
if (!shouldSkipMetricsInEnvironment) {

@@ -60,13 +62,7 @@ Prometheus__namespace.collectDefaultMetrics(options);

const defaultLabels$2 = ['path', 'status_code', 'method'];
const asArray$2 = maybeArray => Array.isArray(maybeArray) ? maybeArray : [maybeArray];
const shouldObserveHttpRequestsAsSummary = options => options.metricTypes.includes('httpRequestsSummary');
const shouldObserveHttpRequestsAsHistogram = options => options.metricTypes.includes('httpRequestsHistogram');
const shouldObserveHttpRequestsAsCounter = options => options.metricTypes.includes('httpRequestsTotal');
const shouldObserveHttpContentLengthAsHistogram = options => options.metricTypes.includes('httpContentLengthHistogram');
const defaultOptions$4 = {

@@ -85,3 +81,2 @@ getLabelValues: () => ({}),

};
const getMetrics$2 = options => ({

@@ -101,3 +96,2 @@ httpRequestContentLengthInBytes: shouldObserveHttpContentLengthAsHistogram(options) ? asArray$2(options.metricNames.httpRequestContentLengthInBytes).map(nameOfHttpContentLengthMetric => new Prometheus__namespace.Histogram({

});
const getHttpRequestLatencyMetricsInSeconds = options => ({

@@ -117,3 +111,2 @@ httpRequestDurationPerPercentileInSeconds: shouldObserveHttpRequestsAsSummary(options) ? asArray$2(options.metricNames.httpRequestDurationPerPercentileInSeconds).map(nameOfHttpRequestDurationPerPercentileInSeconds => new Prometheus__namespace.Summary({

});
const getHttpRequestCounterMetric = options => ({

@@ -126,3 +119,2 @@ httpRequestsTotal: shouldObserveHttpRequestsAsCounter(options) ? asArray$2(options.metricNames.httpRequestsTotal).map(nameOfHttpRequestsTotalMetric => new Prometheus__namespace.Counter({

});
const createHttpMetrics = options => {

@@ -138,3 +130,2 @@ const defaultedOptions = merge__default["default"](defaultOptions$4, options);

};
createHttpMetrics.defaultOptions = defaultOptions$4;

@@ -144,15 +135,8 @@

const defaultLabels$1 = ['operation_name'];
const asArray$1 = maybeArray => Array.isArray(maybeArray) ? maybeArray : [maybeArray];
const shouldObserveGraphQlParseDurationAsHistogram = options => options.metricTypes.includes('graphQlParseDurationHistogram');
const shouldObserveGraphQlValidationDurationAsHistogram = options => options.metricTypes.includes('graphQlValidationDurationHistogram');
const shouldObserveGraphQlResolveFieldDurationAsHistogram = options => options.metricTypes.includes('graphQlResolveFieldDurationHistogram');
const shouldObserveGraphQlRequestDurationAsHistogram = options => options.metricTypes.includes('graphQlRequestDurationHistogram');
const shouldObserveGraphQlErrorsTotalAsCounter = options => options.metricTypes.includes('graphQlErrorsTotal');
const defaultOptions$3 = {

@@ -171,3 +155,2 @@ getLabelValues: () => ({}),

};
const getMetrics$1 = options => ({

@@ -204,3 +187,2 @@ graphQlParseDuration: shouldObserveGraphQlParseDurationAsHistogram(options) ? asArray$1(options.metricNames.graphQlParseDuration).map(nameOfGraphQlParseDuration => new Prometheus__namespace.Histogram({

});
const createGraphQlMetrics = options => {

@@ -214,9 +196,6 @@ const defaultedOptions = merge__default["default"](defaultOptions$3, options);

};
createGraphQlMetrics.defaultOptions = defaultOptions$3;
const defaultLabels = ['gc_type'];
const asArray = maybeArray => Array.isArray(maybeArray) ? maybeArray : [maybeArray];
const defaultOptions$2 = {

@@ -233,3 +212,2 @@ getLabelValues: () => ({}),

};
const getMetrics = options => ({

@@ -256,3 +234,2 @@ up: asArray(options.metricNames.up).map(nameOfUpMetric => new Prometheus__namespace.Gauge({

});
const createGcMetrics = options => {

@@ -266,7 +243,5 @@ const defaultedOptions = merge__default["default"](defaultOptions$2, options);

};
createGcMetrics.defaultOptions = defaultOptions$2;
const getSummary = async () => defaultRegister.metrics();
const getContentType = () => defaultRegister.contentType;

@@ -279,7 +254,5 @@

}
if (a > b) {
return 1;
}
return 0;

@@ -293,3 +266,2 @@ }).reduce((sortedLabels, labelName) => {

const NS_PER_SEC = 1e9;
function endMeasurementFrom(start) {

@@ -306,7 +278,5 @@ const [seconds, nanoseconds] = process.hrtime(start);

};
function isTiming(timing) {
return !Array.isArray(timing);
}
const createRequestRecorder = (metrics, options = defaultOptions$1) => {

@@ -318,6 +288,4 @@ const defaultedRecorderOptions = merge__default["default"](defaultOptions$1, options);

const labels = sortLabels(recordingOptions.labels);
if (!shouldSkipMetricsByEnvironment && durationS !== undefined) {
var _metrics$httpRequestD;
(_metrics$httpRequestD = metrics.httpRequestDurationInSeconds) === null || _metrics$httpRequestD === void 0 ? void 0 : _metrics$httpRequestD.forEach(httpRequestDurationInSecondsMetricType => {

@@ -327,6 +295,4 @@ httpRequestDurationInSecondsMetricType.observe(labels, durationS);

}
if (!shouldSkipMetricsByEnvironment && durationS !== undefined) {
var _metrics$httpRequestD2;
(_metrics$httpRequestD2 = metrics.httpRequestDurationPerPercentileInSeconds) === null || _metrics$httpRequestD2 === void 0 ? void 0 : _metrics$httpRequestD2.forEach(httpRequestDurationPerPercentileInSecondsMetricType => {

@@ -336,6 +302,4 @@ httpRequestDurationPerPercentileInSecondsMetricType.observe(labels, durationS);

}
if (!shouldSkipMetricsByEnvironment && durationS !== undefined) {
var _metrics$httpRequests;
(_metrics$httpRequests = metrics.httpRequestsTotal) === null || _metrics$httpRequests === void 0 ? void 0 : _metrics$httpRequests.forEach(httpRequestsTotalMetricType => {

@@ -345,17 +309,15 @@ httpRequestsTotalMetricType.inc(labels);

}
if (recordingOptions.requestContentLength) {
var _metrics$httpRequestC;
(_metrics$httpRequestC = metrics.httpRequestContentLengthInBytes) === null || _metrics$httpRequestC === void 0 ? void 0 : _metrics$httpRequestC.forEach(httpRequestContentLengthInBytesMetricType => {
httpRequestContentLengthInBytesMetricType.observe(labels, // @ts-expect-error
httpRequestContentLengthInBytesMetricType.observe(labels,
// @ts-expect-error
recordingOptions.requestContentLength);
});
}
if (recordingOptions.responseContentLength) {
var _metrics$httpResponse;
(_metrics$httpResponse = metrics.httpResponseContentLengthInBytes) === null || _metrics$httpResponse === void 0 ? void 0 : _metrics$httpResponse.forEach(httpResponseContentLengthInBytesMetricType => {
httpResponseContentLengthInBytesMetricType.observe(labels, // @ts-expect-error
httpResponseContentLengthInBytesMetricType.observe(labels,
// @ts-expect-error
recordingOptions.responseContentLength);

@@ -366,3 +328,2 @@ });

};
createRequestRecorder.defaultOptions = defaultOptions$1;

@@ -387,3 +348,2 @@

}
if (options.disableGcMetrics) return;

@@ -398,3 +358,2 @@ gc().on('stats', stats => {

});
if (stats.diff.usedHeapSize < 0) {

@@ -412,3 +371,2 @@ metrics.reclaimedInGc.forEach(reclaimedInGcMetricType => {

const urlValueParser = new UrlValueParser__default["default"]();
const normalizePath = path => urlValueParser.replacePathValues(url__default["default"].parse(path).pathname, '#val');

@@ -428,7 +386,5 @@

#endTime;
constructor() {
this.reset();
}
value() {

@@ -444,3 +400,2 @@ const startTime = this.#startTime;

}
reset() {

@@ -451,3 +406,2 @@ this.#startTime = process.hrtime.bigint();

}
end() {

@@ -457,5 +411,3 @@ this.#endTime = process.hrtime.bigint();

}
}
const timing = {

@@ -465,3 +417,2 @@ start() {

}
};

@@ -468,0 +419,0 @@

{
"name": "@promster/metrics",
"version": "9.1.5",
"version": "9.1.6",
"description": "Metrics utilities used by all other server integrations",

@@ -43,14 +43,14 @@ "main": "dist/promster-metrics.cjs.js",

"optional": "0.1.4",
"ts-essentials": "9.1.2",
"tslib": "2.3.1",
"url-value-parser": "2.1.0"
"ts-essentials": "9.3.0",
"tslib": "2.4.1",
"url-value-parser": "2.2.0"
},
"devDependencies": {
"@promster/types": "^3.2.4",
"@types/lodash": "4.14.180",
"prom-client": "14.0.1",
"typescript": "4.6.2"
"@promster/types": "^3.2.5",
"@types/lodash": "4.14.191",
"prom-client": "14.1.0",
"typescript": "4.9.4"
},
"optionalDependencies": {
"@sematext/gc-stats": "1.5.7"
"@sematext/gc-stats": "1.5.8"
},

@@ -57,0 +57,0 @@ "peerDependencies": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc