@vtex/api 6.45.21-beta.0 → 6.45.21-beta.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/CHANGELOG.md +7 -1
- package/lib/HttpClient/middlewares/cache.js +11 -10
- package/lib/HttpClient/middlewares/memoization.js +7 -6
- package/lib/HttpClient/middlewares/request/index.js +5 -4
- package/lib/HttpClient/middlewares/request/setupAxios/interceptors/exponentialBackoff.js +2 -1
- package/lib/HttpClient/middlewares/request/setupAxios/interceptors/tracing/index.js +8 -6
- package/lib/HttpClient/middlewares/request/setupAxios/interceptors/tracing/spanSetup.d.ts +2 -2
- package/lib/HttpClient/middlewares/request/setupAxios/interceptors/tracing/spanSetup.js +6 -6
- package/lib/HttpClient/middlewares/tracing.js +13 -11
- package/lib/HttpClient/typings.d.ts +1 -1
- package/lib/service/tracing/tracingMiddlewares.js +12 -11
- package/lib/service/worker/runtime/builtIn/handlers.js +6 -6
- package/lib/service/worker/runtime/http/middlewares/settings.js +2 -1
- package/lib/service/worker/runtime/statusTrack.js +3 -3
- package/lib/service/worker/runtime/typings.d.ts +1 -1
- package/lib/service/worker/runtime/utils/context.d.ts +1 -1
- package/lib/service/worker/runtime/utils/context.js +1 -1
- package/lib/tracing/UserLandTracer.d.ts +7 -7
- package/lib/tracing/UserLandTracer.js +7 -5
- package/lib/tracing/errorReporting/ErrorReport.d.ts +1 -1
- package/lib/tracing/errorReporting/ErrorReport.js +4 -3
- package/lib/tracing/utils.d.ts +2 -2
- package/lib/tracing/utils.js +3 -3
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [6.45.21-beta.2] - 2023-09-19
|
|
11
|
+
|
|
12
|
+
## [6.45.21-beta.1] - 2023-09-07
|
|
13
|
+
|
|
10
14
|
## [6.45.21-beta.0] - 2023-09-04
|
|
11
15
|
|
|
12
16
|
## [6.45.21-beta] - 2023-09-04
|
|
@@ -1780,11 +1784,13 @@ instead
|
|
|
1780
1784
|
- `HttpClient` now adds `'Accept-Encoding': 'gzip'` header by default.
|
|
1781
1785
|
|
|
1782
1786
|
|
|
1783
|
-
[Unreleased]: https://github.com/vtex/node-vtex-api/compare/v6.45.21-beta.
|
|
1787
|
+
[Unreleased]: https://github.com/vtex/node-vtex-api/compare/v6.45.21-beta.2...HEAD
|
|
1784
1788
|
[6.45.15]: https://github.com/vtex/node-vtex-api/compare/v6.45.14...v6.45.15
|
|
1785
1789
|
[6.45.14]: https://github.com/vtex/node-vtex-api/compare/v6.45.13...v6.45.14
|
|
1786
1790
|
[6.45.13]: https://github.com/vtex/node-vtex-api/compare/v6.45.12...v6.45.13
|
|
1787
1791
|
|
|
1792
|
+
[6.45.21-beta.2]: https://github.com/vtex/node-vtex-api/compare/v6.45.21-beta.1...v6.45.21-beta.2
|
|
1793
|
+
[6.45.21-beta.1]: https://github.com/vtex/node-vtex-api/compare/v6.45.21-beta.0...v6.45.21-beta.1
|
|
1788
1794
|
[6.45.21-beta.0]: https://github.com/vtex/node-vtex-api/compare/v6.45.21-beta...v6.45.21-beta.0
|
|
1789
1795
|
[6.45.21-beta]: https://github.com/vtex/node-vtex-api/compare/v6.45.20...v6.45.21-beta
|
|
1790
1796
|
[6.45.20]: https://github.com/vtex/node-vtex-api/compare/v6.45.20-beta...v6.45.20
|
|
@@ -55,14 +55,15 @@ exports.cacheMiddleware = ({ type, storage }) => {
|
|
|
55
55
|
const CACHE_RESULT_TAG = type === CacheType.Disk ? "http.cache.disk" /* HTTP_DISK_CACHE_RESULT */ : "http.cache.memory" /* HTTP_MEMORY_CACHE_RESULT */;
|
|
56
56
|
const cacheType = CacheTypeNames[type];
|
|
57
57
|
return async (ctx, next) => {
|
|
58
|
+
var _a;
|
|
58
59
|
if (!isLocallyCacheable(ctx.config, type)) {
|
|
59
60
|
return await next();
|
|
60
61
|
}
|
|
61
|
-
const span = ctx.tracing.rootSpan;
|
|
62
|
+
const span = (_a = ctx.tracing) === null || _a === void 0 ? void 0 : _a.rootSpan;
|
|
62
63
|
const key = exports.cacheKey(ctx.config);
|
|
63
64
|
const segmentToken = ctx.config.headers[constants_1.SEGMENT_HEADER];
|
|
64
65
|
const keyWithSegment = key + segmentToken;
|
|
65
|
-
span.log({
|
|
66
|
+
span === null || span === void 0 ? void 0 : span.log({
|
|
66
67
|
event: "cache-key-created" /* CACHE_KEY_CREATE */,
|
|
67
68
|
["cache-type" /* CACHE_TYPE */]: cacheType,
|
|
68
69
|
["key" /* KEY */]: key,
|
|
@@ -76,7 +77,7 @@ exports.cacheMiddleware = ({ type, storage }) => {
|
|
|
76
77
|
response.data = Buffer.from(response.data, responseEncoding);
|
|
77
78
|
}
|
|
78
79
|
const now = Date.now();
|
|
79
|
-
span.log({
|
|
80
|
+
span === null || span === void 0 ? void 0 : span.log({
|
|
80
81
|
event: "local-cache-hit-info" /* LOCAL_CACHE_HIT_INFO */,
|
|
81
82
|
["cache-type" /* CACHE_TYPE */]: cacheType,
|
|
82
83
|
["etag" /* ETAG */]: cachedEtag,
|
|
@@ -91,10 +92,10 @@ exports.cacheMiddleware = ({ type, storage }) => {
|
|
|
91
92
|
revalidated: 0,
|
|
92
93
|
router: 0,
|
|
93
94
|
};
|
|
94
|
-
span.setTag(CACHE_RESULT_TAG, "HIT" /* HIT */);
|
|
95
|
+
span === null || span === void 0 ? void 0 : span.setTag(CACHE_RESULT_TAG, "HIT" /* HIT */);
|
|
95
96
|
return;
|
|
96
97
|
}
|
|
97
|
-
span.setTag(CACHE_RESULT_TAG, "STALE" /* STALE */);
|
|
98
|
+
span === null || span === void 0 ? void 0 : span.setTag(CACHE_RESULT_TAG, "STALE" /* STALE */);
|
|
98
99
|
const validateStatus = addNotModified(ctx.config.validateStatus);
|
|
99
100
|
if (cachedEtag && validateStatus(response.status)) {
|
|
100
101
|
ctx.config.headers['if-none-match'] = cachedEtag;
|
|
@@ -102,7 +103,7 @@ exports.cacheMiddleware = ({ type, storage }) => {
|
|
|
102
103
|
}
|
|
103
104
|
}
|
|
104
105
|
else {
|
|
105
|
-
span.setTag(CACHE_RESULT_TAG, "MISS" /* MISS */);
|
|
106
|
+
span === null || span === void 0 ? void 0 : span.setTag(CACHE_RESULT_TAG, "MISS" /* MISS */);
|
|
106
107
|
}
|
|
107
108
|
await next();
|
|
108
109
|
if (!ctx.response) {
|
|
@@ -121,7 +122,7 @@ exports.cacheMiddleware = ({ type, storage }) => {
|
|
|
121
122
|
const { age, etag, maxAge: headerMaxAge, noStore, noCache } = parseCacheHeaders(headers);
|
|
122
123
|
const { forceMaxAge } = ctx.config;
|
|
123
124
|
const maxAge = forceMaxAge && cacheableStatusCodes.includes(status) ? Math.max(forceMaxAge, headerMaxAge) : headerMaxAge;
|
|
124
|
-
span.log({
|
|
125
|
+
span === null || span === void 0 ? void 0 : span.log({
|
|
125
126
|
event: "cache-config" /* CACHE_CONFIG */,
|
|
126
127
|
["cache-type" /* CACHE_TYPE */]: cacheType,
|
|
127
128
|
["age" /* AGE */]: age,
|
|
@@ -134,7 +135,7 @@ exports.cacheMiddleware = ({ type, storage }) => {
|
|
|
134
135
|
});
|
|
135
136
|
// Indicates this should NOT be cached and this request will not be considered a miss.
|
|
136
137
|
if (!forceMaxAge && (noStore || (noCache && !etag))) {
|
|
137
|
-
span.log({ event: "no-local-cache-save" /* NO_LOCAL_CACHE_SAVE */, ["cache-type" /* CACHE_TYPE */]: cacheType });
|
|
138
|
+
span === null || span === void 0 ? void 0 : span.log({ event: "no-local-cache-save" /* NO_LOCAL_CACHE_SAVE */, ["cache-type" /* CACHE_TYPE */]: cacheType });
|
|
138
139
|
return;
|
|
139
140
|
}
|
|
140
141
|
const shouldCache = maxAge || etag;
|
|
@@ -156,7 +157,7 @@ exports.cacheMiddleware = ({ type, storage }) => {
|
|
|
156
157
|
responseEncoding,
|
|
157
158
|
responseType,
|
|
158
159
|
});
|
|
159
|
-
span.log({
|
|
160
|
+
span === null || span === void 0 ? void 0 : span.log({
|
|
160
161
|
event: "local-cache-saved" /* LOCAL_CACHE_SAVED */,
|
|
161
162
|
["cache-type" /* CACHE_TYPE */]: cacheType,
|
|
162
163
|
["key-set" /* KEY_SET */]: setKey,
|
|
@@ -168,6 +169,6 @@ exports.cacheMiddleware = ({ type, storage }) => {
|
|
|
168
169
|
});
|
|
169
170
|
return;
|
|
170
171
|
}
|
|
171
|
-
span.log({ event: "no-local-cache-save" /* NO_LOCAL_CACHE_SAVE */, ["cache-type" /* CACHE_TYPE */]: cacheType });
|
|
172
|
+
span === null || span === void 0 ? void 0 : span.log({ event: "no-local-cache-save" /* NO_LOCAL_CACHE_SAVE */, ["cache-type" /* CACHE_TYPE */]: cacheType });
|
|
172
173
|
};
|
|
173
174
|
};
|
|
@@ -3,22 +3,23 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const cache_1 = require("./cache");
|
|
4
4
|
exports.memoizationMiddleware = ({ memoizedCache }) => {
|
|
5
5
|
return async (ctx, next) => {
|
|
6
|
+
var _a;
|
|
6
7
|
if (!cache_1.isLocallyCacheable(ctx.config, cache_1.CacheType.Any) || !ctx.config.memoizable) {
|
|
7
8
|
return next();
|
|
8
9
|
}
|
|
9
|
-
const span = ctx.tracing.rootSpan;
|
|
10
|
+
const span = (_a = ctx.tracing) === null || _a === void 0 ? void 0 : _a.rootSpan;
|
|
10
11
|
const key = cache_1.cacheKey(ctx.config);
|
|
11
12
|
const isMemoized = !!memoizedCache.has(key);
|
|
12
|
-
span.log({ event: "cache-key-created" /* CACHE_KEY_CREATE */, ["cache-type" /* CACHE_TYPE */]: 'memoization', ["key" /* KEY */]: key });
|
|
13
|
+
span === null || span === void 0 ? void 0 : span.log({ event: "cache-key-created" /* CACHE_KEY_CREATE */, ["cache-type" /* CACHE_TYPE */]: 'memoization', ["key" /* KEY */]: key });
|
|
13
14
|
if (isMemoized) {
|
|
14
|
-
span.setTag("http.cache.memoization" /* HTTP_MEMOIZATION_CACHE_RESULT */, "HIT" /* HIT */);
|
|
15
|
+
span === null || span === void 0 ? void 0 : span.setTag("http.cache.memoization" /* HTTP_MEMOIZATION_CACHE_RESULT */, "HIT" /* HIT */);
|
|
15
16
|
const memoized = await memoizedCache.get(key);
|
|
16
17
|
ctx.memoizedHit = isMemoized;
|
|
17
18
|
ctx.response = memoized.response;
|
|
18
19
|
return;
|
|
19
20
|
}
|
|
20
21
|
else {
|
|
21
|
-
span.setTag("http.cache.memoization" /* HTTP_MEMOIZATION_CACHE_RESULT */, "MISS" /* MISS */);
|
|
22
|
+
span === null || span === void 0 ? void 0 : span.setTag("http.cache.memoization" /* HTTP_MEMOIZATION_CACHE_RESULT */, "MISS" /* MISS */);
|
|
22
23
|
const promise = new Promise(async (resolve, reject) => {
|
|
23
24
|
try {
|
|
24
25
|
await next();
|
|
@@ -26,11 +27,11 @@ exports.memoizationMiddleware = ({ memoizedCache }) => {
|
|
|
26
27
|
cacheHit: ctx.cacheHit,
|
|
27
28
|
response: ctx.response,
|
|
28
29
|
});
|
|
29
|
-
span.log({ event: "memoization-cache-saved" /* MEMOIZATION_CACHE_SAVED */, ["key-set" /* KEY_SET */]: key });
|
|
30
|
+
span === null || span === void 0 ? void 0 : span.log({ event: "memoization-cache-saved" /* MEMOIZATION_CACHE_SAVED */, ["key-set" /* KEY_SET */]: key });
|
|
30
31
|
}
|
|
31
32
|
catch (err) {
|
|
32
33
|
reject(err);
|
|
33
|
-
span.log({ event: "memoization-cache-saved-error" /* MEMOIZATION_CACHE_SAVED_ERROR */, ["key-set" /* KEY_SET */]: key });
|
|
34
|
+
span === null || span === void 0 ? void 0 : span.log({ event: "memoization-cache-saved-error" /* MEMOIZATION_CACHE_SAVED_ERROR */, ["key-set" /* KEY_SET */]: key });
|
|
34
35
|
}
|
|
35
36
|
});
|
|
36
37
|
memoizedCache.set(key, promise);
|
|
@@ -17,6 +17,7 @@ exports.defaultsMiddleware = ({ baseURL, rawHeaders, params, timeout, retries, v
|
|
|
17
17
|
const countByMetric = {};
|
|
18
18
|
const headers = renameBy_1.renameBy(ramda_1.toLower, rawHeaders);
|
|
19
19
|
return (ctx, next) => {
|
|
20
|
+
var _a, _b, _c;
|
|
20
21
|
ctx.config = {
|
|
21
22
|
baseURL,
|
|
22
23
|
exponentialBackoffCoefficient,
|
|
@@ -46,10 +47,10 @@ exports.defaultsMiddleware = ({ baseURL, rawHeaders, params, timeout, retries, v
|
|
|
46
47
|
ctx.config.count = countByMetric[ctx.config.metric];
|
|
47
48
|
ctx.config.label = `${ctx.config.metric}#${ctx.config.count}`;
|
|
48
49
|
}
|
|
49
|
-
if (ctx.tracing.isSampled) {
|
|
50
|
+
if ((_a = ctx.tracing) === null || _a === void 0 ? void 0 : _a.isSampled) {
|
|
50
51
|
const { config } = ctx;
|
|
51
52
|
const fullUrl = buildFullPath_1.default(config.baseURL, http.getUri(config));
|
|
52
|
-
ctx.tracing.rootSpan.addTags({
|
|
53
|
+
(_c = (_b = ctx.tracing) === null || _b === void 0 ? void 0 : _b.rootSpan) === null || _c === void 0 ? void 0 : _c.addTags({
|
|
53
54
|
[Tags_1.OpentracingTags.HTTP_METHOD]: config.method || 'get',
|
|
54
55
|
[Tags_1.OpentracingTags.HTTP_URL]: fullUrl,
|
|
55
56
|
});
|
|
@@ -61,12 +62,12 @@ const ROUTER_CACHE_KEY = 'x-router-cache';
|
|
|
61
62
|
const ROUTER_CACHE_HIT = 'HIT';
|
|
62
63
|
const ROUTER_CACHE_REVALIDATED = 'REVALIDATED';
|
|
63
64
|
exports.routerCacheMiddleware = async (ctx, next) => {
|
|
64
|
-
var _a, _b, _c;
|
|
65
|
+
var _a, _b, _c, _d, _e;
|
|
65
66
|
await next();
|
|
66
67
|
const routerCacheHit = (_b = (_a = ctx.response) === null || _a === void 0 ? void 0 : _a.headers) === null || _b === void 0 ? void 0 : _b[ROUTER_CACHE_KEY];
|
|
67
68
|
const status = (_c = ctx.response) === null || _c === void 0 ? void 0 : _c.status;
|
|
68
69
|
if (routerCacheHit) {
|
|
69
|
-
ctx.tracing.rootSpan.setTag("http.cache.router" /* HTTP_ROUTER_CACHE_RESULT */, routerCacheHit);
|
|
70
|
+
(_e = (_d = ctx.tracing) === null || _d === void 0 ? void 0 : _d.rootSpan) === null || _e === void 0 ? void 0 : _e.setTag("http.cache.router" /* HTTP_ROUTER_CACHE_RESULT */, routerCacheHit);
|
|
70
71
|
}
|
|
71
72
|
if (routerCacheHit === ROUTER_CACHE_HIT || (routerCacheHit === ROUTER_CACHE_REVALIDATED && status !== 304)) {
|
|
72
73
|
ctx.cacheHit = {
|
|
@@ -18,6 +18,7 @@ const exponentialDelay = (initialBackoffDelay, exponentialBackoffCoefficient, re
|
|
|
18
18
|
// A lot of this code is based on:
|
|
19
19
|
// https://github.com/softonic/axios-retry/blob/ffd4327f31d063522e58c525d28d4c5053d0ea7b/es/index.js#L109
|
|
20
20
|
const onResponseError = (http) => (error) => {
|
|
21
|
+
var _a, _b;
|
|
21
22
|
if (error.config == null) {
|
|
22
23
|
return Promise.reject(error);
|
|
23
24
|
}
|
|
@@ -38,7 +39,7 @@ const onResponseError = (http) => (error) => {
|
|
|
38
39
|
? config.timeout * exponentialTimeoutCoefficient
|
|
39
40
|
: config.timeout;
|
|
40
41
|
config.transformRequest = [data => data];
|
|
41
|
-
config.tracing.rootSpan.log({ event: "setup-request-retry" /* SETUP_REQUEST_RETRY */, ["retry-number" /* RETRY_NUMBER */]: config.retryCount, ["retry-in" /* RETRY_IN */]: delay });
|
|
42
|
+
(_b = (_a = config.tracing) === null || _a === void 0 ? void 0 : _a.rootSpan) === null || _b === void 0 ? void 0 : _b.log({ event: "setup-request-retry" /* SETUP_REQUEST_RETRY */, ["retry-number" /* RETRY_NUMBER */]: config.retryCount, ["retry-in" /* RETRY_IN */]: delay });
|
|
42
43
|
return new Promise(resolve => setTimeout(() => resolve(http(config)), delay));
|
|
43
44
|
}
|
|
44
45
|
return Promise.reject(error);
|
|
@@ -6,7 +6,8 @@ const SpanReferenceTypes_1 = require("../../../../../../tracing/spanReference/Sp
|
|
|
6
6
|
const spanSetup_1 = require("./spanSetup");
|
|
7
7
|
exports.requestSpanPrefix = 'http-request';
|
|
8
8
|
const preRequestInterceptor = (http) => (config) => {
|
|
9
|
-
|
|
9
|
+
var _a;
|
|
10
|
+
if (!config.tracing || !((_a = config.tracing) === null || _a === void 0 ? void 0 : _a.isSampled)) {
|
|
10
11
|
return config;
|
|
11
12
|
}
|
|
12
13
|
const { tracer, rootSpan, requestSpanNameSuffix } = config.tracing;
|
|
@@ -22,17 +23,18 @@ const preRequestInterceptor = (http) => (config) => {
|
|
|
22
23
|
return config;
|
|
23
24
|
};
|
|
24
25
|
const onResponseSuccess = (response) => {
|
|
25
|
-
|
|
26
|
+
var _a, _b;
|
|
27
|
+
if (!response.config.tracing || !((_a = response.config.tracing) === null || _a === void 0 ? void 0 : _a.isSampled)) {
|
|
26
28
|
return response;
|
|
27
29
|
}
|
|
28
|
-
const requestSpan = response.config.tracing.requestSpan;
|
|
30
|
+
const requestSpan = (_b = response.config.tracing) === null || _b === void 0 ? void 0 : _b.requestSpan;
|
|
29
31
|
spanSetup_1.injectResponseInfoOnSpan(requestSpan, response);
|
|
30
|
-
requestSpan.finish();
|
|
32
|
+
requestSpan === null || requestSpan === void 0 ? void 0 : requestSpan.finish();
|
|
31
33
|
return response;
|
|
32
34
|
};
|
|
33
35
|
const onResponseError = (err) => {
|
|
34
|
-
var _a, _b;
|
|
35
|
-
if (!((_b = (_a = err === null || err === void 0 ? void 0 : err.config) === null || _a === void 0 ? void 0 : _a.tracing) === null || _b === void 0 ? void 0 : _b.requestSpan) || !err.config.tracing.isSampled) {
|
|
36
|
+
var _a, _b, _c;
|
|
37
|
+
if (!((_b = (_a = err === null || err === void 0 ? void 0 : err.config) === null || _a === void 0 ? void 0 : _a.tracing) === null || _b === void 0 ? void 0 : _b.requestSpan) || !((_c = err.config.tracing) === null || _c === void 0 ? void 0 : _c.isSampled)) {
|
|
36
38
|
return Promise.reject(err);
|
|
37
39
|
}
|
|
38
40
|
const { requestSpan } = err.config.tracing;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios';
|
|
2
2
|
import { Span } from 'opentracing';
|
|
3
|
-
export declare const injectRequestInfoOnSpan: (span: Span, http: AxiosInstance, config: AxiosRequestConfig) => void;
|
|
4
|
-
export declare const injectResponseInfoOnSpan: (span: Span, response: AxiosResponse<any> | undefined) => void;
|
|
3
|
+
export declare const injectRequestInfoOnSpan: (span: Span | undefined, http: AxiosInstance, config: AxiosRequestConfig) => void;
|
|
4
|
+
export declare const injectResponseInfoOnSpan: (span: Span | undefined, response: AxiosResponse<any> | undefined) => void;
|
|
@@ -8,22 +8,22 @@ const constants_1 = require("../../../../../../constants");
|
|
|
8
8
|
const Tags_1 = require("../../../../../../tracing/Tags");
|
|
9
9
|
const utils_1 = require("../../../../../../tracing/utils");
|
|
10
10
|
exports.injectRequestInfoOnSpan = (span, http, config) => {
|
|
11
|
-
span.addTags({
|
|
11
|
+
span === null || span === void 0 ? void 0 : span.addTags({
|
|
12
12
|
[Tags_1.OpentracingTags.SPAN_KIND]: Tags_1.OpentracingTags.SPAN_KIND_RPC_CLIENT,
|
|
13
13
|
[Tags_1.OpentracingTags.HTTP_METHOD]: config.method,
|
|
14
14
|
[Tags_1.OpentracingTags.HTTP_URL]: buildFullPath_1.default(config.baseURL, http.getUri(config)),
|
|
15
15
|
});
|
|
16
|
-
span.log({ 'request-headers': utils_1.cloneAndSanitizeHeaders(config.headers) });
|
|
16
|
+
span === null || span === void 0 ? void 0 : span.log({ 'request-headers': utils_1.cloneAndSanitizeHeaders(config.headers) });
|
|
17
17
|
};
|
|
18
18
|
// Response may be undefined in case of client timeout, invalid URL, ...
|
|
19
19
|
exports.injectResponseInfoOnSpan = (span, response) => {
|
|
20
20
|
if (!response) {
|
|
21
|
-
span.setTag("http.no_response" /* HTTP_NO_RESPONSE */, 'true');
|
|
21
|
+
span === null || span === void 0 ? void 0 : span.setTag("http.no_response" /* HTTP_NO_RESPONSE */, 'true');
|
|
22
22
|
return;
|
|
23
23
|
}
|
|
24
|
-
span.log({ 'response-headers': utils_1.cloneAndSanitizeHeaders(response.headers) });
|
|
25
|
-
span.setTag(Tags_1.OpentracingTags.HTTP_STATUS_CODE, response.status);
|
|
24
|
+
span === null || span === void 0 ? void 0 : span.log({ 'response-headers': utils_1.cloneAndSanitizeHeaders(response.headers) });
|
|
25
|
+
span === null || span === void 0 ? void 0 : span.setTag(Tags_1.OpentracingTags.HTTP_STATUS_CODE, response.status);
|
|
26
26
|
if (response.headers[constants_1.ROUTER_CACHE_HEADER]) {
|
|
27
|
-
span.setTag("http.cache.router" /* HTTP_ROUTER_CACHE_RESULT */, response.headers[constants_1.ROUTER_CACHE_HEADER]);
|
|
27
|
+
span === null || span === void 0 ? void 0 : span.setTag("http.cache.router" /* HTTP_ROUTER_CACHE_RESULT */, response.headers[constants_1.ROUTER_CACHE_HEADER]);
|
|
28
28
|
}
|
|
29
29
|
};
|
|
@@ -5,13 +5,15 @@ const Tags_1 = require("../../tracing/Tags");
|
|
|
5
5
|
const cache_1 = require("./cache");
|
|
6
6
|
exports.createHttpClientTracingMiddleware = ({ tracer, logger, clientName, hasMemoryCacheMiddleware, hasDiskCacheMiddleware, }) => {
|
|
7
7
|
return async function tracingMiddleware(ctx, next) {
|
|
8
|
-
|
|
8
|
+
var _a;
|
|
9
|
+
if (!tracer.isTraceSampled) {
|
|
10
|
+
await next();
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
const rootSpan = tracer.fallbackSpanContext();
|
|
14
|
+
const { requestSpanNameSuffix } = ctx.config.tracing || {};
|
|
9
15
|
const spanName = requestSpanNameSuffix ? `request:${requestSpanNameSuffix}` : 'request';
|
|
10
|
-
const span = rootSpan
|
|
11
|
-
? tracer.startSpan(spanName, {
|
|
12
|
-
references: [tracing_1.createSpanReference(rootSpan, referenceType)],
|
|
13
|
-
})
|
|
14
|
-
: tracer.startSpan(spanName);
|
|
16
|
+
const span = tracer.startSpan(spanName, { childOf: rootSpan });
|
|
15
17
|
ctx.tracing = {
|
|
16
18
|
...ctx.config.tracing,
|
|
17
19
|
isSampled: tracing_1.getTraceInfo(span).isSampled,
|
|
@@ -23,7 +25,7 @@ exports.createHttpClientTracingMiddleware = ({ tracer, logger, clientName, hasMe
|
|
|
23
25
|
const hasMemoCache = !(!cache_1.isLocallyCacheable(ctx.config, cache_1.CacheType.Any) || !ctx.config.memoizable);
|
|
24
26
|
const hasMemoryCache = hasMemoryCacheMiddleware && !!cache_1.isLocallyCacheable(ctx.config, cache_1.CacheType.Memory);
|
|
25
27
|
const hasDiskCache = hasDiskCacheMiddleware && !!cache_1.isLocallyCacheable(ctx.config, cache_1.CacheType.Disk);
|
|
26
|
-
span.addTags({
|
|
28
|
+
span === null || span === void 0 ? void 0 : span.addTags({
|
|
27
29
|
["http.cache.memoization.enabled" /* HTTP_MEMOIZATION_CACHE_ENABLED */]: hasMemoCache,
|
|
28
30
|
["http.cache.memory.enabled" /* HTTP_MEMORY_CACHE_ENABLED */]: hasMemoryCache,
|
|
29
31
|
["http.cache.disk.enabled" /* HTTP_DISK_CACHE_ENABLED */]: hasDiskCache,
|
|
@@ -36,19 +38,19 @@ exports.createHttpClientTracingMiddleware = ({ tracer, logger, clientName, hasMe
|
|
|
36
38
|
}
|
|
37
39
|
catch (err) {
|
|
38
40
|
response = err.response;
|
|
39
|
-
if (ctx.tracing.isSampled) {
|
|
41
|
+
if ((_a = ctx.tracing) === null || _a === void 0 ? void 0 : _a.isSampled) {
|
|
40
42
|
tracing_1.ErrorReport.create({ originalError: err }).injectOnSpan(span, logger);
|
|
41
43
|
}
|
|
42
44
|
throw err;
|
|
43
45
|
}
|
|
44
46
|
finally {
|
|
45
47
|
if (response) {
|
|
46
|
-
span.setTag(Tags_1.OpentracingTags.HTTP_STATUS_CODE, response.status);
|
|
48
|
+
span === null || span === void 0 ? void 0 : span.setTag(Tags_1.OpentracingTags.HTTP_STATUS_CODE, response.status);
|
|
47
49
|
}
|
|
48
50
|
else {
|
|
49
|
-
span.setTag("http.no_response" /* HTTP_NO_RESPONSE */, true);
|
|
51
|
+
span === null || span === void 0 ? void 0 : span.setTag("http.no_response" /* HTTP_NO_RESPONSE */, true);
|
|
50
52
|
}
|
|
51
|
-
span.finish();
|
|
53
|
+
span === null || span === void 0 ? void 0 : span.finish();
|
|
52
54
|
}
|
|
53
55
|
};
|
|
54
56
|
};
|
|
@@ -57,7 +57,7 @@ export interface CacheHit {
|
|
|
57
57
|
export interface MiddlewaresTracingContext extends Omit<RequestTracingUserConfig, 'rootSpan'> {
|
|
58
58
|
tracer: IUserLandTracer;
|
|
59
59
|
logger: IOContext['logger'];
|
|
60
|
-
rootSpan
|
|
60
|
+
rootSpan?: Span;
|
|
61
61
|
isSampled: boolean;
|
|
62
62
|
}
|
|
63
63
|
export interface MiddlewareContext {
|
|
@@ -20,6 +20,7 @@ exports.addTracingMiddleware = (tracer) => {
|
|
|
20
20
|
const start = process.hrtime();
|
|
21
21
|
concurrentRequests.inc(1);
|
|
22
22
|
const rootSpan = tracer.extract(opentracing_1.FORMAT_HTTP_HEADERS, ctx.request.headers);
|
|
23
|
+
ctx.tracing = { tracer, currentSpan: undefined };
|
|
23
24
|
if (!shouldTrace(ctx, rootSpan)) {
|
|
24
25
|
await next();
|
|
25
26
|
concurrentRequests.dec(1);
|
|
@@ -51,11 +52,11 @@ exports.addTracingMiddleware = (tracer) => {
|
|
|
51
52
|
["status_code" /* STATUS_CODE */]: ctx.response.status,
|
|
52
53
|
}, 1);
|
|
53
54
|
const traceInfo = tracing_1.getTraceInfo(currentSpan);
|
|
54
|
-
if (traceInfo.isSampled) {
|
|
55
|
+
if (traceInfo === null || traceInfo === void 0 ? void 0 : traceInfo.isSampled) {
|
|
55
56
|
if (!initialSamplingDecision) {
|
|
56
|
-
currentSpan.setTag(Tags_1.OpentracingTags.SPAN_KIND, Tags_1.OpentracingTags.SPAN_KIND_RPC_SERVER);
|
|
57
|
+
currentSpan === null || currentSpan === void 0 ? void 0 : currentSpan.setTag(Tags_1.OpentracingTags.SPAN_KIND, Tags_1.OpentracingTags.SPAN_KIND_RPC_SERVER);
|
|
57
58
|
}
|
|
58
|
-
currentSpan.addTags({
|
|
59
|
+
currentSpan === null || currentSpan === void 0 ? void 0 : currentSpan.addTags({
|
|
59
60
|
[Tags_1.OpentracingTags.HTTP_URL]: ctx.request.href,
|
|
60
61
|
[Tags_1.OpentracingTags.HTTP_METHOD]: ctx.request.method,
|
|
61
62
|
[Tags_1.OpentracingTags.HTTP_STATUS_CODE]: ctx.response.status,
|
|
@@ -64,8 +65,8 @@ exports.addTracingMiddleware = (tracer) => {
|
|
|
64
65
|
["vtex.incoming.workspace" /* VTEX_WORKSPACE */]: ctx.get(constants_1.WORKSPACE_HEADER),
|
|
65
66
|
["vtex.incoming.account" /* VTEX_ACCOUNT */]: ctx.get(constants_1.ACCOUNT_HEADER),
|
|
66
67
|
});
|
|
67
|
-
currentSpan.log(utils_1.cloneAndSanitizeHeaders(ctx.request.headers, 'req.headers.'));
|
|
68
|
-
currentSpan.log(utils_1.cloneAndSanitizeHeaders(ctx.response.headers, 'res.headers.'));
|
|
68
|
+
currentSpan === null || currentSpan === void 0 ? void 0 : currentSpan.log(utils_1.cloneAndSanitizeHeaders(ctx.request.headers, 'req.headers.'));
|
|
69
|
+
currentSpan === null || currentSpan === void 0 ? void 0 : currentSpan.log(utils_1.cloneAndSanitizeHeaders(ctx.response.headers, 'res.headers.'));
|
|
69
70
|
ctx.set(constants_1.TRACE_ID_HEADER, traceInfo.traceId);
|
|
70
71
|
}
|
|
71
72
|
const onResFinished = () => {
|
|
@@ -73,7 +74,7 @@ exports.addTracingMiddleware = (tracer) => {
|
|
|
73
74
|
["handler" /* REQUEST_HANDLER */]: currentSpan.operationName,
|
|
74
75
|
}, utils_2.hrToMillisFloat(process.hrtime(start)));
|
|
75
76
|
concurrentRequests.dec(1);
|
|
76
|
-
currentSpan.finish();
|
|
77
|
+
currentSpan === null || currentSpan === void 0 ? void 0 : currentSpan.finish();
|
|
77
78
|
};
|
|
78
79
|
if (responseClosed) {
|
|
79
80
|
onResFinished();
|
|
@@ -86,8 +87,8 @@ exports.addTracingMiddleware = (tracer) => {
|
|
|
86
87
|
};
|
|
87
88
|
exports.nameSpanOperationMiddleware = (operationType, operationName) => {
|
|
88
89
|
return function nameSpanOperation(ctx, next) {
|
|
89
|
-
var _a;
|
|
90
|
-
(_a = ctx.tracing) === null || _a === void 0 ? void 0 : _a.currentSpan.setOperationName(`${operationType}:${operationName}`);
|
|
90
|
+
var _a, _b;
|
|
91
|
+
(_b = (_a = ctx.tracing) === null || _a === void 0 ? void 0 : _a.currentSpan) === null || _b === void 0 ? void 0 : _b.setOperationName(`${operationType}:${operationName}`);
|
|
91
92
|
return next();
|
|
92
93
|
};
|
|
93
94
|
};
|
|
@@ -95,13 +96,13 @@ exports.traceUserLandRemainingPipelineMiddleware = () => {
|
|
|
95
96
|
return async function traceUserLandRemainingPipeline(ctx, next) {
|
|
96
97
|
const tracingCtx = ctx.tracing;
|
|
97
98
|
ctx.tracing = undefined;
|
|
98
|
-
const span = tracingCtx.currentSpan;
|
|
99
|
+
const span = tracingCtx === null || tracingCtx === void 0 ? void 0 : tracingCtx.currentSpan;
|
|
99
100
|
const userLandTracer = ctx.vtex.tracer;
|
|
100
101
|
userLandTracer.setFallbackSpan(span);
|
|
101
102
|
userLandTracer.lockFallbackSpan();
|
|
102
103
|
const startTime = process.hrtime();
|
|
103
104
|
try {
|
|
104
|
-
span.log({ event: "user-middlewares-start" /* USER_MIDDLEWARES_START */ });
|
|
105
|
+
span === null || span === void 0 ? void 0 : span.log({ event: "user-middlewares-start" /* USER_MIDDLEWARES_START */ });
|
|
105
106
|
await next();
|
|
106
107
|
}
|
|
107
108
|
catch (err) {
|
|
@@ -109,7 +110,7 @@ exports.traceUserLandRemainingPipelineMiddleware = () => {
|
|
|
109
110
|
throw err;
|
|
110
111
|
}
|
|
111
112
|
finally {
|
|
112
|
-
span.log({
|
|
113
|
+
span === null || span === void 0 ? void 0 : span.log({
|
|
113
114
|
event: "user-middlewares-finish" /* USER_MIDDLEWARES_FINISH */,
|
|
114
115
|
["user-middlewares-duration" /* USER_MIDDLEWARES_DURATION */]: utils_2.hrToMillis(process.hrtime(startTime)),
|
|
115
116
|
});
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.whoAmIHandler = ({ events, routes, }) => (ctx) => {
|
|
4
|
-
var _a;
|
|
5
|
-
(_a = ctx.tracing) === null || _a === void 0 ? void 0 : _a.currentSpan.setOperationName('builtin:whoami');
|
|
4
|
+
var _a, _b;
|
|
5
|
+
(_b = (_a = ctx.tracing) === null || _a === void 0 ? void 0 : _a.currentSpan) === null || _b === void 0 ? void 0 : _b.setOperationName('builtin:whoami');
|
|
6
6
|
ctx.status = 200;
|
|
7
7
|
ctx.body = {
|
|
8
8
|
events,
|
|
@@ -11,8 +11,8 @@ exports.whoAmIHandler = ({ events, routes, }) => (ctx) => {
|
|
|
11
11
|
ctx.set('Cache-Control', 'public, max-age=86400'); // cache for 24 hours
|
|
12
12
|
};
|
|
13
13
|
exports.healthcheckHandler = ({ events, routes, }) => (ctx) => {
|
|
14
|
-
var _a;
|
|
15
|
-
(_a = ctx.tracing) === null || _a === void 0 ? void 0 : _a.currentSpan.setOperationName('builtin:healthcheck');
|
|
14
|
+
var _a, _b;
|
|
15
|
+
(_b = (_a = ctx.tracing) === null || _a === void 0 ? void 0 : _a.currentSpan) === null || _b === void 0 ? void 0 : _b.setOperationName('builtin:healthcheck');
|
|
16
16
|
ctx.status = 200;
|
|
17
17
|
ctx.body = {
|
|
18
18
|
events,
|
|
@@ -20,8 +20,8 @@ exports.healthcheckHandler = ({ events, routes, }) => (ctx) => {
|
|
|
20
20
|
};
|
|
21
21
|
};
|
|
22
22
|
exports.metricsLoggerHandler = (ctx) => {
|
|
23
|
-
var _a;
|
|
24
|
-
(_a = ctx.tracing) === null || _a === void 0 ? void 0 : _a.currentSpan.setOperationName('builtin:metrics-logger');
|
|
23
|
+
var _a, _b;
|
|
24
|
+
(_b = (_a = ctx.tracing) === null || _a === void 0 ? void 0 : _a.currentSpan) === null || _b === void 0 ? void 0 : _b.setOperationName('builtin:metrics-logger');
|
|
25
25
|
ctx.status = 200;
|
|
26
26
|
ctx.body = ctx.metricsLogger.getSummaries();
|
|
27
27
|
};
|
|
@@ -33,8 +33,9 @@ exports.getDependenciesSettings = async (apps, assets, tracingConfig) => {
|
|
|
33
33
|
};
|
|
34
34
|
exports.getServiceSettings = () => {
|
|
35
35
|
return async function settingsContext(ctx, next) {
|
|
36
|
+
var _a;
|
|
36
37
|
const { clients: { apps, assets }, } = ctx;
|
|
37
|
-
const rootSpan = ctx.tracing.currentSpan;
|
|
38
|
+
const rootSpan = (_a = ctx.tracing) === null || _a === void 0 ? void 0 : _a.currentSpan;
|
|
38
39
|
const dependenciesSettings = await exports.getDependenciesSettings(apps, assets, { tracing: { rootSpan } });
|
|
39
40
|
// TODO: for now returning all settings, but the ideia is to do merge
|
|
40
41
|
ctx.vtex.settings = dependenciesSettings;
|
|
@@ -10,10 +10,10 @@ const STATUS_TRACK = 'statusTrack';
|
|
|
10
10
|
exports.isStatusTrack = (message) => message === STATUS_TRACK;
|
|
11
11
|
exports.isStatusTrackBroadcast = (message) => message === BROADCAST_STATUS_TRACK;
|
|
12
12
|
exports.statusTrackHandler = async (ctx) => {
|
|
13
|
-
var _a, _b;
|
|
14
|
-
(_a = ctx.tracing) === null || _a === void 0 ? void 0 : _a.currentSpan.setOperationName('builtin:status-track');
|
|
13
|
+
var _a, _b, _c;
|
|
14
|
+
(_b = (_a = ctx.tracing) === null || _a === void 0 ? void 0 : _a.currentSpan) === null || _b === void 0 ? void 0 : _b.setOperationName('builtin:status-track');
|
|
15
15
|
if (!constants_1.LINKED) {
|
|
16
|
-
(
|
|
16
|
+
(_c = process.send) === null || _c === void 0 ? void 0 : _c.call(process, BROADCAST_STATUS_TRACK);
|
|
17
17
|
}
|
|
18
18
|
ctx.body = [];
|
|
19
19
|
return;
|
|
@@ -21,7 +21,7 @@ declare type ServerTiming = Record<string, string>;
|
|
|
21
21
|
export declare type Maybe<T> = T | null | undefined;
|
|
22
22
|
export interface TracingContext {
|
|
23
23
|
tracer: Tracer;
|
|
24
|
-
currentSpan: Span;
|
|
24
|
+
currentSpan: Span | undefined;
|
|
25
25
|
}
|
|
26
26
|
export interface Context<T extends IOClients> {
|
|
27
27
|
clients: T;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { IOContext, TracingContext } from '../typings';
|
|
2
|
-
export declare const prepareHandlerCtx: (header: any, tracingContext
|
|
2
|
+
export declare const prepareHandlerCtx: (header: any, tracingContext?: TracingContext | undefined) => Pick<IOContext, "host" | "serverTiming" | "locale" | "account" | "workspace" | "region" | "logger" | "requestId" | "operationId" | "production" | "platform" | "authToken" | "adminUserAuthToken" | "storeUserAuthToken" | "product" | "recorder" | "userAgent" | "segmentToken" | "sessionToken" | "janusEnv" | "eventInfo" | "tenant" | "binding" | "cancellation" | "settings" | "tracer">;
|
|
@@ -29,7 +29,7 @@ exports.prepareHandlerCtx = (header, tracingContext) => {
|
|
|
29
29
|
segmentToken: header[constants_1.SEGMENT_HEADER],
|
|
30
30
|
sessionToken: header[constants_1.SESSION_HEADER],
|
|
31
31
|
tenant: header[constants_1.TENANT_HEADER] ? tenant_1.parseTenantHeaderValue(header[constants_1.TENANT_HEADER]) : undefined,
|
|
32
|
-
tracer: new UserLandTracer_1.UserLandTracer(tracingContext.tracer, tracingContext.currentSpan),
|
|
32
|
+
tracer: new UserLandTracer_1.UserLandTracer(tracingContext === null || tracingContext === void 0 ? void 0 : tracingContext.tracer, tracingContext === null || tracingContext === void 0 ? void 0 : tracingContext.currentSpan),
|
|
33
33
|
userAgent: process.env.VTEX_APP_ID || '',
|
|
34
34
|
workspace: header[constants_1.WORKSPACE_HEADER],
|
|
35
35
|
};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { Span, SpanContext, SpanOptions, Tracer } from 'opentracing';
|
|
2
2
|
export interface IUserLandTracer {
|
|
3
|
-
traceId
|
|
3
|
+
traceId?: string;
|
|
4
4
|
isTraceSampled: boolean;
|
|
5
5
|
startSpan: Tracer['startSpan'];
|
|
6
6
|
inject: Tracer['inject'];
|
|
7
|
-
fallbackSpanContext: () => SpanContext;
|
|
7
|
+
fallbackSpanContext: () => SpanContext | undefined;
|
|
8
8
|
}
|
|
9
9
|
export declare const createTracingContextFromCarrier: (newSpanName: string, carrier: Record<string, any>) => {
|
|
10
10
|
span: Span;
|
|
@@ -15,13 +15,13 @@ export declare class UserLandTracer implements IUserLandTracer {
|
|
|
15
15
|
private fallbackSpan;
|
|
16
16
|
private fallbackSpanLock;
|
|
17
17
|
private _isSampled;
|
|
18
|
-
private _traceId
|
|
19
|
-
constructor(tracer: Tracer, fallbackSpan
|
|
20
|
-
get traceId(): string;
|
|
18
|
+
private _traceId?;
|
|
19
|
+
constructor(tracer: Tracer, fallbackSpan?: Span);
|
|
20
|
+
get traceId(): string | undefined;
|
|
21
21
|
get isTraceSampled(): boolean;
|
|
22
22
|
lockFallbackSpan(): void;
|
|
23
|
-
setFallbackSpan(newSpan
|
|
23
|
+
setFallbackSpan(newSpan?: Span): void;
|
|
24
24
|
startSpan(name: string, options?: SpanOptions): Span;
|
|
25
25
|
inject(spanContext: SpanContext | Span, format: string, carrier: any): void;
|
|
26
|
-
fallbackSpanContext(): SpanContext;
|
|
26
|
+
fallbackSpanContext(): SpanContext | undefined;
|
|
27
27
|
}
|
|
@@ -39,17 +39,19 @@ class UserLandTracer {
|
|
|
39
39
|
this.fallbackSpan = newSpan;
|
|
40
40
|
}
|
|
41
41
|
startSpan(name, options) {
|
|
42
|
-
var _a;
|
|
42
|
+
var _a, _b, _c;
|
|
43
43
|
if (options && (options.childOf || ((_a = options.references) === null || _a === void 0 ? void 0 : _a.length))) {
|
|
44
|
-
return this.tracer.startSpan(name, options);
|
|
44
|
+
return (_b = this.tracer) === null || _b === void 0 ? void 0 : _b.startSpan(name, options);
|
|
45
45
|
}
|
|
46
|
-
return this.tracer.startSpan(name, { ...options, childOf: this.fallbackSpan });
|
|
46
|
+
return (_c = this.tracer) === null || _c === void 0 ? void 0 : _c.startSpan(name, { ...options, childOf: this.fallbackSpan });
|
|
47
47
|
}
|
|
48
48
|
inject(spanContext, format, carrier) {
|
|
49
|
-
|
|
49
|
+
var _a;
|
|
50
|
+
return (_a = this.tracer) === null || _a === void 0 ? void 0 : _a.inject(spanContext, format, carrier);
|
|
50
51
|
}
|
|
51
52
|
fallbackSpanContext() {
|
|
52
|
-
|
|
53
|
+
var _a;
|
|
54
|
+
return (_a = this.fallbackSpan) === null || _a === void 0 ? void 0 : _a.context();
|
|
53
55
|
}
|
|
54
56
|
}
|
|
55
57
|
exports.UserLandTracer = UserLandTracer;
|
|
@@ -26,6 +26,6 @@ export declare class ErrorReport extends ErrorReportBase {
|
|
|
26
26
|
* instance on the provided Span. If a logger is provided and the
|
|
27
27
|
* span is part of a **sampled** trace, then the error will be logged.
|
|
28
28
|
*/
|
|
29
|
-
injectOnSpan(span
|
|
29
|
+
injectOnSpan(span?: Span, logger?: IOContext['logger']): this;
|
|
30
30
|
private shouldLogToSplunk;
|
|
31
31
|
}
|
|
@@ -35,7 +35,7 @@ class ErrorReport extends node_error_report_1.ErrorReportBase {
|
|
|
35
35
|
*/
|
|
36
36
|
injectOnSpan(span, logger) {
|
|
37
37
|
var _a;
|
|
38
|
-
span.setTag(__1.TracingTags.ERROR, 'true');
|
|
38
|
+
span === null || span === void 0 ? void 0 : span.setTag(__1.TracingTags.ERROR, 'true');
|
|
39
39
|
const indexedLogs = {
|
|
40
40
|
["error.kind" /* ERROR_KIND */]: this.kind,
|
|
41
41
|
["error.id" /* ERROR_ID */]: this.metadata.errorId,
|
|
@@ -47,7 +47,7 @@ class ErrorReport extends node_error_report_1.ErrorReportBase {
|
|
|
47
47
|
indexedLogs["error.server.request_id" /* ERROR_SERVER_REQUEST_ID */] = this.parsedInfo.response.data.requestId;
|
|
48
48
|
}
|
|
49
49
|
const serializableError = this.toObject();
|
|
50
|
-
span.log({ event: 'error', ...indexedLogs, error: serializableError });
|
|
50
|
+
span === null || span === void 0 ? void 0 : span.log({ event: 'error', ...indexedLogs, error: serializableError });
|
|
51
51
|
if (logger && this.shouldLogToSplunk(span)) {
|
|
52
52
|
logger.error(serializableError);
|
|
53
53
|
this.markErrorAsReported();
|
|
@@ -55,7 +55,8 @@ class ErrorReport extends node_error_report_1.ErrorReportBase {
|
|
|
55
55
|
return this;
|
|
56
56
|
}
|
|
57
57
|
shouldLogToSplunk(span) {
|
|
58
|
-
|
|
58
|
+
var _a;
|
|
59
|
+
return !this.isErrorReported() && ((_a = utils_1.getTraceInfo(span)) === null || _a === void 0 ? void 0 : _a.isSampled);
|
|
59
60
|
}
|
|
60
61
|
}
|
|
61
62
|
exports.ErrorReport = ErrorReport;
|
package/lib/tracing/utils.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Span } from 'opentracing';
|
|
2
2
|
export interface TraceInfo {
|
|
3
|
-
traceId
|
|
3
|
+
traceId?: string;
|
|
4
4
|
isSampled: boolean;
|
|
5
5
|
}
|
|
6
|
-
export declare function getTraceInfo(span
|
|
6
|
+
export declare function getTraceInfo(span?: Span): TraceInfo;
|
|
7
7
|
/**
|
|
8
8
|
* Do a shallow copy of a headers object and redacts sensitive information.
|
|
9
9
|
*
|
package/lib/tracing/utils.js
CHANGED
|
@@ -3,10 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const node_error_report_1 = require("@vtex/node-error-report");
|
|
4
4
|
function getTraceInfo(span) {
|
|
5
5
|
var _a, _b, _c;
|
|
6
|
-
const spanContext = span.context();
|
|
6
|
+
const spanContext = span === null || span === void 0 ? void 0 : span.context();
|
|
7
7
|
return {
|
|
8
|
-
isSampled: (_c = (_b = (_a = spanContext).isSampled) === null || _b === void 0 ? void 0 : _b.call(_a)) !== null && _c !== void 0 ? _c : false,
|
|
9
|
-
traceId: spanContext.toTraceId(),
|
|
8
|
+
isSampled: (_c = (_b = (_a = spanContext) === null || _a === void 0 ? void 0 : _a.isSampled) === null || _b === void 0 ? void 0 : _b.call(_a)) !== null && _c !== void 0 ? _c : false,
|
|
9
|
+
traceId: spanContext === null || spanContext === void 0 ? void 0 : spanContext.toTraceId(),
|
|
10
10
|
};
|
|
11
11
|
}
|
|
12
12
|
exports.getTraceInfo = getTraceInfo;
|