@tramvai/module-metrics 4.31.0 → 4.32.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 CHANGED
@@ -16,9 +16,16 @@ Next labels are added to metrics:
16
16
  - http response code
17
17
  - service name
18
18
 
19
- Name of the service calculates by comparing request urls with values in `MetricsServicesRegistry`. Initially the register is bootstrapped with the inverted content of env variables, e.g. if some url from env is a substring of the request url, then the name of the env become the service name. If several envs matches this logic then the env with the longest url is used.
19
+ #### Make service names showed in metrics instead of hostnames
20
20
 
21
- If you need to customize the service name you can provide HTTP header to the request via `x-tramvai-service-name` header.
21
+ Name of the service calculates by comparing request urls with values in `MetricsServicesRegistry`. Initially the register is bootstrapped with the inverted content of env variables. For example if some url from env is a substring of the request url, then the name of the env become the service name. If several envs matches this logic then the env with the longest url is used. If none of envs matches then **domain** used as service name label.
22
+
23
+ It is possible to give a hint to module about the service name in case url is dynamic. To do that:
24
+
25
+ - use token `METRICS_SERVICES_REGISTRY_TOKEN`;
26
+ - call `metricsServicesRegistry.register("Part of the url or the whole url", "Name of service")`
27
+
28
+ To explicitly associate the service name label with request, you should provide the `x-tramvai-service-name` header. This header will be consumed by the metrics module and then removed.
22
29
 
23
30
  ### Event Loop Lag
24
31
 
@@ -144,13 +151,6 @@ export const SOME_MODULE = createToken<SomeModule>('someModule');
144
151
  export class SomeModuleContainer {}
145
152
  ```
146
153
 
147
- ### Make service names showed in metrics instead of hostnames
148
-
149
- It is possible to give a hint to module about the service name in case url is dynamic. To do that:
150
-
151
- - use token `METRICS_SERVICES_REGISTRY_TOKEN`;
152
- - call `metricsServicesRegistry.register("Part of the url or the whole url", "Name of service")`
153
-
154
154
  ### Use metrics to profile performance in browser
155
155
 
156
156
  To measure length of the events you must use method `startTimer` of classes Gauge, Histogram, Summary. In dev-mode these classes are patched and methods to work with timers will use [PerformanceApi](https://developer.mozilla.org/en-US/docs/Web/API/Performance).
@@ -1,4 +1,5 @@
1
1
  import type { MetricsServicesRegistryInterface } from '@tramvai/tokens-metrics';
2
+ export declare const SERVICE_NAME_HEADER = "x-tramvai-service-name";
2
3
  declare class MetricsServicesRegistry implements MetricsServicesRegistryInterface {
3
4
  private registryPrefixTree;
4
5
  registerEnv(env: any): void;
@@ -68,4 +68,4 @@ class MetricsServicesRegistry {
68
68
  }
69
69
  }
70
70
 
71
- export { MetricsServicesRegistry };
71
+ export { MetricsServicesRegistry, SERVICE_NAME_HEADER };
@@ -77,3 +77,4 @@ class MetricsServicesRegistry {
77
77
  }
78
78
 
79
79
  exports.MetricsServicesRegistry = MetricsServicesRegistry;
80
+ exports.SERVICE_NAME_HEADER = SERVICE_NAME_HEADER;
package/lib/server.d.ts CHANGED
@@ -1,4 +1,6 @@
1
1
  export { getUrlAndOptions } from './request/createRequestWithMetrics';
2
+ export { SERVICE_NAME_HEADER } from './request/MetricsServicesRegistry';
3
+ export { METRICS_DEFAULT_REGISTRY } from './tokens';
2
4
  export * from '@tramvai/tokens-metrics';
3
5
  export declare class MetricsModule {
4
6
  }
package/lib/server.es.js CHANGED
@@ -12,7 +12,10 @@ import { RequestModule } from './request/index.es.js';
12
12
  import { InstantMetricsModule } from './instantMetrics/server.es.js';
13
13
  import { eventLoopMetrics } from './metrics/eventLoop.es.js';
14
14
  import { commandLineMetrics } from './metrics/commandLine.es.js';
15
+ import { METRICS_DEFAULT_REGISTRY } from './tokens.es.js';
16
+ export { METRICS_DEFAULT_REGISTRY } from './tokens.es.js';
15
17
  export { getUrlAndOptions } from './request/createRequestWithMetrics.es.js';
18
+ export { SERVICE_NAME_HEADER } from './request/MetricsServicesRegistry.es.js';
16
19
 
17
20
  let MetricsModule = class MetricsModule {
18
21
  };
@@ -27,7 +30,7 @@ MetricsModule = __decorate([
27
30
  },
28
31
  }),
29
32
  provide({
30
- provide: 'metricsDefaultRegistry',
33
+ provide: METRICS_DEFAULT_REGISTRY,
31
34
  scope: Scope.SINGLETON,
32
35
  useClass: Registry,
33
36
  }),
@@ -44,7 +47,7 @@ MetricsModule = __decorate([
44
47
  },
45
48
  scope: Scope.SINGLETON,
46
49
  deps: {
47
- registry: 'metricsDefaultRegistry',
50
+ registry: METRICS_DEFAULT_REGISTRY,
48
51
  },
49
52
  }),
50
53
  provide({
@@ -59,7 +62,7 @@ MetricsModule = __decorate([
59
62
  },
60
63
  deps: {
61
64
  app: UTILITY_WEB_FASTIFY_APP_TOKEN,
62
- registry: 'metricsDefaultRegistry',
65
+ registry: METRICS_DEFAULT_REGISTRY,
63
66
  },
64
67
  multi: true,
65
68
  }),
package/lib/server.js CHANGED
@@ -15,7 +15,9 @@ var index = require('./request/index.js');
15
15
  var server = require('./instantMetrics/server.js');
16
16
  var eventLoop = require('./metrics/eventLoop.js');
17
17
  var commandLine = require('./metrics/commandLine.js');
18
+ var tokens = require('./tokens.js');
18
19
  var createRequestWithMetrics = require('./request/createRequestWithMetrics.js');
20
+ var MetricsServicesRegistry = require('./request/MetricsServicesRegistry.js');
19
21
 
20
22
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
21
23
 
@@ -34,7 +36,7 @@ exports.MetricsModule = tslib.__decorate([
34
36
  },
35
37
  }),
36
38
  core.provide({
37
- provide: 'metricsDefaultRegistry',
39
+ provide: tokens.METRICS_DEFAULT_REGISTRY,
38
40
  scope: core.Scope.SINGLETON,
39
41
  useClass: promClient.Registry,
40
42
  }),
@@ -51,7 +53,7 @@ exports.MetricsModule = tslib.__decorate([
51
53
  },
52
54
  scope: core.Scope.SINGLETON,
53
55
  deps: {
54
- registry: 'metricsDefaultRegistry',
56
+ registry: tokens.METRICS_DEFAULT_REGISTRY,
55
57
  },
56
58
  }),
57
59
  core.provide({
@@ -66,7 +68,7 @@ exports.MetricsModule = tslib.__decorate([
66
68
  },
67
69
  deps: {
68
70
  app: tokensServerPrivate.UTILITY_WEB_FASTIFY_APP_TOKEN,
69
- registry: 'metricsDefaultRegistry',
71
+ registry: tokens.METRICS_DEFAULT_REGISTRY,
70
72
  },
71
73
  multi: true,
72
74
  }),
@@ -138,7 +140,9 @@ exports.MetricsModule = tslib.__decorate([
138
140
  })
139
141
  ], exports.MetricsModule);
140
142
 
143
+ exports.METRICS_DEFAULT_REGISTRY = tokens.METRICS_DEFAULT_REGISTRY;
141
144
  exports.getUrlAndOptions = createRequestWithMetrics.getUrlAndOptions;
145
+ exports.SERVICE_NAME_HEADER = MetricsServicesRegistry.SERVICE_NAME_HEADER;
142
146
  Object.keys(tokensMetrics).forEach(function (k) {
143
147
  if (k !== 'default' && !exports.hasOwnProperty(k)) Object.defineProperty(exports, k, {
144
148
  enumerable: true,
@@ -0,0 +1,5 @@
1
+ import type { Registry } from 'prom-client';
2
+ export declare const METRICS_DEFAULT_REGISTRY: Registry & {
3
+ __type?: "base token";
4
+ };
5
+ //# sourceMappingURL=tokens.d.ts.map
@@ -0,0 +1,5 @@
1
+ import { createToken } from '@tramvai/core';
2
+
3
+ const METRICS_DEFAULT_REGISTRY = createToken('metricsDefaultRegistry');
4
+
5
+ export { METRICS_DEFAULT_REGISTRY };
package/lib/tokens.js ADDED
@@ -0,0 +1,9 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var core = require('@tramvai/core');
6
+
7
+ const METRICS_DEFAULT_REGISTRY = core.createToken('metricsDefaultRegistry');
8
+
9
+ exports.METRICS_DEFAULT_REGISTRY = METRICS_DEFAULT_REGISTRY;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tramvai/module-metrics",
3
- "version": "4.31.0",
3
+ "version": "4.32.2",
4
4
  "description": "",
5
5
  "browser": "lib/browser.js",
6
6
  "main": "lib/server.js",
@@ -18,16 +18,16 @@
18
18
  "watch": "tsc -w"
19
19
  },
20
20
  "dependencies": {
21
- "@tramvai/core": "4.31.0",
22
- "@tramvai/tokens-common": "4.31.0",
23
- "@tramvai/tokens-core-private": "4.31.0",
24
- "@tramvai/tokens-server": "4.31.0",
25
- "@tramvai/tokens-server-private": "4.31.0",
26
- "@tramvai/tokens-metrics": "4.31.0",
27
- "@tramvai/tokens-router": "4.31.0",
28
- "@tramvai/tokens-http-client": "4.31.0",
29
- "@tramvai/state": "4.31.0",
30
- "@tramvai/papi": "4.31.0",
21
+ "@tramvai/core": "4.32.2",
22
+ "@tramvai/tokens-common": "4.32.2",
23
+ "@tramvai/tokens-core-private": "4.32.2",
24
+ "@tramvai/tokens-server": "4.32.2",
25
+ "@tramvai/tokens-server-private": "4.32.2",
26
+ "@tramvai/tokens-metrics": "4.32.2",
27
+ "@tramvai/tokens-router": "4.32.2",
28
+ "@tramvai/tokens-http-client": "4.32.2",
29
+ "@tramvai/state": "4.32.2",
30
+ "@tramvai/papi": "4.32.2",
31
31
  "@tinkoff/measure-fastify-requests": "0.3.1",
32
32
  "@tinkoff/monkeypatch": "4.0.1",
33
33
  "@tinkoff/url": "0.10.1",