axios-prometheus-adapter 0.0.6 → 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ export { AxiosPrometheusAdapterConfig, createAxiosPrometheusMiddleware } from './lib/AxiosPrometheusAdapter';
package/dist/index.js ADDED
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createAxiosPrometheusMiddleware = void 0;
4
+ var AxiosPrometheusAdapter_1 = require("./lib/AxiosPrometheusAdapter");
5
+ Object.defineProperty(exports, "createAxiosPrometheusMiddleware", { enumerable: true, get: function () { return AxiosPrometheusAdapter_1.createAxiosPrometheusMiddleware; } });
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;AAAA,uEAA6G;AAAtE,yIAAA,+BAA+B,OAAA"}
@@ -0,0 +1,8 @@
1
+ import type { AxiosInstance } from 'axios';
2
+ import type { Registry } from 'prom-client';
3
+ export type AxiosPrometheusAdapterConfig = {
4
+ name: string;
5
+ help: string;
6
+ labelNames: string[];
7
+ };
8
+ export declare const createAxiosPrometheusMiddleware: (axiosInstance: AxiosInstance, registry: Registry, config?: AxiosPrometheusAdapterConfig) => void;
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.createAxiosPrometheusMiddleware = void 0;
7
+ const prom_client_1 = __importDefault(require("prom-client"));
8
+ const createAxiosPrometheusMiddleware = (axiosInstance, registry, config) => {
9
+ const clientRequestDuration = new prom_client_1.default.Histogram({
10
+ name: 'http_client_requests_seconds',
11
+ help: 'Outgoing requests metrics',
12
+ labelNames: ['status_code', 'method', 'protocol', 'host', 'path'],
13
+ ...config,
14
+ });
15
+ registry.registerMetric(clientRequestDuration);
16
+ axiosInstance.interceptors.request.use((config) => {
17
+ const end = clientRequestDuration.startTimer();
18
+ config.metadata = {
19
+ endTimer: end,
20
+ };
21
+ return config;
22
+ });
23
+ axiosInstance.interceptors.response.use((response) => {
24
+ const labels = {
25
+ status_code: response.status,
26
+ method: response.request.method,
27
+ protocol: response.request.protocol,
28
+ host: response.request.host,
29
+ path: response.request.path.split('?')[0],
30
+ };
31
+ response.config.metadata.endTimer(labels);
32
+ return response;
33
+ }, error => {
34
+ let labels;
35
+ if (error.response) {
36
+ labels = {
37
+ status_code: error.response.status,
38
+ method: error.response.request.method,
39
+ protocol: error.response.request.protocol,
40
+ host: error.response.request.host,
41
+ path: error.response.request.path.split('?')[0],
42
+ };
43
+ }
44
+ else if (error.request._currentRequest) {
45
+ labels = {
46
+ status_code: error.status,
47
+ method: error.request._currentRequest.method,
48
+ protocol: error.request._currentRequest.protocol,
49
+ host: error.request._currentRequest.host,
50
+ path: error.request._currentRequest.path.split('?')[0],
51
+ };
52
+ }
53
+ else {
54
+ labels = {
55
+ status_code: 500,
56
+ method: "UNKNOWN",
57
+ protocol: "UNKNOWN",
58
+ host: "UNKNOWN",
59
+ path: "UNKNOWN",
60
+ };
61
+ }
62
+ error.config.metadata.endTimer(labels);
63
+ return Promise.reject(error);
64
+ });
65
+ };
66
+ exports.createAxiosPrometheusMiddleware = createAxiosPrometheusMiddleware;
67
+ //# sourceMappingURL=AxiosPrometheusAdapter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AxiosPrometheusAdapter.js","sourceRoot":"","sources":["../../lib/AxiosPrometheusAdapter.ts"],"names":[],"mappings":";;;;;;AAEA,8DAAiC;AAQ1B,MAAM,+BAA+B,GAAG,CAC7C,aAA4B,EAC5B,QAAkB,EAClB,MAAqC,EAC/B,EAAE;IACR,MAAM,qBAAqB,GAAG,IAAI,qBAAM,CAAC,SAAS,CAAC;QACjD,IAAI,EAAE,8BAA8B;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CAAC,QAAQ;gBACzC,IAAI,EAAE,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI;gBACjC,IAAI,EAAE,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;aAChD,CAAC;SACH;aAAM,IAAI,KAAK,CAAC,OAAO,CAAC,eAAe,EAAE;YACxC,MAAM,GAAG;gBACP,WAAW,EAAE,KAAK,CAAC,MAAM;gBACzB,MAAM,EAAE,KAAK,CAAC,OAAO,CAAC,eAAe,CAAC,MAAM;gBAC5C,QAAQ,EAAE,KAAK,CAAC,OAAO,CAAC,eAAe,CAAC,QAAQ;gBAChD,IAAI,EAAE,KAAK,CAAC,OAAO,CAAC,eAAe,CAAC,IAAI;gBACxC,IAAI,EAAE,KAAK,CAAC,OAAO,CAAC,eAAe,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;aACvD,CAAC;SACH;aAAM;YACL,MAAM,GAAG;gBACP,WAAW,EAAE,GAAG;gBAChB,MAAM,EAAE,SAAS;gBACjB,QAAQ,EAAE,SAAS;gBACnB,IAAI,EAAE,SAAS;gBACf,IAAI,EAAE,SAAS;aAChB,CAAC;SACH;QACD,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;QACvC,OAAO,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAC/B,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AA/DW,QAAA,+BAA+B,mCA+D1C"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "axios-prometheus-adapter",
3
- "version": "0.0.6",
3
+ "version": "0.0.7",
4
4
  "description": "Provides prometheus metrics for outgoing axios requests",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",