@foxford/den-traces 5.0.0 → 7.0.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/{chunk-DAPDESIH.cjs → chunk-C54MGVV6.cjs} +7 -7
- package/{chunk-PMYUYUJQ.js → chunk-IDEPG3TX.js} +6 -6
- package/index.cjs +24 -16
- package/index.js +21 -13
- package/package.json +5 -5
- package/services/index.cjs +16 -13
- package/services/index.js +13 -10
- package/timings/index.cjs +2 -2
- package/timings/index.js +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true})
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/timings/index.ts
|
|
2
2
|
var sink = null;
|
|
3
3
|
var requestSink = null;
|
|
4
4
|
var upstreamErrorSink = null;
|
|
@@ -30,18 +30,18 @@ function startRequest(name, url) {
|
|
|
30
30
|
if (done) return;
|
|
31
31
|
done = true;
|
|
32
32
|
const ms = performance.now() - startedAt;
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
33
|
+
sink == null ? void 0 : sink(name, ms, startedAt);
|
|
34
|
+
requestSink == null ? void 0 : requestSink({ bytes: null, error: String(error), ms, name, startedAt, status: null, url });
|
|
35
|
+
upstreamErrorSink == null ? void 0 : upstreamErrorSink({ name, reason: "network", status: null, url });
|
|
36
36
|
},
|
|
37
37
|
finish(status, bytes = null) {
|
|
38
38
|
if (done) return;
|
|
39
39
|
done = true;
|
|
40
40
|
const ms = performance.now() - startedAt;
|
|
41
|
-
|
|
42
|
-
|
|
41
|
+
sink == null ? void 0 : sink(name, ms, startedAt);
|
|
42
|
+
requestSink == null ? void 0 : requestSink({ bytes, ms, name, startedAt, status, url });
|
|
43
43
|
if (status < 200 || status >= 300) {
|
|
44
|
-
|
|
44
|
+
upstreamErrorSink == null ? void 0 : upstreamErrorSink({ name, reason: "http_".concat(String(status)), status, url });
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
};
|
|
@@ -30,18 +30,18 @@ function startRequest(name, url) {
|
|
|
30
30
|
if (done) return;
|
|
31
31
|
done = true;
|
|
32
32
|
const ms = performance.now() - startedAt;
|
|
33
|
-
sink
|
|
34
|
-
requestSink
|
|
35
|
-
upstreamErrorSink
|
|
33
|
+
sink == null ? void 0 : sink(name, ms, startedAt);
|
|
34
|
+
requestSink == null ? void 0 : requestSink({ bytes: null, error: String(error), ms, name, startedAt, status: null, url });
|
|
35
|
+
upstreamErrorSink == null ? void 0 : upstreamErrorSink({ name, reason: "network", status: null, url });
|
|
36
36
|
},
|
|
37
37
|
finish(status, bytes = null) {
|
|
38
38
|
if (done) return;
|
|
39
39
|
done = true;
|
|
40
40
|
const ms = performance.now() - startedAt;
|
|
41
|
-
sink
|
|
42
|
-
requestSink
|
|
41
|
+
sink == null ? void 0 : sink(name, ms, startedAt);
|
|
42
|
+
requestSink == null ? void 0 : requestSink({ bytes, ms, name, startedAt, status, url });
|
|
43
43
|
if (status < 200 || status >= 300) {
|
|
44
|
-
upstreamErrorSink
|
|
44
|
+
upstreamErrorSink == null ? void 0 : upstreamErrorSink({ name, reason: "http_".concat(String(status)), status, url });
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
};
|
package/index.cjs
CHANGED
|
@@ -1,31 +1,36 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
var
|
|
7
|
+
var _chunkC54MGVV6cjs = require('./chunk-C54MGVV6.cjs');
|
|
8
8
|
|
|
9
9
|
// src/server/install.ts
|
|
10
10
|
var _async_hooks = require('async_hooks');
|
|
11
11
|
|
|
12
12
|
// src/server/trace.ts
|
|
13
13
|
function nameOf(named) {
|
|
14
|
-
|
|
14
|
+
var _a;
|
|
15
|
+
return (_a = named.token.description) != null ? _a : "?";
|
|
15
16
|
}
|
|
16
17
|
function describeDeclarations(app) {
|
|
18
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
17
19
|
return {
|
|
18
|
-
guards: (
|
|
20
|
+
guards: ((_a = app.guards) != null ? _a : []).map(nameOf),
|
|
19
21
|
mountsInto: app.mountsInto,
|
|
20
22
|
name: app.name,
|
|
21
|
-
provides: (
|
|
22
|
-
requires: (
|
|
23
|
-
routes: (
|
|
24
|
-
(route) =>
|
|
23
|
+
provides: ((_b = app.provides) != null ? _b : []).map(nameOf),
|
|
24
|
+
requires: ((_c = app.requires) != null ? _c : []).map((token) => token.description),
|
|
25
|
+
routes: ((_d = app.routes) != null ? _d : []).map(
|
|
26
|
+
(route) => {
|
|
27
|
+
var _a2;
|
|
28
|
+
return typeof route === "string" ? { guards: [], source: route } : { guards: ((_a2 = route.guards) != null ? _a2 : []).map(nameOf), source: route.source };
|
|
29
|
+
}
|
|
25
30
|
),
|
|
26
|
-
slots: Object.keys(
|
|
27
|
-
units: (
|
|
28
|
-
viewModels: (
|
|
31
|
+
slots: Object.keys((_e = app.slots) != null ? _e : {}),
|
|
32
|
+
units: ((_f = app.units) != null ? _f : []).map(nameOf),
|
|
33
|
+
viewModels: ((_g = app.viewModels) != null ? _g : []).map(nameOf)
|
|
29
34
|
};
|
|
30
35
|
}
|
|
31
36
|
var TRACE_LIMIT_BYTES = 8192;
|
|
@@ -47,7 +52,7 @@ function traceHeader(requests, startedAt) {
|
|
|
47
52
|
return encoded;
|
|
48
53
|
}
|
|
49
54
|
function serverTimingHeader(marks) {
|
|
50
|
-
return marks.map(({ name, ms, startMs }) =>
|
|
55
|
+
return marks.map(({ name, ms, startMs }) => "".concat(name, ";dur=").concat(ms.toFixed(1), ';desc="@').concat(startMs.toFixed(1), '"')).join(", ");
|
|
51
56
|
}
|
|
52
57
|
|
|
53
58
|
// src/server/install.ts
|
|
@@ -55,14 +60,17 @@ var TRACE_HEADER = "x-den-trace";
|
|
|
55
60
|
var storage = new (0, _async_hooks.AsyncLocalStorage)();
|
|
56
61
|
function recordServerTiming(name, ms, startedAt) {
|
|
57
62
|
const timings = storage.getStore();
|
|
58
|
-
|
|
63
|
+
timings == null ? void 0 : timings.marks.push({ ms, name, startMs: (startedAt != null ? startedAt : performance.now() - ms) - timings.startedAt });
|
|
59
64
|
}
|
|
60
65
|
function asked(headers) {
|
|
61
66
|
return headers[TRACE_HEADER] !== void 0;
|
|
62
67
|
}
|
|
63
68
|
function installServerTrace(instance, options = {}) {
|
|
64
|
-
|
|
65
|
-
|
|
69
|
+
_chunkC54MGVV6cjs.setTimingSink.call(void 0, recordServerTiming);
|
|
70
|
+
_chunkC54MGVV6cjs.setRequestSink.call(void 0, (request) => {
|
|
71
|
+
var _a;
|
|
72
|
+
return (_a = storage.getStore()) == null ? void 0 : _a.requests.push(request);
|
|
73
|
+
});
|
|
66
74
|
instance.addHook("onRequest", (_request, _reply, done) => {
|
|
67
75
|
storage.run({ marks: [], requests: [], startedAt: performance.now() }, done);
|
|
68
76
|
});
|
|
@@ -94,4 +102,4 @@ function installServerTrace(instance, options = {}) {
|
|
|
94
102
|
|
|
95
103
|
|
|
96
104
|
|
|
97
|
-
exports.describeDeclarations = describeDeclarations; exports.installServerTrace = installServerTrace; exports.measure =
|
|
105
|
+
exports.describeDeclarations = describeDeclarations; exports.installServerTrace = installServerTrace; exports.measure = _chunkC54MGVV6cjs.measure; exports.recordServerTiming = recordServerTiming; exports.setRequestSink = _chunkC54MGVV6cjs.setRequestSink; exports.setTimingSink = _chunkC54MGVV6cjs.setTimingSink; exports.setUpstreamErrorSink = _chunkC54MGVV6cjs.setUpstreamErrorSink; exports.startRequest = _chunkC54MGVV6cjs.startRequest; exports.traceHeader = traceHeader;
|
package/index.js
CHANGED
|
@@ -4,28 +4,33 @@ import {
|
|
|
4
4
|
setTimingSink,
|
|
5
5
|
setUpstreamErrorSink,
|
|
6
6
|
startRequest
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-IDEPG3TX.js";
|
|
8
8
|
|
|
9
9
|
// src/server/install.ts
|
|
10
10
|
import { AsyncLocalStorage } from "async_hooks";
|
|
11
11
|
|
|
12
12
|
// src/server/trace.ts
|
|
13
13
|
function nameOf(named) {
|
|
14
|
-
|
|
14
|
+
var _a;
|
|
15
|
+
return (_a = named.token.description) != null ? _a : "?";
|
|
15
16
|
}
|
|
16
17
|
function describeDeclarations(app) {
|
|
18
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
17
19
|
return {
|
|
18
|
-
guards: (app.guards
|
|
20
|
+
guards: ((_a = app.guards) != null ? _a : []).map(nameOf),
|
|
19
21
|
mountsInto: app.mountsInto,
|
|
20
22
|
name: app.name,
|
|
21
|
-
provides: (app.provides
|
|
22
|
-
requires: (app.requires
|
|
23
|
-
routes: (app.routes
|
|
24
|
-
(route) =>
|
|
23
|
+
provides: ((_b = app.provides) != null ? _b : []).map(nameOf),
|
|
24
|
+
requires: ((_c = app.requires) != null ? _c : []).map((token) => token.description),
|
|
25
|
+
routes: ((_d = app.routes) != null ? _d : []).map(
|
|
26
|
+
(route) => {
|
|
27
|
+
var _a2;
|
|
28
|
+
return typeof route === "string" ? { guards: [], source: route } : { guards: ((_a2 = route.guards) != null ? _a2 : []).map(nameOf), source: route.source };
|
|
29
|
+
}
|
|
25
30
|
),
|
|
26
|
-
slots: Object.keys(app.slots
|
|
27
|
-
units: (app.units
|
|
28
|
-
viewModels: (app.viewModels
|
|
31
|
+
slots: Object.keys((_e = app.slots) != null ? _e : {}),
|
|
32
|
+
units: ((_f = app.units) != null ? _f : []).map(nameOf),
|
|
33
|
+
viewModels: ((_g = app.viewModels) != null ? _g : []).map(nameOf)
|
|
29
34
|
};
|
|
30
35
|
}
|
|
31
36
|
var TRACE_LIMIT_BYTES = 8192;
|
|
@@ -47,7 +52,7 @@ function traceHeader(requests, startedAt) {
|
|
|
47
52
|
return encoded;
|
|
48
53
|
}
|
|
49
54
|
function serverTimingHeader(marks) {
|
|
50
|
-
return marks.map(({ name, ms, startMs }) =>
|
|
55
|
+
return marks.map(({ name, ms, startMs }) => "".concat(name, ";dur=").concat(ms.toFixed(1), ';desc="@').concat(startMs.toFixed(1), '"')).join(", ");
|
|
51
56
|
}
|
|
52
57
|
|
|
53
58
|
// src/server/install.ts
|
|
@@ -55,14 +60,17 @@ var TRACE_HEADER = "x-den-trace";
|
|
|
55
60
|
var storage = new AsyncLocalStorage();
|
|
56
61
|
function recordServerTiming(name, ms, startedAt) {
|
|
57
62
|
const timings = storage.getStore();
|
|
58
|
-
timings
|
|
63
|
+
timings == null ? void 0 : timings.marks.push({ ms, name, startMs: (startedAt != null ? startedAt : performance.now() - ms) - timings.startedAt });
|
|
59
64
|
}
|
|
60
65
|
function asked(headers) {
|
|
61
66
|
return headers[TRACE_HEADER] !== void 0;
|
|
62
67
|
}
|
|
63
68
|
function installServerTrace(instance, options = {}) {
|
|
64
69
|
setTimingSink(recordServerTiming);
|
|
65
|
-
setRequestSink((request) =>
|
|
70
|
+
setRequestSink((request) => {
|
|
71
|
+
var _a;
|
|
72
|
+
return (_a = storage.getStore()) == null ? void 0 : _a.requests.push(request);
|
|
73
|
+
});
|
|
66
74
|
instance.addHook("onRequest", (_request, _reply, done) => {
|
|
67
75
|
storage.run({ marks: [], requests: [], startedAt: performance.now() }, done);
|
|
68
76
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@foxford/den-traces",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.0.0",
|
|
4
4
|
"description": "Метки времени, походы наружу и дев-трасса для den-приложений",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"foxford",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
],
|
|
33
33
|
"type": "module",
|
|
34
34
|
"peerDependencies": {
|
|
35
|
-
"@foxford/den": "^4.
|
|
35
|
+
"@foxford/den": "^4.2.0"
|
|
36
36
|
},
|
|
37
37
|
"main": "./index.cjs",
|
|
38
38
|
"module": "./index.js",
|
|
@@ -55,8 +55,8 @@
|
|
|
55
55
|
},
|
|
56
56
|
"files": [
|
|
57
57
|
"README.mdx",
|
|
58
|
-
"chunk-
|
|
59
|
-
"chunk-
|
|
58
|
+
"chunk-C54MGVV6.cjs",
|
|
59
|
+
"chunk-IDEPG3TX.js",
|
|
60
60
|
"index.cjs",
|
|
61
61
|
"index.d.cts",
|
|
62
62
|
"index.d.ts",
|
|
@@ -65,6 +65,6 @@
|
|
|
65
65
|
"services",
|
|
66
66
|
"timings"
|
|
67
67
|
],
|
|
68
|
-
"sha": "
|
|
68
|
+
"sha": "6bf9ff8",
|
|
69
69
|
"scripts": {}
|
|
70
70
|
}
|
package/services/index.cjs
CHANGED
|
@@ -1,37 +1,39 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
var
|
|
4
|
+
var _chunkC54MGVV6cjs = require('../chunk-C54MGVV6.cjs');
|
|
5
5
|
|
|
6
6
|
// src/services/index.ts
|
|
7
7
|
var SPAN = /* @__PURE__ */ Symbol("den-traces:span");
|
|
8
8
|
function traceNameOf(config) {
|
|
9
|
+
var _a, _b, _c;
|
|
9
10
|
if (typeof config.traceName === "string" && config.traceName !== "") {
|
|
10
11
|
return config.traceName;
|
|
11
12
|
}
|
|
12
|
-
const path =
|
|
13
|
-
return
|
|
13
|
+
const path = (_b = ((_a = config.url) != null ? _a : "").split("?")[0]) != null ? _b : "";
|
|
14
|
+
return "".concat(((_c = config.method) != null ? _c : "get").toLowerCase(), " ").concat(path);
|
|
14
15
|
}
|
|
15
16
|
function traceUrlOf(config) {
|
|
16
|
-
|
|
17
|
+
var _a;
|
|
18
|
+
const url = (_a = config.url) != null ? _a : "";
|
|
17
19
|
if (/^https?:\/\//.test(url) || !config.baseURL) {
|
|
18
20
|
return url;
|
|
19
21
|
}
|
|
20
|
-
return
|
|
22
|
+
return "".concat(config.baseURL.replace(/\/$/, ""), "/").concat(url.replace(/^\//, ""));
|
|
21
23
|
}
|
|
22
24
|
function spanOf(config) {
|
|
23
|
-
const span =
|
|
25
|
+
const span = config == null ? void 0 : config[SPAN];
|
|
24
26
|
return typeof span === "object" && span !== null ? span : void 0;
|
|
25
27
|
}
|
|
26
28
|
function lengthOf(headers) {
|
|
27
|
-
const value =
|
|
28
|
-
return
|
|
29
|
+
const value = headers == null ? void 0 : headers["content-length"];
|
|
30
|
+
return _chunkC54MGVV6cjs.contentLength.call(void 0, typeof value === "string" ? value : typeof value === "number" ? String(value) : null);
|
|
29
31
|
}
|
|
30
32
|
function createTracePlugins() {
|
|
31
33
|
return [
|
|
32
34
|
{
|
|
33
35
|
execute: (config) => {
|
|
34
|
-
config[SPAN] =
|
|
36
|
+
config[SPAN] = _chunkC54MGVV6cjs.startRequest.call(void 0, traceNameOf(config), traceUrlOf(config));
|
|
35
37
|
return Promise.resolve(config);
|
|
36
38
|
},
|
|
37
39
|
isApplicable: () => true,
|
|
@@ -40,7 +42,8 @@ function createTracePlugins() {
|
|
|
40
42
|
},
|
|
41
43
|
{
|
|
42
44
|
execute: (response) => {
|
|
43
|
-
|
|
45
|
+
var _a;
|
|
46
|
+
(_a = spanOf(response.config)) == null ? void 0 : _a.finish(response.status, lengthOf(response.headers));
|
|
44
47
|
return Promise.resolve(response);
|
|
45
48
|
},
|
|
46
49
|
isApplicable: () => true,
|
|
@@ -51,9 +54,9 @@ function createTracePlugins() {
|
|
|
51
54
|
execute: (error) => {
|
|
52
55
|
const span = spanOf(error.config);
|
|
53
56
|
if (error.response) {
|
|
54
|
-
|
|
57
|
+
span == null ? void 0 : span.finish(error.response.status, lengthOf(error.response.headers));
|
|
55
58
|
} else {
|
|
56
|
-
|
|
59
|
+
span == null ? void 0 : span.fail(error);
|
|
57
60
|
}
|
|
58
61
|
return Promise.resolve(error);
|
|
59
62
|
},
|
package/services/index.js
CHANGED
|
@@ -1,30 +1,32 @@
|
|
|
1
1
|
import {
|
|
2
2
|
contentLength,
|
|
3
3
|
startRequest
|
|
4
|
-
} from "../chunk-
|
|
4
|
+
} from "../chunk-IDEPG3TX.js";
|
|
5
5
|
|
|
6
6
|
// src/services/index.ts
|
|
7
7
|
var SPAN = /* @__PURE__ */ Symbol("den-traces:span");
|
|
8
8
|
function traceNameOf(config) {
|
|
9
|
+
var _a, _b, _c;
|
|
9
10
|
if (typeof config.traceName === "string" && config.traceName !== "") {
|
|
10
11
|
return config.traceName;
|
|
11
12
|
}
|
|
12
|
-
const path = (config.url
|
|
13
|
-
return
|
|
13
|
+
const path = (_b = ((_a = config.url) != null ? _a : "").split("?")[0]) != null ? _b : "";
|
|
14
|
+
return "".concat(((_c = config.method) != null ? _c : "get").toLowerCase(), " ").concat(path);
|
|
14
15
|
}
|
|
15
16
|
function traceUrlOf(config) {
|
|
16
|
-
|
|
17
|
+
var _a;
|
|
18
|
+
const url = (_a = config.url) != null ? _a : "";
|
|
17
19
|
if (/^https?:\/\//.test(url) || !config.baseURL) {
|
|
18
20
|
return url;
|
|
19
21
|
}
|
|
20
|
-
return
|
|
22
|
+
return "".concat(config.baseURL.replace(/\/$/, ""), "/").concat(url.replace(/^\//, ""));
|
|
21
23
|
}
|
|
22
24
|
function spanOf(config) {
|
|
23
|
-
const span = config
|
|
25
|
+
const span = config == null ? void 0 : config[SPAN];
|
|
24
26
|
return typeof span === "object" && span !== null ? span : void 0;
|
|
25
27
|
}
|
|
26
28
|
function lengthOf(headers) {
|
|
27
|
-
const value = headers
|
|
29
|
+
const value = headers == null ? void 0 : headers["content-length"];
|
|
28
30
|
return contentLength(typeof value === "string" ? value : typeof value === "number" ? String(value) : null);
|
|
29
31
|
}
|
|
30
32
|
function createTracePlugins() {
|
|
@@ -40,7 +42,8 @@ function createTracePlugins() {
|
|
|
40
42
|
},
|
|
41
43
|
{
|
|
42
44
|
execute: (response) => {
|
|
43
|
-
|
|
45
|
+
var _a;
|
|
46
|
+
(_a = spanOf(response.config)) == null ? void 0 : _a.finish(response.status, lengthOf(response.headers));
|
|
44
47
|
return Promise.resolve(response);
|
|
45
48
|
},
|
|
46
49
|
isApplicable: () => true,
|
|
@@ -51,9 +54,9 @@ function createTracePlugins() {
|
|
|
51
54
|
execute: (error) => {
|
|
52
55
|
const span = spanOf(error.config);
|
|
53
56
|
if (error.response) {
|
|
54
|
-
span
|
|
57
|
+
span == null ? void 0 : span.finish(error.response.status, lengthOf(error.response.headers));
|
|
55
58
|
} else {
|
|
56
|
-
span
|
|
59
|
+
span == null ? void 0 : span.fail(error);
|
|
57
60
|
}
|
|
58
61
|
return Promise.resolve(error);
|
|
59
62
|
},
|
package/timings/index.cjs
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
|
|
8
|
-
var
|
|
8
|
+
var _chunkC54MGVV6cjs = require('../chunk-C54MGVV6.cjs');
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
|
|
@@ -13,4 +13,4 @@ var _chunkDAPDESIHcjs = require('../chunk-DAPDESIH.cjs');
|
|
|
13
13
|
|
|
14
14
|
|
|
15
15
|
|
|
16
|
-
exports.contentLength =
|
|
16
|
+
exports.contentLength = _chunkC54MGVV6cjs.contentLength; exports.measure = _chunkC54MGVV6cjs.measure; exports.setRequestSink = _chunkC54MGVV6cjs.setRequestSink; exports.setTimingSink = _chunkC54MGVV6cjs.setTimingSink; exports.setUpstreamErrorSink = _chunkC54MGVV6cjs.setUpstreamErrorSink; exports.startRequest = _chunkC54MGVV6cjs.startRequest;
|