@mondaydotcomorg/monday-authorization 3.3.1 → 3.3.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.
- package/README.md +3 -1
- package/dist/esm/index.d.ts +9 -6
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.mjs +14 -7
- package/dist/esm/metrics-service.d.ts +4 -1
- package/dist/esm/metrics-service.d.ts.map +1 -1
- package/dist/esm/metrics-service.mjs +30 -14
- package/dist/index.d.ts +9 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +14 -7
- package/dist/metrics-service.d.ts +4 -1
- package/dist/metrics-service.d.ts.map +1 -1
- package/dist/metrics-service.js +30 -14
- package/package.json +1 -1
- package/src/index.ts +24 -15
- package/src/metrics-service.ts +41 -15
package/README.md
CHANGED
|
@@ -39,7 +39,9 @@ startServer(...)
|
|
|
39
39
|
**Recommended** - optionally init authorization with redisClient so the granted feature results will be cached and reduce http calls.
|
|
40
40
|
|
|
41
41
|
- grantedFeatureRedisExpirationInSeconds - (optional), redis TTL for cached granted features, default set to 5 minutes
|
|
42
|
-
- metrics - (optional), configure internal DataDog/observability integration.
|
|
42
|
+
- metrics - (optional), configure internal DataDog/observability integration. Provide either:
|
|
43
|
+
- `metrics.client` with a pre-initialized StatsD client that exposes `distribution` and `increment`.
|
|
44
|
+
- Or the config fields (`serviceName`, `host`, `port`, `disabled`) to let the SDK initialize `@mondaydotcomorg/monday-observability-kit` for you. Defaults to `process.env.APP_NAME` as the service name, uses the standard StatsD endpoint (`localhost:8125`) when host/port are not provided, and disables emission automatically in test/development environments (override with `disabled`).
|
|
43
45
|
|
|
44
46
|
### Metrics & Observability
|
|
45
47
|
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
import { MondayFetchOptions } from '@mondaydotcomorg/monday-fetch';
|
|
2
|
+
import { MetricsClient } from './metrics-service';
|
|
2
3
|
import * as TestKit from './testKit';
|
|
4
|
+
interface MetricsInitOptions {
|
|
5
|
+
client?: MetricsClient;
|
|
6
|
+
serviceName?: string;
|
|
7
|
+
host?: string;
|
|
8
|
+
port?: number;
|
|
9
|
+
disabled?: boolean;
|
|
10
|
+
}
|
|
3
11
|
export interface InitOptions {
|
|
4
12
|
prometheus?: any;
|
|
5
13
|
mondayFetchOptions?: MondayFetchOptions;
|
|
6
14
|
redisClient?: any;
|
|
7
15
|
grantedFeatureRedisExpirationInSeconds?: number;
|
|
8
|
-
metrics?:
|
|
9
|
-
serviceName?: string;
|
|
10
|
-
host?: string;
|
|
11
|
-
port?: number;
|
|
12
|
-
disabled?: boolean;
|
|
13
|
-
};
|
|
16
|
+
metrics?: MetricsInitOptions;
|
|
14
17
|
}
|
|
15
18
|
export declare function init(options?: InitOptions): Promise<void>;
|
|
16
19
|
export { authorizationCheckMiddleware, getAuthorizationMiddleware, skipAuthorizationMiddleware, } from './authorization-middleware';
|
package/dist/esm/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AAGnE,OAAO,EAAqB,aAAa,EAAE,MAAM,mBAAmB,CAAC;AACrE,OAAO,KAAK,OAAO,MAAM,WAAW,CAAC;AAErC,UAAU,kBAAkB;IAC1B,MAAM,CAAC,EAAE,aAAa,CAAC;IACvB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,WAAW,WAAW;IAC1B,UAAU,CAAC,EAAE,GAAG,CAAC;IACjB,kBAAkB,CAAC,EAAE,kBAAkB,CAAC;IACxC,WAAW,CAAC,EAAE,GAAG,CAAC;IAClB,sCAAsC,CAAC,EAAE,MAAM,CAAC;IAChD,OAAO,CAAC,EAAE,kBAAkB,CAAC;CAC9B;AAED,wBAAsB,IAAI,CAAC,OAAO,GAAE,WAAgB,iBA6BnD;AAED,OAAO,EACL,4BAA4B,EAC5B,0BAA0B,EAC1B,2BAA2B,GAC5B,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAClF,OAAO,EAAE,8BAA8B,EAAE,MAAM,oCAAoC,CAAC;AACpF,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,mBAAmB,EAAE,QAAQ,EAAE,WAAW,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAC5G,OAAO,EACL,WAAW,EACX,YAAY,EACZ,0BAA0B,EAC1B,kBAAkB,GACnB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAErH,OAAO,EAAE,OAAO,EAAE,CAAC"}
|
package/dist/esm/index.mjs
CHANGED
|
@@ -13,13 +13,20 @@ async function init(options = {}) {
|
|
|
13
13
|
if (options.prometheus) {
|
|
14
14
|
setPrometheus(options.prometheus);
|
|
15
15
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
16
|
+
if (options.metrics) {
|
|
17
|
+
if (options.metrics.client) {
|
|
18
|
+
initializeMetrics({ client: options.metrics.client });
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
const resolvedDisabled = options.metrics.disabled ?? ['test', 'development'].includes((process.env.NODE_ENV ?? '').toLowerCase());
|
|
22
|
+
initializeMetrics({
|
|
23
|
+
serviceName: options.metrics.serviceName ?? process.env.APP_NAME ?? 'authorization-sdk',
|
|
24
|
+
host: options.metrics.host,
|
|
25
|
+
port: options.metrics.port,
|
|
26
|
+
disabled: resolvedDisabled,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
}
|
|
23
30
|
if (options.mondayFetchOptions) {
|
|
24
31
|
setRequestFetchOptions(options.mondayFetchOptions);
|
|
25
32
|
}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
import { Metric } from '@mondaydotcomorg/monday-observability-kit';
|
|
1
2
|
type ApiType = 'platform' | 'graph';
|
|
3
|
+
export type MetricsClient = Pick<typeof Metric, 'distribution' | 'increment'>;
|
|
2
4
|
interface InitializeMetricsOptions {
|
|
3
|
-
|
|
5
|
+
client?: MetricsClient;
|
|
6
|
+
serviceName?: string;
|
|
4
7
|
host?: string;
|
|
5
8
|
port?: number;
|
|
6
9
|
disabled?: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"metrics-service.d.ts","sourceRoot":"","sources":["../../src/metrics-service.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"metrics-service.d.ts","sourceRoot":"","sources":["../../src/metrics-service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AAGnE,KAAK,OAAO,GAAG,UAAU,GAAG,OAAO,CAAC;AAEpC,MAAM,MAAM,aAAa,GAAG,IAAI,CAAC,OAAO,MAAM,EAAE,cAAc,GAAG,WAAW,CAAC,CAAC;AAE9E,UAAU,wBAAwB;IAChC,MAAM,CAAC,EAAE,aAAa,CAAC;IACvB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAID,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,wBAAwB,GAAG,IAAI,CAiCzE;AAED,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,CAmBlF;AAED,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,GAAG,IAAI,CAmBnF"}
|
|
@@ -1,17 +1,21 @@
|
|
|
1
1
|
import { Metric } from '@mondaydotcomorg/monday-observability-kit';
|
|
2
2
|
import { logger } from './authorization-internal-service.mjs';
|
|
3
3
|
|
|
4
|
-
let
|
|
4
|
+
let metricsClient = null;
|
|
5
5
|
function initializeMetrics(options) {
|
|
6
|
-
if (
|
|
6
|
+
if (metricsClient) {
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
if (options.client) {
|
|
10
|
+
metricsClient = options.client;
|
|
7
11
|
return;
|
|
8
12
|
}
|
|
9
13
|
const { serviceName } = options;
|
|
10
14
|
if (!serviceName) {
|
|
11
|
-
logger.warn({ tag: '
|
|
15
|
+
logger.warn({ tag: 'monday-authorization-sdk' }, 'Metrics initialization skipped: serviceName is missing');
|
|
12
16
|
return;
|
|
13
17
|
}
|
|
14
|
-
const resolvedHost = options.host ?? process.env.
|
|
18
|
+
const resolvedHost = options.host ?? process.env.HOST_IP ?? 'localhost';
|
|
15
19
|
const envPort = process.env.DOGSTATSD_PORT ? Number(process.env.DOGSTATSD_PORT) : undefined;
|
|
16
20
|
const resolvedPort = options.port ?? (Number.isFinite(envPort ?? NaN) ? envPort : undefined) ?? 8125;
|
|
17
21
|
const resolvedDisabled = options.disabled ?? ['test', 'development'].includes((process.env.NODE_ENV ?? '').toLowerCase());
|
|
@@ -22,32 +26,44 @@ function initializeMetrics(options) {
|
|
|
22
26
|
port: resolvedPort,
|
|
23
27
|
disabled: resolvedDisabled,
|
|
24
28
|
});
|
|
25
|
-
|
|
29
|
+
metricsClient = Metric;
|
|
26
30
|
}
|
|
27
31
|
catch (error) {
|
|
28
|
-
logger.warn({ tag: '
|
|
32
|
+
logger.warn({ tag: 'monday-authorization-sdk', error }, 'Failed to initialize metrics');
|
|
29
33
|
}
|
|
30
34
|
}
|
|
31
35
|
function recordAuthorizationTiming(apiType, duration) {
|
|
32
|
-
if (!
|
|
36
|
+
if (!metricsClient) {
|
|
33
37
|
return;
|
|
34
38
|
}
|
|
35
39
|
try {
|
|
36
|
-
|
|
40
|
+
metricsClient.distribution(`authorization.authorizationCheck.${apiType}.duration`, duration);
|
|
37
41
|
}
|
|
38
|
-
catch {
|
|
39
|
-
|
|
42
|
+
catch (error) {
|
|
43
|
+
logger.warn({
|
|
44
|
+
tag: 'monday-authorization-sdk',
|
|
45
|
+
metric: 'authorizationCheckDuration',
|
|
46
|
+
apiType,
|
|
47
|
+
duration,
|
|
48
|
+
error,
|
|
49
|
+
}, 'Failed to emit authorization timing metric');
|
|
40
50
|
}
|
|
41
51
|
}
|
|
42
52
|
function recordAuthorizationError(apiType, statusCode) {
|
|
43
|
-
if (!
|
|
53
|
+
if (!metricsClient) {
|
|
44
54
|
return;
|
|
45
55
|
}
|
|
46
56
|
try {
|
|
47
|
-
|
|
57
|
+
metricsClient.increment(`authorization.authorizationCheck.${apiType}.error`, { statusCode: String(statusCode) }, 1);
|
|
48
58
|
}
|
|
49
|
-
catch {
|
|
50
|
-
|
|
59
|
+
catch (error) {
|
|
60
|
+
logger.warn({
|
|
61
|
+
tag: 'monday-authorization-sdk',
|
|
62
|
+
metric: 'authorizationCheckError',
|
|
63
|
+
apiType,
|
|
64
|
+
statusCode,
|
|
65
|
+
error,
|
|
66
|
+
}, 'Failed to emit authorization error metric');
|
|
51
67
|
}
|
|
52
68
|
}
|
|
53
69
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
import { MondayFetchOptions } from '@mondaydotcomorg/monday-fetch';
|
|
2
|
+
import { MetricsClient } from './metrics-service';
|
|
2
3
|
import * as TestKit from './testKit';
|
|
4
|
+
interface MetricsInitOptions {
|
|
5
|
+
client?: MetricsClient;
|
|
6
|
+
serviceName?: string;
|
|
7
|
+
host?: string;
|
|
8
|
+
port?: number;
|
|
9
|
+
disabled?: boolean;
|
|
10
|
+
}
|
|
3
11
|
export interface InitOptions {
|
|
4
12
|
prometheus?: any;
|
|
5
13
|
mondayFetchOptions?: MondayFetchOptions;
|
|
6
14
|
redisClient?: any;
|
|
7
15
|
grantedFeatureRedisExpirationInSeconds?: number;
|
|
8
|
-
metrics?:
|
|
9
|
-
serviceName?: string;
|
|
10
|
-
host?: string;
|
|
11
|
-
port?: number;
|
|
12
|
-
disabled?: boolean;
|
|
13
|
-
};
|
|
16
|
+
metrics?: MetricsInitOptions;
|
|
14
17
|
}
|
|
15
18
|
export declare function init(options?: InitOptions): Promise<void>;
|
|
16
19
|
export { authorizationCheckMiddleware, getAuthorizationMiddleware, skipAuthorizationMiddleware, } from './authorization-middleware';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AAGnE,OAAO,EAAqB,aAAa,EAAE,MAAM,mBAAmB,CAAC;AACrE,OAAO,KAAK,OAAO,MAAM,WAAW,CAAC;AAErC,UAAU,kBAAkB;IAC1B,MAAM,CAAC,EAAE,aAAa,CAAC;IACvB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,WAAW,WAAW;IAC1B,UAAU,CAAC,EAAE,GAAG,CAAC;IACjB,kBAAkB,CAAC,EAAE,kBAAkB,CAAC;IACxC,WAAW,CAAC,EAAE,GAAG,CAAC;IAClB,sCAAsC,CAAC,EAAE,MAAM,CAAC;IAChD,OAAO,CAAC,EAAE,kBAAkB,CAAC;CAC9B;AAED,wBAAsB,IAAI,CAAC,OAAO,GAAE,WAAgB,iBA6BnD;AAED,OAAO,EACL,4BAA4B,EAC5B,0BAA0B,EAC1B,2BAA2B,GAC5B,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAClF,OAAO,EAAE,8BAA8B,EAAE,MAAM,oCAAoC,CAAC;AACpF,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,mBAAmB,EAAE,QAAQ,EAAE,WAAW,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAC5G,OAAO,EACL,WAAW,EACX,YAAY,EACZ,0BAA0B,EAC1B,kBAAkB,GACnB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAErH,OAAO,EAAE,OAAO,EAAE,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -13,13 +13,20 @@ async function init(options = {}) {
|
|
|
13
13
|
if (options.prometheus) {
|
|
14
14
|
prometheusService.setPrometheus(options.prometheus);
|
|
15
15
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
16
|
+
if (options.metrics) {
|
|
17
|
+
if (options.metrics.client) {
|
|
18
|
+
metricsService.initializeMetrics({ client: options.metrics.client });
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
const resolvedDisabled = options.metrics.disabled ?? ['test', 'development'].includes((process.env.NODE_ENV ?? '').toLowerCase());
|
|
22
|
+
metricsService.initializeMetrics({
|
|
23
|
+
serviceName: options.metrics.serviceName ?? process.env.APP_NAME ?? 'authorization-sdk',
|
|
24
|
+
host: options.metrics.host,
|
|
25
|
+
port: options.metrics.port,
|
|
26
|
+
disabled: resolvedDisabled,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
}
|
|
23
30
|
if (options.mondayFetchOptions) {
|
|
24
31
|
authorizationService.setRequestFetchOptions(options.mondayFetchOptions);
|
|
25
32
|
}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
import { Metric } from '@mondaydotcomorg/monday-observability-kit';
|
|
1
2
|
type ApiType = 'platform' | 'graph';
|
|
3
|
+
export type MetricsClient = Pick<typeof Metric, 'distribution' | 'increment'>;
|
|
2
4
|
interface InitializeMetricsOptions {
|
|
3
|
-
|
|
5
|
+
client?: MetricsClient;
|
|
6
|
+
serviceName?: string;
|
|
4
7
|
host?: string;
|
|
5
8
|
port?: number;
|
|
6
9
|
disabled?: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"metrics-service.d.ts","sourceRoot":"","sources":["../src/metrics-service.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"metrics-service.d.ts","sourceRoot":"","sources":["../src/metrics-service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AAGnE,KAAK,OAAO,GAAG,UAAU,GAAG,OAAO,CAAC;AAEpC,MAAM,MAAM,aAAa,GAAG,IAAI,CAAC,OAAO,MAAM,EAAE,cAAc,GAAG,WAAW,CAAC,CAAC;AAE9E,UAAU,wBAAwB;IAChC,MAAM,CAAC,EAAE,aAAa,CAAC;IACvB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAID,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,wBAAwB,GAAG,IAAI,CAiCzE;AAED,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,CAmBlF;AAED,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,GAAG,IAAI,CAmBnF"}
|
package/dist/metrics-service.js
CHANGED
|
@@ -3,17 +3,21 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
3
3
|
const mondayObservabilityKit = require('@mondaydotcomorg/monday-observability-kit');
|
|
4
4
|
const authorizationInternalService = require('./authorization-internal-service.js');
|
|
5
5
|
|
|
6
|
-
let
|
|
6
|
+
let metricsClient = null;
|
|
7
7
|
function initializeMetrics(options) {
|
|
8
|
-
if (
|
|
8
|
+
if (metricsClient) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
if (options.client) {
|
|
12
|
+
metricsClient = options.client;
|
|
9
13
|
return;
|
|
10
14
|
}
|
|
11
15
|
const { serviceName } = options;
|
|
12
16
|
if (!serviceName) {
|
|
13
|
-
authorizationInternalService.logger.warn({ tag: '
|
|
17
|
+
authorizationInternalService.logger.warn({ tag: 'monday-authorization-sdk' }, 'Metrics initialization skipped: serviceName is missing');
|
|
14
18
|
return;
|
|
15
19
|
}
|
|
16
|
-
const resolvedHost = options.host ?? process.env.
|
|
20
|
+
const resolvedHost = options.host ?? process.env.HOST_IP ?? 'localhost';
|
|
17
21
|
const envPort = process.env.DOGSTATSD_PORT ? Number(process.env.DOGSTATSD_PORT) : undefined;
|
|
18
22
|
const resolvedPort = options.port ?? (Number.isFinite(envPort ?? NaN) ? envPort : undefined) ?? 8125;
|
|
19
23
|
const resolvedDisabled = options.disabled ?? ['test', 'development'].includes((process.env.NODE_ENV ?? '').toLowerCase());
|
|
@@ -24,32 +28,44 @@ function initializeMetrics(options) {
|
|
|
24
28
|
port: resolvedPort,
|
|
25
29
|
disabled: resolvedDisabled,
|
|
26
30
|
});
|
|
27
|
-
|
|
31
|
+
metricsClient = mondayObservabilityKit.Metric;
|
|
28
32
|
}
|
|
29
33
|
catch (error) {
|
|
30
|
-
authorizationInternalService.logger.warn({ tag: '
|
|
34
|
+
authorizationInternalService.logger.warn({ tag: 'monday-authorization-sdk', error }, 'Failed to initialize metrics');
|
|
31
35
|
}
|
|
32
36
|
}
|
|
33
37
|
function recordAuthorizationTiming(apiType, duration) {
|
|
34
|
-
if (!
|
|
38
|
+
if (!metricsClient) {
|
|
35
39
|
return;
|
|
36
40
|
}
|
|
37
41
|
try {
|
|
38
|
-
|
|
42
|
+
metricsClient.distribution(`authorization.authorizationCheck.${apiType}.duration`, duration);
|
|
39
43
|
}
|
|
40
|
-
catch {
|
|
41
|
-
|
|
44
|
+
catch (error) {
|
|
45
|
+
authorizationInternalService.logger.warn({
|
|
46
|
+
tag: 'monday-authorization-sdk',
|
|
47
|
+
metric: 'authorizationCheckDuration',
|
|
48
|
+
apiType,
|
|
49
|
+
duration,
|
|
50
|
+
error,
|
|
51
|
+
}, 'Failed to emit authorization timing metric');
|
|
42
52
|
}
|
|
43
53
|
}
|
|
44
54
|
function recordAuthorizationError(apiType, statusCode) {
|
|
45
|
-
if (!
|
|
55
|
+
if (!metricsClient) {
|
|
46
56
|
return;
|
|
47
57
|
}
|
|
48
58
|
try {
|
|
49
|
-
|
|
59
|
+
metricsClient.increment(`authorization.authorizationCheck.${apiType}.error`, { statusCode: String(statusCode) }, 1);
|
|
50
60
|
}
|
|
51
|
-
catch {
|
|
52
|
-
|
|
61
|
+
catch (error) {
|
|
62
|
+
authorizationInternalService.logger.warn({
|
|
63
|
+
tag: 'monday-authorization-sdk',
|
|
64
|
+
metric: 'authorizationCheckError',
|
|
65
|
+
apiType,
|
|
66
|
+
statusCode,
|
|
67
|
+
error,
|
|
68
|
+
}, 'Failed to emit authorization error metric');
|
|
53
69
|
}
|
|
54
70
|
}
|
|
55
71
|
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,20 +1,23 @@
|
|
|
1
1
|
import { MondayFetchOptions } from '@mondaydotcomorg/monday-fetch';
|
|
2
2
|
import { setPrometheus } from './prometheus-service';
|
|
3
3
|
import { setIgniteClient, setRedisClient, setRequestFetchOptions } from './authorization-service';
|
|
4
|
-
import { initializeMetrics } from './metrics-service';
|
|
4
|
+
import { initializeMetrics, MetricsClient } from './metrics-service';
|
|
5
5
|
import * as TestKit from './testKit';
|
|
6
6
|
|
|
7
|
+
interface MetricsInitOptions {
|
|
8
|
+
client?: MetricsClient;
|
|
9
|
+
serviceName?: string;
|
|
10
|
+
host?: string;
|
|
11
|
+
port?: number;
|
|
12
|
+
disabled?: boolean;
|
|
13
|
+
}
|
|
14
|
+
|
|
7
15
|
export interface InitOptions {
|
|
8
16
|
prometheus?: any;
|
|
9
17
|
mondayFetchOptions?: MondayFetchOptions;
|
|
10
18
|
redisClient?: any;
|
|
11
19
|
grantedFeatureRedisExpirationInSeconds?: number;
|
|
12
|
-
metrics?:
|
|
13
|
-
serviceName?: string;
|
|
14
|
-
host?: string;
|
|
15
|
-
port?: number;
|
|
16
|
-
disabled?: boolean;
|
|
17
|
-
};
|
|
20
|
+
metrics?: MetricsInitOptions;
|
|
18
21
|
}
|
|
19
22
|
|
|
20
23
|
export async function init(options: InitOptions = {}) {
|
|
@@ -22,14 +25,20 @@ export async function init(options: InitOptions = {}) {
|
|
|
22
25
|
setPrometheus(options.prometheus);
|
|
23
26
|
}
|
|
24
27
|
|
|
25
|
-
|
|
26
|
-
options.metrics
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
28
|
+
if (options.metrics) {
|
|
29
|
+
if (options.metrics.client) {
|
|
30
|
+
initializeMetrics({ client: options.metrics.client });
|
|
31
|
+
} else {
|
|
32
|
+
const resolvedDisabled =
|
|
33
|
+
options.metrics.disabled ?? ['test', 'development'].includes((process.env.NODE_ENV ?? '').toLowerCase());
|
|
34
|
+
initializeMetrics({
|
|
35
|
+
serviceName: options.metrics.serviceName ?? process.env.APP_NAME ?? 'authorization-sdk',
|
|
36
|
+
host: options.metrics.host,
|
|
37
|
+
port: options.metrics.port,
|
|
38
|
+
disabled: resolvedDisabled,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
33
42
|
|
|
34
43
|
if (options.mondayFetchOptions) {
|
|
35
44
|
setRequestFetchOptions(options.mondayFetchOptions);
|
package/src/metrics-service.ts
CHANGED
|
@@ -3,27 +3,35 @@ import { logger } from './authorization-internal-service';
|
|
|
3
3
|
|
|
4
4
|
type ApiType = 'platform' | 'graph';
|
|
5
5
|
|
|
6
|
+
export type MetricsClient = Pick<typeof Metric, 'distribution' | 'increment'>;
|
|
7
|
+
|
|
6
8
|
interface InitializeMetricsOptions {
|
|
7
|
-
|
|
9
|
+
client?: MetricsClient;
|
|
10
|
+
serviceName?: string;
|
|
8
11
|
host?: string;
|
|
9
12
|
port?: number;
|
|
10
13
|
disabled?: boolean;
|
|
11
14
|
}
|
|
12
15
|
|
|
13
|
-
let
|
|
16
|
+
let metricsClient: MetricsClient | null = null;
|
|
14
17
|
|
|
15
18
|
export function initializeMetrics(options: InitializeMetricsOptions): void {
|
|
16
|
-
if (
|
|
19
|
+
if (metricsClient) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (options.client) {
|
|
24
|
+
metricsClient = options.client;
|
|
17
25
|
return;
|
|
18
26
|
}
|
|
19
27
|
|
|
20
28
|
const { serviceName } = options;
|
|
21
29
|
if (!serviceName) {
|
|
22
|
-
logger.warn({ tag: '
|
|
30
|
+
logger.warn({ tag: 'monday-authorization-sdk' }, 'Metrics initialization skipped: serviceName is missing');
|
|
23
31
|
return;
|
|
24
32
|
}
|
|
25
33
|
|
|
26
|
-
const resolvedHost = options.host ?? process.env.
|
|
34
|
+
const resolvedHost = options.host ?? process.env.HOST_IP ?? 'localhost';
|
|
27
35
|
const envPort = process.env.DOGSTATSD_PORT ? Number(process.env.DOGSTATSD_PORT) : undefined;
|
|
28
36
|
const resolvedPort = options.port ?? (Number.isFinite(envPort ?? NaN) ? envPort : undefined) ?? 8125;
|
|
29
37
|
const resolvedDisabled =
|
|
@@ -36,32 +44,50 @@ export function initializeMetrics(options: InitializeMetricsOptions): void {
|
|
|
36
44
|
port: resolvedPort,
|
|
37
45
|
disabled: resolvedDisabled,
|
|
38
46
|
});
|
|
39
|
-
|
|
47
|
+
metricsClient = Metric;
|
|
40
48
|
} catch (error) {
|
|
41
|
-
logger.warn({ tag: '
|
|
49
|
+
logger.warn({ tag: 'monday-authorization-sdk', error }, 'Failed to initialize metrics');
|
|
42
50
|
}
|
|
43
51
|
}
|
|
44
52
|
|
|
45
53
|
export function recordAuthorizationTiming(apiType: ApiType, duration: number): void {
|
|
46
|
-
if (!
|
|
54
|
+
if (!metricsClient) {
|
|
47
55
|
return;
|
|
48
56
|
}
|
|
49
57
|
|
|
50
58
|
try {
|
|
51
|
-
|
|
52
|
-
} catch {
|
|
53
|
-
|
|
59
|
+
metricsClient.distribution(`authorization.authorizationCheck.${apiType}.duration`, duration);
|
|
60
|
+
} catch (error) {
|
|
61
|
+
logger.warn(
|
|
62
|
+
{
|
|
63
|
+
tag: 'monday-authorization-sdk',
|
|
64
|
+
metric: 'authorizationCheckDuration',
|
|
65
|
+
apiType,
|
|
66
|
+
duration,
|
|
67
|
+
error,
|
|
68
|
+
},
|
|
69
|
+
'Failed to emit authorization timing metric'
|
|
70
|
+
);
|
|
54
71
|
}
|
|
55
72
|
}
|
|
56
73
|
|
|
57
74
|
export function recordAuthorizationError(apiType: ApiType, statusCode: number): void {
|
|
58
|
-
if (!
|
|
75
|
+
if (!metricsClient) {
|
|
59
76
|
return;
|
|
60
77
|
}
|
|
61
78
|
|
|
62
79
|
try {
|
|
63
|
-
|
|
64
|
-
} catch {
|
|
65
|
-
|
|
80
|
+
metricsClient.increment(`authorization.authorizationCheck.${apiType}.error`, { statusCode: String(statusCode) }, 1);
|
|
81
|
+
} catch (error) {
|
|
82
|
+
logger.warn(
|
|
83
|
+
{
|
|
84
|
+
tag: 'monday-authorization-sdk',
|
|
85
|
+
metric: 'authorizationCheckError',
|
|
86
|
+
apiType,
|
|
87
|
+
statusCode,
|
|
88
|
+
error,
|
|
89
|
+
},
|
|
90
|
+
'Failed to emit authorization error metric'
|
|
91
|
+
);
|
|
66
92
|
}
|
|
67
93
|
}
|