@tramvai/module-server 2.51.2 → 2.56.0

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
@@ -176,6 +176,12 @@ There are special headers in the module, which help to determine the exact infor
176
176
 
177
177
  For all of the headers above which are passed via environment variables to be available, you need the external infrastructure to pass them when building and deprovisioning the application image (inside tinkoff this is done automatically).
178
178
 
179
+ #### Server-Timing
180
+
181
+ Header [Server-Timing](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Server-Timing) provides additional information about different timings that were spent on server to handle current request. Currently, it shows timings for [CommandLineRunner's](concepts/command-line-runner.md) lines execution.
182
+
183
+ To see values that related to request look for the header `Server-Timing` or check the `Timing` tab in browser DevTools for the page's main html.
184
+
179
185
  ### Debugging
180
186
 
181
187
  Module uses loggers with identifiers: `server`, `server:static`, `server:webapp`, `server:node-debug:request`
@@ -6,3 +6,4 @@ export * from './proxy';
6
6
  export * from './dependenciesVersion';
7
7
  export * from './utilityServer';
8
8
  export * from './keepAlive';
9
+ export * from './serverTiming';
@@ -0,0 +1,6 @@
1
+ export declare const ServerTimingModule: import("@tinkoff/dippy/lib/modules/module.h").ModuleClass & Partial<import("@tinkoff/dippy/lib/modules/module.h").ModuleSecretParameters> & {
2
+ [x: string]: (...args: any[]) => {
3
+ mainModule: import("@tramvai/core").ModuleType<import("@tinkoff/dippy/lib/modules/module.h").ModuleClass>;
4
+ providers: import("@tramvai/core").Provider<any, any>[];
5
+ };
6
+ };
package/lib/server.es.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { __decorate } from 'tslib';
2
2
  import { setDefaultResultOrder } from 'dns';
3
3
  import EventEmitter$1, { EventEmitter } from 'events';
4
- import { Scope, APP_INFO_TOKEN, Module, provide as provide$1, DI_TOKEN as DI_TOKEN$1, COMMAND_LINE_RUNNER_TOKEN, commandLineListTokens, createToken } from '@tramvai/core';
4
+ import { Scope, APP_INFO_TOKEN, Module, provide as provide$1, DI_TOKEN as DI_TOKEN$1, COMMAND_LINE_RUNNER_TOKEN, commandLineListTokens, createToken, declareModule } from '@tramvai/core';
5
5
  import { SERVER_MODULE_PAPI_PUBLIC_ROUTE, SERVER_MODULE_PAPI_PUBLIC_URL, SERVER_MODULE_PAPI_PRIVATE_URL, SERVER_MODULE_PAPI_PRIVATE_ROUTE, SERVER_MODULE_STATICS_OPTIONS, SERVER_TOKEN, LIVENESS_PATH_TOKEN, READINESS_PATH_TOKEN, READINESS_PROBE_TOKEN, LIVENESS_PROBE_TOKEN, UTILITY_SERVER_PATHS, PROXY_CONFIG_TOKEN, DEPENDENCIES_VERSION_FILTER_TOKEN, UTILITY_SERVER_PORT_TOKEN } from '@tramvai/tokens-server';
6
6
  export * from '@tramvai/tokens-server';
7
7
  import { FASTIFY_REQUEST, FASTIFY_RESPONSE, PAPI_EXECUTOR, WEB_FASTIFY_APP_BEFORE_INIT_TOKEN, UTILITY_WEB_FASTIFY_APP_TOKEN, WEB_FASTIFY_APP_INIT_TOKEN, UTILITY_SERVER_TOKEN, SERVER_FACTORY_TOKEN, WEB_FASTIFY_APP_TOKEN, WEB_FASTIFY_APP_FACTORY_TOKEN, WEB_FASTIFY_APP_AFTER_INIT_TOKEN, WEB_FASTIFY_APP_METRICS_TOKEN, WEB_FASTIFY_APP_LIMITER_TOKEN, WEB_FASTIFY_APP_BEFORE_ERROR_TOKEN, WEB_FASTIFY_APP_PROCESS_ERROR_TOKEN, WEB_FASTIFY_APP_AFTER_ERROR_TOKEN } from '@tramvai/tokens-server-private';
@@ -32,6 +32,7 @@ import isArray from '@tinkoff/utils/is/array';
32
32
  import isObject from '@tinkoff/utils/is/object';
33
33
  import { createProxyMiddleware } from 'http-proxy-middleware';
34
34
  import { ENV_MANAGER_TOKEN as ENV_MANAGER_TOKEN$1 } from '@tramvai/module-common';
35
+ import { COMMAND_LINE_EXECUTION_END_TOKEN } from '@tramvai/tokens-core-private';
35
36
 
36
37
  const serverFactory = () => {
37
38
  return http.createServer();
@@ -1008,6 +1009,31 @@ KeepAliveModule = __decorate([
1008
1009
  })
1009
1010
  ], KeepAliveModule);
1010
1011
 
1012
+ const ServerTimingModule = declareModule({
1013
+ name: 'ServerTiming',
1014
+ providers: [
1015
+ provide$1({
1016
+ provide: COMMAND_LINE_EXECUTION_END_TOKEN,
1017
+ multi: true,
1018
+ useValue: (di, type, status, timingInfo) => {
1019
+ var _a;
1020
+ if (type === 'server' && status === 'customer') {
1021
+ const responseManager = di.get(RESPONSE_MANAGER_TOKEN);
1022
+ const initialHeader = (_a = responseManager.getHeader('Server-Timing')) !== null && _a !== void 0 ? _a : '';
1023
+ const entries = [];
1024
+ // index for custom sort
1025
+ let index = 0;
1026
+ for (const line in timingInfo) {
1027
+ const info = timingInfo[line];
1028
+ entries.push(`line_${index++}_${line};dur=${info.end - info.start}`);
1029
+ }
1030
+ responseManager.setHeader('Server-Timing', `${initialHeader ? `${initialHeader}, ` : ''}${entries.join(', ')}`);
1031
+ }
1032
+ },
1033
+ }),
1034
+ ],
1035
+ });
1036
+
1011
1037
  if (typeof setDefaultResultOrder === 'function') {
1012
1038
  setDefaultResultOrder('ipv4first');
1013
1039
  }
@@ -1028,6 +1054,7 @@ ServerModule = __decorate([
1028
1054
  DependenciesVersionModule,
1029
1055
  UtilityServerModule,
1030
1056
  KeepAliveModule,
1057
+ ServerTimingModule,
1031
1058
  process.env.NODE_ENV !== 'production' && DebugHttpRequestsModule,
1032
1059
  ].filter(Boolean),
1033
1060
  providers: [
package/lib/server.js CHANGED
@@ -35,6 +35,7 @@ var isArray = require('@tinkoff/utils/is/array');
35
35
  var isObject = require('@tinkoff/utils/is/object');
36
36
  var httpProxyMiddleware = require('http-proxy-middleware');
37
37
  var moduleCommon = require('@tramvai/module-common');
38
+ var tokensCorePrivate = require('@tramvai/tokens-core-private');
38
39
 
39
40
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
40
41
 
@@ -1030,6 +1031,31 @@ KeepAliveModule = tslib.__decorate([
1030
1031
  })
1031
1032
  ], KeepAliveModule);
1032
1033
 
1034
+ const ServerTimingModule = core.declareModule({
1035
+ name: 'ServerTiming',
1036
+ providers: [
1037
+ core.provide({
1038
+ provide: tokensCorePrivate.COMMAND_LINE_EXECUTION_END_TOKEN,
1039
+ multi: true,
1040
+ useValue: (di, type, status, timingInfo) => {
1041
+ var _a;
1042
+ if (type === 'server' && status === 'customer') {
1043
+ const responseManager = di.get(tokensCommon.RESPONSE_MANAGER_TOKEN);
1044
+ const initialHeader = (_a = responseManager.getHeader('Server-Timing')) !== null && _a !== void 0 ? _a : '';
1045
+ const entries = [];
1046
+ // index for custom sort
1047
+ let index = 0;
1048
+ for (const line in timingInfo) {
1049
+ const info = timingInfo[line];
1050
+ entries.push(`line_${index++}_${line};dur=${info.end - info.start}`);
1051
+ }
1052
+ responseManager.setHeader('Server-Timing', `${initialHeader ? `${initialHeader}, ` : ''}${entries.join(', ')}`);
1053
+ }
1054
+ },
1055
+ }),
1056
+ ],
1057
+ });
1058
+
1033
1059
  if (typeof dns.setDefaultResultOrder === 'function') {
1034
1060
  dns.setDefaultResultOrder('ipv4first');
1035
1061
  }
@@ -1050,6 +1076,7 @@ exports.ServerModule = tslib.__decorate([
1050
1076
  DependenciesVersionModule,
1051
1077
  UtilityServerModule,
1052
1078
  KeepAliveModule,
1079
+ ServerTimingModule,
1053
1080
  process.env.NODE_ENV !== 'production' && DebugHttpRequestsModule,
1054
1081
  ].filter(Boolean),
1055
1082
  providers: [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tramvai/module-server",
3
- "version": "2.51.2",
3
+ "version": "2.56.0",
4
4
  "description": "",
5
5
  "browser": "lib/browser.js",
6
6
  "main": "lib/server.js",
@@ -26,11 +26,11 @@
26
26
  "@tinkoff/monkeypatch": "2.0.3",
27
27
  "@tinkoff/terminus": "0.1.5",
28
28
  "@tinkoff/url": "0.8.4",
29
- "@tramvai/module-cache-warmup": "2.51.2",
30
- "@tramvai/module-metrics": "2.51.2",
31
- "@tramvai/papi": "2.51.2",
32
- "@tramvai/tokens-server": "2.51.2",
33
- "@tramvai/tokens-server-private": "2.51.2",
29
+ "@tramvai/module-cache-warmup": "2.56.0",
30
+ "@tramvai/module-metrics": "2.56.0",
31
+ "@tramvai/papi": "2.56.0",
32
+ "@tramvai/tokens-server": "2.56.0",
33
+ "@tramvai/tokens-server-private": "2.56.0",
34
34
  "fastify": "^4.6.0",
35
35
  "@fastify/cookie": "^8.1.0",
36
36
  "@fastify/compress": "^6.1.1",
@@ -39,13 +39,14 @@
39
39
  "http-proxy-middleware": "^2.0.2"
40
40
  },
41
41
  "peerDependencies": {
42
- "@tinkoff/dippy": "0.8.9",
42
+ "@tinkoff/dippy": "0.8.10",
43
43
  "@tinkoff/utils": "^2.1.2",
44
- "@tramvai/cli": "2.51.2",
45
- "@tramvai/core": "2.51.2",
46
- "@tramvai/module-common": "2.51.2",
47
- "@tramvai/module-environment": "2.51.2",
48
- "@tramvai/tokens-common": "2.51.2",
44
+ "@tramvai/cli": "2.56.0",
45
+ "@tramvai/core": "2.56.0",
46
+ "@tramvai/module-common": "2.56.0",
47
+ "@tramvai/module-environment": "2.56.0",
48
+ "@tramvai/tokens-common": "2.56.0",
49
+ "@tramvai/tokens-core-private": "2.56.0",
49
50
  "tslib": "^2.4.0"
50
51
  },
51
52
  "devDependencies": {