@vtex/api 6.45.21-beta.1 → 6.45.21

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 CHANGED
@@ -7,6 +7,13 @@ 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] - 2023-09-19
11
+ ### Changed
12
+ - Fix tracingMiddleware shouldTrace decision
13
+ - Fix HttpClient tracing based on sampling decision
14
+
15
+ ## [6.45.21-beta.2] - 2023-09-19
16
+
10
17
  ## [6.45.21-beta.1] - 2023-09-07
11
18
 
12
19
  ## [6.45.21-beta.0] - 2023-09-04
@@ -1782,11 +1789,13 @@ instead
1782
1789
  - `HttpClient` now adds `'Accept-Encoding': 'gzip'` header by default.
1783
1790
 
1784
1791
 
1785
- [Unreleased]: https://github.com/vtex/node-vtex-api/compare/v6.45.21-beta.1...HEAD
1792
+ [Unreleased]: https://github.com/vtex/node-vtex-api/compare/v6.45.21...HEAD
1786
1793
  [6.45.15]: https://github.com/vtex/node-vtex-api/compare/v6.45.14...v6.45.15
1787
1794
  [6.45.14]: https://github.com/vtex/node-vtex-api/compare/v6.45.13...v6.45.14
1788
1795
  [6.45.13]: https://github.com/vtex/node-vtex-api/compare/v6.45.12...v6.45.13
1789
1796
 
1797
+ [6.45.21]: https://github.com/vtex/node-vtex-api/compare/v6.45.21-beta.2...v6.45.21
1798
+ [6.45.21-beta.2]: https://github.com/vtex/node-vtex-api/compare/v6.45.21-beta.1...v6.45.21-beta.2
1790
1799
  [6.45.21-beta.1]: https://github.com/vtex/node-vtex-api/compare/v6.45.21-beta.0...v6.45.21-beta.1
1791
1800
  [6.45.21-beta.0]: https://github.com/vtex/node-vtex-api/compare/v6.45.21-beta...v6.45.21-beta.0
1792
1801
  [6.45.21-beta]: https://github.com/vtex/node-vtex-api/compare/v6.45.20...v6.45.21-beta
@@ -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
- if (!config.tracing || !config.tracing.isSampled) {
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
- if (!response.config.tracing || !response.config.tracing.isSampled) {
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
- const { rootSpan, requestSpanNameSuffix, referenceType = tracing_1.SpanReferenceTypes.CHILD_OF } = ctx.config.tracing || {};
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: Span;
60
+ rootSpan?: Span;
61
61
  isSampled: boolean;
62
62
  }
63
63
  export interface MiddlewareContext {
@@ -52,11 +52,11 @@ exports.addTracingMiddleware = (tracer) => {
52
52
  ["status_code" /* STATUS_CODE */]: ctx.response.status,
53
53
  }, 1);
54
54
  const traceInfo = tracing_1.getTraceInfo(currentSpan);
55
- if (traceInfo.isSampled) {
55
+ if (traceInfo === null || traceInfo === void 0 ? void 0 : traceInfo.isSampled) {
56
56
  if (!initialSamplingDecision) {
57
- 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);
58
58
  }
59
- currentSpan.addTags({
59
+ currentSpan === null || currentSpan === void 0 ? void 0 : currentSpan.addTags({
60
60
  [Tags_1.OpentracingTags.HTTP_URL]: ctx.request.href,
61
61
  [Tags_1.OpentracingTags.HTTP_METHOD]: ctx.request.method,
62
62
  [Tags_1.OpentracingTags.HTTP_STATUS_CODE]: ctx.response.status,
@@ -65,8 +65,8 @@ exports.addTracingMiddleware = (tracer) => {
65
65
  ["vtex.incoming.workspace" /* VTEX_WORKSPACE */]: ctx.get(constants_1.WORKSPACE_HEADER),
66
66
  ["vtex.incoming.account" /* VTEX_ACCOUNT */]: ctx.get(constants_1.ACCOUNT_HEADER),
67
67
  });
68
- currentSpan.log(utils_1.cloneAndSanitizeHeaders(ctx.request.headers, 'req.headers.'));
69
- 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.'));
70
70
  ctx.set(constants_1.TRACE_ID_HEADER, traceInfo.traceId);
71
71
  }
72
72
  const onResFinished = () => {
@@ -74,7 +74,7 @@ exports.addTracingMiddleware = (tracer) => {
74
74
  ["handler" /* REQUEST_HANDLER */]: currentSpan.operationName,
75
75
  }, utils_2.hrToMillisFloat(process.hrtime(start)));
76
76
  concurrentRequests.dec(1);
77
- currentSpan.finish();
77
+ currentSpan === null || currentSpan === void 0 ? void 0 : currentSpan.finish();
78
78
  };
79
79
  if (responseClosed) {
80
80
  onResFinished();
@@ -96,7 +96,7 @@ exports.traceUserLandRemainingPipelineMiddleware = () => {
96
96
  return async function traceUserLandRemainingPipeline(ctx, next) {
97
97
  const tracingCtx = ctx.tracing;
98
98
  ctx.tracing = undefined;
99
- const span = tracingCtx.currentSpan;
99
+ const span = tracingCtx === null || tracingCtx === void 0 ? void 0 : tracingCtx.currentSpan;
100
100
  const userLandTracer = ctx.vtex.tracer;
101
101
  userLandTracer.setFallbackSpan(span);
102
102
  userLandTracer.lockFallbackSpan();
@@ -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;
@@ -1,2 +1,2 @@
1
1
  import { IOContext, TracingContext } from '../typings';
2
- export declare const prepareHandlerCtx: (header: any, tracingContext: TracingContext) => 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">;
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">;
@@ -55,7 +55,8 @@ class ErrorReport extends node_error_report_1.ErrorReportBase {
55
55
  return this;
56
56
  }
57
57
  shouldLogToSplunk(span) {
58
- return !this.isErrorReported() && utils_1.getTraceInfo(span).isSampled;
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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vtex/api",
3
- "version": "6.45.21-beta.1",
3
+ "version": "6.45.21",
4
4
  "description": "VTEX I/O API client",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",