@vtex/api 6.48.1-beta.2 → 6.48.1-beta.4
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/gen/manifest.schema +1 -1
- package/lib/HttpClient/middlewares/metrics.js +0 -4
- package/lib/HttpClient/middlewares/recorder.js +0 -4
- package/lib/HttpClient/middlewares/request/index.js +1 -1
- package/lib/HttpClient/middlewares/request/setupAxios/index.d.ts +1 -0
- package/lib/HttpClient/middlewares/request/setupAxios/interceptors/tracing/index.js +2 -0
- package/lib/HttpClient/middlewares/request/setupAxios/interceptors/tracing/spanSetup.js +1 -1
- package/lib/HttpClient/middlewares/tracing.js +0 -4
- package/lib/caches/DiskCache.js +1 -1
- package/lib/caches/LRUDiskCache.js +1 -1
- package/lib/clients/infra/Apps.js +0 -2
- package/lib/clients/infra/Registry.js +0 -1
- package/lib/constants.d.ts +1 -0
- package/lib/constants.js +2 -1
- package/lib/service/index.js +0 -3
- package/lib/service/logger/client.d.ts +2 -0
- package/lib/service/logger/client.js +48 -0
- package/lib/service/logger/console.d.ts +1 -1
- package/lib/service/logger/index.d.ts +2 -0
- package/lib/service/logger/index.js +2 -0
- package/lib/service/logger/logger.d.ts +4 -15
- package/lib/service/logger/logger.js +59 -16
- package/lib/service/logger/loggerTypes.d.ts +14 -0
- package/lib/service/logger/loggerTypes.js +10 -0
- package/lib/service/telemetry/client.d.ts +3 -0
- package/lib/service/telemetry/client.js +57 -0
- package/lib/service/telemetry/index.d.ts +1 -0
- package/lib/service/telemetry/index.js +17 -0
- package/lib/service/tracing/tracingMiddlewares.js +0 -6
- package/lib/service/worker/index.js +2 -2
- package/lib/service/worker/runtime/events/middlewares/body.js +1 -4
- package/lib/service/worker/runtime/graphql/middlewares/error.js +0 -3
- package/lib/utils/buildFullPath.d.ts +11 -0
- package/lib/utils/buildFullPath.js +54 -0
- package/package.json +26 -4
package/gen/manifest.schema
CHANGED
|
@@ -6,7 +6,6 @@ const requestStats_1 = require("../../service/worker/runtime/http/middlewares/re
|
|
|
6
6
|
const utils_1 = require("../../utils");
|
|
7
7
|
const retry_1 = require("../../utils/retry");
|
|
8
8
|
const status_1 = require("../../utils/status");
|
|
9
|
-
const axios_1 = require("axios");
|
|
10
9
|
const metricsMiddleware = ({ metrics, serverTiming, name }) => {
|
|
11
10
|
const serverTimingStart = process.hrtime();
|
|
12
11
|
const serverTimingLabel = (0, utils_1.shrinkTimings)((0, utils_1.formatTimingName)({
|
|
@@ -29,9 +28,6 @@ const metricsMiddleware = ({ metrics, serverTiming, name }) => {
|
|
|
29
28
|
}
|
|
30
29
|
}
|
|
31
30
|
catch (err) {
|
|
32
|
-
if (!(err instanceof axios_1.AxiosError)) {
|
|
33
|
-
throw err;
|
|
34
|
-
}
|
|
35
31
|
const isCancelled = (err.message === requestStats_1.cancelMessage);
|
|
36
32
|
if (ctx.config.metric) {
|
|
37
33
|
errorCode = err.code;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.recorderMiddleware = void 0;
|
|
4
|
-
const axios_1 = require("axios");
|
|
5
4
|
const recorderMiddleware = (recorder) => async (ctx, next) => {
|
|
6
5
|
var _a;
|
|
7
6
|
if ((_a = ctx.config) === null || _a === void 0 ? void 0 : _a.ignoreRecorder) {
|
|
@@ -15,9 +14,6 @@ const recorderMiddleware = (recorder) => async (ctx, next) => {
|
|
|
15
14
|
}
|
|
16
15
|
}
|
|
17
16
|
catch (err) {
|
|
18
|
-
if (!(err instanceof axios_1.AxiosError)) {
|
|
19
|
-
throw err;
|
|
20
|
-
}
|
|
21
17
|
if (err.response && err.response.headers && err.response.status === 404) {
|
|
22
18
|
recorder.record(err.response.headers);
|
|
23
19
|
}
|
|
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.requestMiddleware = exports.routerCacheMiddleware = exports.defaultsMiddleware = void 0;
|
|
7
|
-
const buildFullPath_1 = __importDefault(require("
|
|
7
|
+
const buildFullPath_1 = __importDefault(require("../../../utils/buildFullPath"));
|
|
8
8
|
const qs_1 = require("qs");
|
|
9
9
|
const ramda_1 = require("ramda");
|
|
10
10
|
const Tags_1 = require("../../../tracing/Tags");
|
|
@@ -45,11 +45,13 @@ const onResponseError = (err) => {
|
|
|
45
45
|
return Promise.reject(err);
|
|
46
46
|
};
|
|
47
47
|
const addTracingPreRequestInterceptor = (http) => {
|
|
48
|
+
// Usando type assertion para compatibilidade com TypeScript 3.9.7
|
|
48
49
|
const requestTracingInterceptor = http.interceptors.request.use(preRequestInterceptor(http), undefined);
|
|
49
50
|
return { requestTracingInterceptor };
|
|
50
51
|
};
|
|
51
52
|
exports.addTracingPreRequestInterceptor = addTracingPreRequestInterceptor;
|
|
52
53
|
const addTracingResponseInterceptor = (http) => {
|
|
54
|
+
// Usando type assertion para compatibilidade com TypeScript 3.9.7
|
|
53
55
|
const responseTracingInterceptor = http.interceptors.response.use(onResponseSuccess, onResponseError);
|
|
54
56
|
return { responseTracingInterceptor };
|
|
55
57
|
};
|
|
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.injectResponseInfoOnSpan = exports.injectRequestInfoOnSpan = void 0;
|
|
7
|
-
const buildFullPath_1 = __importDefault(require("
|
|
7
|
+
const buildFullPath_1 = __importDefault(require("../../../../../../utils/buildFullPath"));
|
|
8
8
|
const constants_1 = require("../../../../../../constants");
|
|
9
9
|
const Tags_1 = require("../../../../../../tracing/Tags");
|
|
10
10
|
const utils_1 = require("../../../../../../tracing/utils");
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createHttpClientTracingMiddleware = void 0;
|
|
4
|
-
const axios_1 = require("axios");
|
|
5
4
|
const tracing_1 = require("../../tracing");
|
|
6
5
|
const Tags_1 = require("../../tracing/Tags");
|
|
7
6
|
const cache_1 = require("./cache");
|
|
@@ -39,9 +38,6 @@ const createHttpClientTracingMiddleware = ({ tracer, logger, clientName, hasMemo
|
|
|
39
38
|
response = ctx.response;
|
|
40
39
|
}
|
|
41
40
|
catch (err) {
|
|
42
|
-
if (!(err instanceof axios_1.AxiosError)) {
|
|
43
|
-
throw err;
|
|
44
|
-
}
|
|
45
41
|
response = err.response;
|
|
46
42
|
if ((_a = ctx.tracing) === null || _a === void 0 ? void 0 : _a.isSampled) {
|
|
47
43
|
tracing_1.ErrorReport.create({ originalError: err }).injectOnSpan(span, logger);
|
package/lib/caches/DiskCache.js
CHANGED
|
@@ -143,8 +143,6 @@ class Apps extends InfraClient_1.InfraClient {
|
|
|
143
143
|
return response;
|
|
144
144
|
}
|
|
145
145
|
catch (e) {
|
|
146
|
-
// Typing cast for compatibility with error handling in TS versions > 4.0
|
|
147
|
-
// Source: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-0.html#unknown-on-catch-clause-bindings
|
|
148
146
|
e.bundleSize = zip.pointer();
|
|
149
147
|
throw e;
|
|
150
148
|
}
|
package/lib/constants.d.ts
CHANGED
package/lib/constants.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.cancellableMethods = exports.INSPECT_DEBUGGER_PORT = exports.PRODUCTION = exports.WORKSPACE = exports.ACCOUNT = exports.NODE_ENV = exports.APP = exports.PUBLIC_ENDPOINT = exports.REGION = exports.LINKED = exports.MAX_WORKERS = exports.HTTP_SERVER_PORT = exports.MAX_AGE = exports.UP_SIGNAL = exports.BODY_HASH = exports.PROVIDER_HEADER = exports.TRACE_ID_HEADER = exports.COLOSSUS_PARAMS_HEADER = exports.COLOSSUS_ROUTE_ID_HEADER = exports.COLOSSUS_ROUTE_DECLARER_HEADER = exports.EVENT_HANDLER_ID_HEADER = exports.EVENT_SUBJECT_HEADER = exports.EVENT_SENDER_HEADER = exports.EVENT_KEY_HEADER = exports.WORKSPACE_HEADER = exports.WORKSPACE_IS_PRODUCTION_HEADER = exports.PLATFORM_HEADER = exports.OPERATION_ID_HEADER = exports.ROUTER_CACHE_HEADER = exports.REQUEST_ID_HEADER = exports.CREDENTIAL_HEADER = exports.ACCOUNT_HEADER = exports.ETAG_HEADER = exports.META_HEADER_BUCKET = exports.META_HEADER = exports.BINDING_HEADER = exports.TENANT_HEADER = exports.FORWARDED_HOST_HEADER = exports.LOCALE_HEADER = exports.PRODUCT_HEADER = exports.SESSION_HEADER = exports.SEGMENT_HEADER = exports.CACHE_CONTROL_HEADER = exports.PID = exports.IS_IO = exports.DEFAULT_WORKSPACE = exports.NODE_VTEX_API_VERSION = void 0;
|
|
3
|
+
exports.LOG_CLIENT_INIT_TIMEOUT_MS = exports.cancellableMethods = exports.INSPECT_DEBUGGER_PORT = exports.PRODUCTION = exports.WORKSPACE = exports.ACCOUNT = exports.NODE_ENV = exports.APP = exports.PUBLIC_ENDPOINT = exports.REGION = exports.LINKED = exports.MAX_WORKERS = exports.HTTP_SERVER_PORT = exports.MAX_AGE = exports.UP_SIGNAL = exports.BODY_HASH = exports.PROVIDER_HEADER = exports.TRACE_ID_HEADER = exports.COLOSSUS_PARAMS_HEADER = exports.COLOSSUS_ROUTE_ID_HEADER = exports.COLOSSUS_ROUTE_DECLARER_HEADER = exports.EVENT_HANDLER_ID_HEADER = exports.EVENT_SUBJECT_HEADER = exports.EVENT_SENDER_HEADER = exports.EVENT_KEY_HEADER = exports.WORKSPACE_HEADER = exports.WORKSPACE_IS_PRODUCTION_HEADER = exports.PLATFORM_HEADER = exports.OPERATION_ID_HEADER = exports.ROUTER_CACHE_HEADER = exports.REQUEST_ID_HEADER = exports.CREDENTIAL_HEADER = exports.ACCOUNT_HEADER = exports.ETAG_HEADER = exports.META_HEADER_BUCKET = exports.META_HEADER = exports.BINDING_HEADER = exports.TENANT_HEADER = exports.FORWARDED_HOST_HEADER = exports.LOCALE_HEADER = exports.PRODUCT_HEADER = exports.SESSION_HEADER = exports.SEGMENT_HEADER = exports.CACHE_CONTROL_HEADER = exports.PID = exports.IS_IO = exports.DEFAULT_WORKSPACE = exports.NODE_VTEX_API_VERSION = void 0;
|
|
4
4
|
const app_1 = require("./utils/app");
|
|
5
5
|
// tslint:disable-next-line
|
|
6
6
|
const pkg = require('../package.json');
|
|
@@ -64,3 +64,4 @@ exports.WORKSPACE = process.env.VTEX_WORKSPACE;
|
|
|
64
64
|
exports.PRODUCTION = process.env.VTEX_PRODUCTION === 'true';
|
|
65
65
|
exports.INSPECT_DEBUGGER_PORT = 5858;
|
|
66
66
|
exports.cancellableMethods = new Set(['GET', 'OPTIONS', 'HEAD']);
|
|
67
|
+
exports.LOG_CLIENT_INIT_TIMEOUT_MS = 5000;
|
package/lib/service/index.js
CHANGED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getLogClient = void 0;
|
|
4
|
+
const diagnostics_nodejs_1 = require("@vtex/diagnostics-nodejs");
|
|
5
|
+
const telemetry_1 = require("../telemetry");
|
|
6
|
+
let logClient;
|
|
7
|
+
let isInitializing = false;
|
|
8
|
+
let initPromise = undefined;
|
|
9
|
+
async function getLogClient(account, workspace, appName) {
|
|
10
|
+
if (logClient) {
|
|
11
|
+
return logClient;
|
|
12
|
+
}
|
|
13
|
+
if (initPromise) {
|
|
14
|
+
return initPromise;
|
|
15
|
+
}
|
|
16
|
+
isInitializing = true;
|
|
17
|
+
initPromise = initializeClient(account, workspace, appName);
|
|
18
|
+
return initPromise;
|
|
19
|
+
}
|
|
20
|
+
exports.getLogClient = getLogClient;
|
|
21
|
+
async function initializeClient(account, workspace, appName) {
|
|
22
|
+
try {
|
|
23
|
+
const telemetryClient = await (0, telemetry_1.getTelemetryClient)();
|
|
24
|
+
const logsConfig = diagnostics_nodejs_1.Exporters.CreateLogsExporterConfig({
|
|
25
|
+
endpoint: process.env.OTEL_EXPORTER_OTLP_ENDPOINT,
|
|
26
|
+
path: process.env.OTEL_EXPORTER_OTLP_PATH || '/v1/logs',
|
|
27
|
+
protocol: 'http',
|
|
28
|
+
interval: 5,
|
|
29
|
+
timeoutSeconds: 5,
|
|
30
|
+
headers: { 'Content-Type': 'application/json' },
|
|
31
|
+
});
|
|
32
|
+
const logsExporter = diagnostics_nodejs_1.Exporters.CreateExporter(logsConfig, 'otlp');
|
|
33
|
+
await logsExporter.initialize();
|
|
34
|
+
const clientKey = `${account}-${workspace}-${appName}`;
|
|
35
|
+
logClient = await telemetryClient.newLogsClient({
|
|
36
|
+
exporter: logsExporter,
|
|
37
|
+
loggerName: `node-vtex-api-${clientKey}`,
|
|
38
|
+
});
|
|
39
|
+
return logClient;
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
console.error('Failed to initialize logs client:', error);
|
|
43
|
+
throw error;
|
|
44
|
+
}
|
|
45
|
+
finally {
|
|
46
|
+
isInitializing = false;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -16,3 +16,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./console"), exports);
|
|
18
18
|
__exportStar(require("./logger"), exports);
|
|
19
|
+
__exportStar(require("./loggerTypes"), exports);
|
|
20
|
+
__exportStar(require("./client"), exports);
|
|
@@ -1,17 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { IOContext } from '../worker/runtime/typings';
|
|
3
|
-
export interface LoggerTracingContext {
|
|
4
|
-
requestTracer: IUserLandTracer;
|
|
5
|
-
}
|
|
6
|
-
export declare enum LogLevel {
|
|
7
|
-
Debug = "debug",
|
|
8
|
-
Info = "info",
|
|
9
|
-
Warn = "warn",
|
|
10
|
-
Error = "error"
|
|
11
|
-
}
|
|
12
|
-
interface LoggerContext extends Pick<IOContext, 'account' | 'workspace' | 'requestId' | 'operationId' | 'production'> {
|
|
13
|
-
tracer?: IOContext['tracer'];
|
|
14
|
-
}
|
|
1
|
+
import { LoggerContext, LogLevel } from './loggerTypes';
|
|
15
2
|
export declare class Logger {
|
|
16
3
|
private account;
|
|
17
4
|
private workspace;
|
|
@@ -19,11 +6,13 @@ export declare class Logger {
|
|
|
19
6
|
private requestId;
|
|
20
7
|
private production;
|
|
21
8
|
private tracingState?;
|
|
9
|
+
private logClient;
|
|
10
|
+
private clientInitPromise;
|
|
22
11
|
constructor(ctx: LoggerContext);
|
|
12
|
+
private initLogClient;
|
|
23
13
|
debug: (message: any) => void;
|
|
24
14
|
info: (message: any) => void;
|
|
25
15
|
warn: (warning: any) => void;
|
|
26
16
|
error: (error: any) => void;
|
|
27
17
|
log: (message: any, level: LogLevel) => void;
|
|
28
18
|
}
|
|
29
|
-
export {};
|
|
@@ -1,25 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Logger =
|
|
3
|
+
exports.Logger = void 0;
|
|
4
4
|
const constants_1 = require("../../constants");
|
|
5
5
|
const error_1 = require("../../utils/error");
|
|
6
6
|
const log_1 = require("../../utils/log");
|
|
7
|
-
const
|
|
7
|
+
const loggerTypes_1 = require("./loggerTypes");
|
|
8
|
+
const client_1 = require("./client");
|
|
8
9
|
const app = constants_1.APP.ID;
|
|
9
10
|
const EMPTY_MESSAGE = 'Logger.log was called with null or undefined message';
|
|
10
|
-
var LogLevel;
|
|
11
|
-
(function (LogLevel) {
|
|
12
|
-
LogLevel["Debug"] = "debug";
|
|
13
|
-
LogLevel["Info"] = "info";
|
|
14
|
-
LogLevel["Warn"] = "warn";
|
|
15
|
-
LogLevel["Error"] = "error";
|
|
16
|
-
})(LogLevel = exports.LogLevel || (exports.LogLevel = {}));
|
|
17
11
|
class Logger {
|
|
18
12
|
constructor(ctx) {
|
|
19
|
-
this.
|
|
20
|
-
this.
|
|
21
|
-
this.
|
|
22
|
-
this.
|
|
13
|
+
this.logClient = undefined;
|
|
14
|
+
this.clientInitPromise = undefined;
|
|
15
|
+
this.debug = (message) => this.log(message, loggerTypes_1.LogLevel.Debug);
|
|
16
|
+
this.info = (message) => this.log(message, loggerTypes_1.LogLevel.Info);
|
|
17
|
+
this.warn = (warning) => this.log(warning, loggerTypes_1.LogLevel.Warn);
|
|
18
|
+
this.error = (error) => this.log(error, loggerTypes_1.LogLevel.Error);
|
|
23
19
|
this.log = (message, level) => {
|
|
24
20
|
var _a;
|
|
25
21
|
const data = message ? (0, error_1.cleanError)(message) : EMPTY_MESSAGE;
|
|
@@ -40,11 +36,35 @@ class Logger {
|
|
|
40
36
|
// Mark third-party apps logs to send to skidder
|
|
41
37
|
if (constants_1.APP.IS_THIRD_PARTY()) {
|
|
42
38
|
Object.assign(inflatedLog, {
|
|
43
|
-
__SKIDDER_TOPIC_1: `skidder.vendor.${constants_1.APP.VENDOR}`,
|
|
44
|
-
__SKIDDER_TOPIC_2: `skidder.app.${constants_1.APP.VENDOR}.${constants_1.APP.NAME}`,
|
|
39
|
+
'__SKIDDER_TOPIC_1': `skidder.vendor.${constants_1.APP.VENDOR}`,
|
|
40
|
+
'__SKIDDER_TOPIC_2': `skidder.app.${constants_1.APP.VENDOR}.${constants_1.APP.NAME}`,
|
|
45
41
|
});
|
|
46
42
|
}
|
|
47
|
-
|
|
43
|
+
if (this.logClient) {
|
|
44
|
+
try {
|
|
45
|
+
let logMessage = typeof data === 'string' ? data : JSON.stringify(data);
|
|
46
|
+
switch (level) {
|
|
47
|
+
case loggerTypes_1.LogLevel.Debug:
|
|
48
|
+
this.logClient.debug(logMessage, inflatedLog);
|
|
49
|
+
break;
|
|
50
|
+
case loggerTypes_1.LogLevel.Info:
|
|
51
|
+
this.logClient.info(logMessage, inflatedLog);
|
|
52
|
+
break;
|
|
53
|
+
case loggerTypes_1.LogLevel.Warn:
|
|
54
|
+
this.logClient.warn(logMessage, inflatedLog);
|
|
55
|
+
break;
|
|
56
|
+
case loggerTypes_1.LogLevel.Error:
|
|
57
|
+
this.logClient.error(logMessage, inflatedLog);
|
|
58
|
+
break;
|
|
59
|
+
default:
|
|
60
|
+
this.logClient.info(logMessage, inflatedLog);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
catch (e) {
|
|
64
|
+
console.error('Error using diagnostics client for logging:', e);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
console.log(typeof inflatedLog === 'string' ? JSON.stringify(inflatedLog) : inflatedLog);
|
|
48
68
|
};
|
|
49
69
|
this.account = ctx.account;
|
|
50
70
|
this.workspace = ctx.workspace;
|
|
@@ -57,6 +77,29 @@ class Logger {
|
|
|
57
77
|
traceId: ctx.tracer.traceId,
|
|
58
78
|
};
|
|
59
79
|
}
|
|
80
|
+
// this.initLogClient();
|
|
81
|
+
}
|
|
82
|
+
initLogClient() {
|
|
83
|
+
if (this.clientInitPromise) {
|
|
84
|
+
return this.clientInitPromise;
|
|
85
|
+
}
|
|
86
|
+
this.clientInitPromise = (async () => {
|
|
87
|
+
try {
|
|
88
|
+
const timeoutPromise = new Promise((_, reject) => {
|
|
89
|
+
setTimeout(() => reject(new Error('Log client initialization timeout')), constants_1.LOG_CLIENT_INIT_TIMEOUT_MS);
|
|
90
|
+
});
|
|
91
|
+
this.logClient = await Promise.race([
|
|
92
|
+
(0, client_1.getLogClient)(this.account, this.workspace, constants_1.APP.NAME),
|
|
93
|
+
timeoutPromise
|
|
94
|
+
]);
|
|
95
|
+
return this.logClient;
|
|
96
|
+
}
|
|
97
|
+
catch (error) {
|
|
98
|
+
console.error('Failed to initialize log client:', error);
|
|
99
|
+
return undefined;
|
|
100
|
+
}
|
|
101
|
+
})();
|
|
102
|
+
return this.clientInitPromise;
|
|
60
103
|
}
|
|
61
104
|
}
|
|
62
105
|
exports.Logger = Logger;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { IOContext } from '../worker/runtime/typings';
|
|
2
|
+
export interface LoggerContext extends Pick<IOContext, 'account' | 'workspace' | 'requestId' | 'operationId' | 'production'> {
|
|
3
|
+
tracer?: IOContext['tracer'];
|
|
4
|
+
}
|
|
5
|
+
export interface TracingState {
|
|
6
|
+
isTraceSampled: boolean;
|
|
7
|
+
traceId?: string;
|
|
8
|
+
}
|
|
9
|
+
export declare enum LogLevel {
|
|
10
|
+
Debug = "debug",
|
|
11
|
+
Info = "info",
|
|
12
|
+
Warn = "warn",
|
|
13
|
+
Error = "error"
|
|
14
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LogLevel = void 0;
|
|
4
|
+
var LogLevel;
|
|
5
|
+
(function (LogLevel) {
|
|
6
|
+
LogLevel["Debug"] = "debug";
|
|
7
|
+
LogLevel["Info"] = "info";
|
|
8
|
+
LogLevel["Warn"] = "warn";
|
|
9
|
+
LogLevel["Error"] = "error";
|
|
10
|
+
})(LogLevel = exports.LogLevel || (exports.LogLevel = {}));
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resetTelemetryClient = exports.getTelemetryClient = void 0;
|
|
4
|
+
const diagnostics_nodejs_1 = require("@vtex/diagnostics-nodejs");
|
|
5
|
+
const constants_1 = require("../../constants");
|
|
6
|
+
class TelemetryClientSingleton {
|
|
7
|
+
constructor() {
|
|
8
|
+
this.initializationPromise = undefined;
|
|
9
|
+
}
|
|
10
|
+
static getInstance() {
|
|
11
|
+
if (!TelemetryClientSingleton.instance) {
|
|
12
|
+
TelemetryClientSingleton.instance = new TelemetryClientSingleton();
|
|
13
|
+
}
|
|
14
|
+
return TelemetryClientSingleton.instance;
|
|
15
|
+
}
|
|
16
|
+
async initTelemetryClient() {
|
|
17
|
+
try {
|
|
18
|
+
const telemetryClient = await (0, diagnostics_nodejs_1.NewTelemetryClient)('node-vtex-api', constants_1.APP.ID || 'vtex-app', {
|
|
19
|
+
additionalAttrs: {
|
|
20
|
+
'version': constants_1.APP.VERSION || '',
|
|
21
|
+
'environment': process.env.VTEX_WORKSPACE || 'development',
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
this.telemetryClient = telemetryClient;
|
|
25
|
+
return telemetryClient;
|
|
26
|
+
}
|
|
27
|
+
catch (error) {
|
|
28
|
+
console.error('Failed to initialize telemetry client:', error);
|
|
29
|
+
throw error;
|
|
30
|
+
}
|
|
31
|
+
finally {
|
|
32
|
+
this.initializationPromise = undefined;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
async getClient() {
|
|
36
|
+
if (this.telemetryClient) {
|
|
37
|
+
return this.telemetryClient;
|
|
38
|
+
}
|
|
39
|
+
if (this.initializationPromise) {
|
|
40
|
+
return this.initializationPromise;
|
|
41
|
+
}
|
|
42
|
+
this.initializationPromise = this.initTelemetryClient();
|
|
43
|
+
return this.initializationPromise;
|
|
44
|
+
}
|
|
45
|
+
reset() {
|
|
46
|
+
this.telemetryClient = undefined;
|
|
47
|
+
this.initializationPromise = undefined;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
async function getTelemetryClient() {
|
|
51
|
+
return TelemetryClientSingleton.getInstance().getClient();
|
|
52
|
+
}
|
|
53
|
+
exports.getTelemetryClient = getTelemetryClient;
|
|
54
|
+
function resetTelemetryClient() {
|
|
55
|
+
TelemetryClientSingleton.getInstance().reset();
|
|
56
|
+
}
|
|
57
|
+
exports.resetTelemetryClient = resetTelemetryClient;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './client';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./client"), exports);
|
|
@@ -30,9 +30,6 @@ const addTracingMiddleware = (tracer) => {
|
|
|
30
30
|
await next();
|
|
31
31
|
}
|
|
32
32
|
catch (err) {
|
|
33
|
-
if (!(err instanceof Error)) {
|
|
34
|
-
throw err;
|
|
35
|
-
}
|
|
36
33
|
tracing_1.ErrorReport.create({ originalError: err }).injectOnSpan(currentSpan, (_a = ctx.vtex) === null || _a === void 0 ? void 0 : _a.logger);
|
|
37
34
|
throw err;
|
|
38
35
|
}
|
|
@@ -91,9 +88,6 @@ const traceUserLandRemainingPipelineMiddleware = () => {
|
|
|
91
88
|
await next();
|
|
92
89
|
}
|
|
93
90
|
catch (err) {
|
|
94
|
-
if (!(err instanceof Error)) {
|
|
95
|
-
throw err;
|
|
96
|
-
}
|
|
97
91
|
tracing_1.ErrorReport.create({ originalError: err }).injectOnSpan(span, ctx.vtex.logger);
|
|
98
92
|
throw err;
|
|
99
93
|
}
|
|
@@ -13,7 +13,7 @@ const constants_1 = require("../../constants");
|
|
|
13
13
|
const MetricsAccumulator_1 = require("../../metrics/MetricsAccumulator");
|
|
14
14
|
const loaders_1 = require("../loaders");
|
|
15
15
|
const console_1 = require("../logger/console");
|
|
16
|
-
const
|
|
16
|
+
const loggerTypes_1 = require("../logger/loggerTypes");
|
|
17
17
|
const requestMetricsMiddleware_1 = require("../metrics/requestMetricsMiddleware");
|
|
18
18
|
const TracerSingleton_1 = require("../tracing/TracerSingleton");
|
|
19
19
|
const tracingMiddlewares_1 = require("../tracing/tracingMiddlewares");
|
|
@@ -146,7 +146,7 @@ const scaleClientCaches = (scaleFactor, options) => Object.entries(options || {}
|
|
|
146
146
|
const previous = opts.memoryCache.storage.max;
|
|
147
147
|
const current = previous / scaleFactor;
|
|
148
148
|
opts.memoryCache.storage.max = current;
|
|
149
|
-
(0, console_1.logOnceToDevConsole)(`Scaling ${name} cache capacity from ${previous} to ${current}`,
|
|
149
|
+
(0, console_1.logOnceToDevConsole)(`Scaling ${name} cache capacity from ${previous} to ${current}`, loggerTypes_1.LogLevel.Warn);
|
|
150
150
|
}
|
|
151
151
|
});
|
|
152
152
|
const startWorker = (serviceJSON) => {
|
|
@@ -6,15 +6,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.parseBodyMiddleware = void 0;
|
|
7
7
|
const co_body_1 = __importDefault(require("co-body"));
|
|
8
8
|
const logger_1 = require("../../../../logger");
|
|
9
|
-
const console_1 = require("
|
|
9
|
+
const console_1 = require("../../../../logger/console");
|
|
10
10
|
async function parseBodyMiddleware(ctx, next) {
|
|
11
11
|
try {
|
|
12
12
|
ctx.state.body = await (0, co_body_1.default)(ctx.req);
|
|
13
13
|
}
|
|
14
14
|
catch (err) {
|
|
15
|
-
if (!(err instanceof Error)) {
|
|
16
|
-
throw err;
|
|
17
|
-
}
|
|
18
15
|
const msg = `Error parsing event body: ${err.message || err}`;
|
|
19
16
|
ctx.status = 500;
|
|
20
17
|
ctx.body = msg;
|
|
@@ -53,9 +53,6 @@ async function graphqlError(ctx, next) {
|
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
55
|
catch (e) {
|
|
56
|
-
if (!(e instanceof apollo_server_errors_1.ApolloError)) {
|
|
57
|
-
throw e;
|
|
58
|
-
}
|
|
59
56
|
if (e.code === RequestCancelledError_1.cancelledErrorCode) {
|
|
60
57
|
ctx.status = RequestCancelledError_1.cancelledRequestStatus;
|
|
61
58
|
return;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a new URL by combining the baseURL with the requestedURL,
|
|
3
|
+
* only when the requestedURL is not already an absolute URL.
|
|
4
|
+
* If the requestURL is absolute, this function returns the requestedURL untouched.
|
|
5
|
+
*
|
|
6
|
+
* @param {string} baseURL The base URL
|
|
7
|
+
* @param {string} requestedURL Absolute or relative URL to combine
|
|
8
|
+
*
|
|
9
|
+
* @returns {string} The combined full path
|
|
10
|
+
*/
|
|
11
|
+
export default function (baseURL?: string, requestedURL?: string, allowAbsoluteUrls?: boolean): string | undefined;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// This module is part of the Axios library.
|
|
3
|
+
// It is used to build a full URL by combining a base URL with a relative URL.
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
// It is originally not intended to be used directly, but rather as a utility function within the Axios library.
|
|
6
|
+
// Since Axios 1.0, this function is not exported by default, and the team does not recommend using it directly,
|
|
7
|
+
// as it may not be available in future versions.
|
|
8
|
+
// The function takes a base URL and a relative URL as input, and returns the full URL.
|
|
9
|
+
// It handles both absolute and relative URLs, and ensures that the resulting URL is properly formatted.
|
|
10
|
+
// It is used internally by Axios to construct the full URL for HTTP requests.
|
|
11
|
+
/**
|
|
12
|
+
* Creates a new URL by combining the baseURL with the requestedURL,
|
|
13
|
+
* only when the requestedURL is not already an absolute URL.
|
|
14
|
+
* If the requestURL is absolute, this function returns the requestedURL untouched.
|
|
15
|
+
*
|
|
16
|
+
* @param {string} baseURL The base URL
|
|
17
|
+
* @param {string} requestedURL Absolute or relative URL to combine
|
|
18
|
+
*
|
|
19
|
+
* @returns {string} The combined full path
|
|
20
|
+
*/
|
|
21
|
+
function default_1(baseURL, requestedURL, allowAbsoluteUrls) {
|
|
22
|
+
let isRelativeUrl = !isAbsoluteURL(requestedURL);
|
|
23
|
+
if (baseURL && (isRelativeUrl || allowAbsoluteUrls == false)) {
|
|
24
|
+
return combineURLs(baseURL, requestedURL);
|
|
25
|
+
}
|
|
26
|
+
return requestedURL;
|
|
27
|
+
}
|
|
28
|
+
exports.default = default_1;
|
|
29
|
+
/**
|
|
30
|
+
* Determines whether the specified URL is absolute
|
|
31
|
+
*
|
|
32
|
+
* @param {string} url The URL to test
|
|
33
|
+
*
|
|
34
|
+
* @returns {boolean} True if the specified URL is absolute, otherwise false
|
|
35
|
+
*/
|
|
36
|
+
function isAbsoluteURL(url) {
|
|
37
|
+
// A URL is considered absolute if it begins with "<scheme>://" or "//" (protocol-relative URL).
|
|
38
|
+
// RFC 3986 defines scheme name as a sequence of characters beginning with a letter and followed
|
|
39
|
+
// by any combination of letters, digits, plus, period, or hyphen.
|
|
40
|
+
return !!url && /^([a-z][a-z\d+\-.]*:)?\/\//i.test(url);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Creates a new URL by combining the specified URLs
|
|
44
|
+
*
|
|
45
|
+
* @param {string} baseURL The base URL
|
|
46
|
+
* @param {string} relativeURL The relative URL
|
|
47
|
+
*
|
|
48
|
+
* @returns {string} The combined URL
|
|
49
|
+
*/
|
|
50
|
+
function combineURLs(baseURL, relativeURL) {
|
|
51
|
+
return relativeURL && baseURL
|
|
52
|
+
? baseURL.replace(/\/?\/$/, '') + '/' + relativeURL.replace(/^\/+/, '')
|
|
53
|
+
: baseURL;
|
|
54
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vtex/api",
|
|
3
|
-
"version": "6.48.1-beta.
|
|
3
|
+
"version": "6.48.1-beta.4",
|
|
4
4
|
"description": "VTEX I/O API client",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"typings": "lib/index.d.ts",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"clean": "rimraf lib/",
|
|
13
13
|
"watch": "yarn clean && tsc --watch",
|
|
14
14
|
"build": "yarn clean && tsc",
|
|
15
|
-
"gen": "typescript-json-schema
|
|
15
|
+
"gen": "typescript-json-schema src/responses.ts PublicAppManifest > gen/manifest.schema",
|
|
16
16
|
"test": "jest",
|
|
17
17
|
"lint": "tslint -c tslint.json './src/**/*.ts'",
|
|
18
18
|
"format": "prettier --config ./.prettierrc --write \"src/**/*.ts\" \"src/**/*.js\"",
|
|
@@ -49,6 +49,7 @@
|
|
|
49
49
|
"dependencies": {
|
|
50
50
|
"@types/koa": "^2.11.0",
|
|
51
51
|
"@types/koa-compose": "^3.2.3",
|
|
52
|
+
"@vtex/diagnostics-nodejs": "0.1.0-beta.8",
|
|
52
53
|
"@vtex/node-error-report": "^0.0.3",
|
|
53
54
|
"@wry/equality": "^0.1.9",
|
|
54
55
|
"agentkeepalive": "^4.0.2",
|
|
@@ -121,7 +122,28 @@
|
|
|
121
122
|
"tslint-config-vtex": "^2.1.0",
|
|
122
123
|
"tslint-eslint-rules": "^5.4.0",
|
|
123
124
|
"typemoq": "^2.1.0",
|
|
124
|
-
"typescript": "4.
|
|
125
|
-
"typescript-json-schema": "^0.
|
|
125
|
+
"typescript": "^4.4.4",
|
|
126
|
+
"typescript-json-schema": "^0.52.0"
|
|
127
|
+
},
|
|
128
|
+
"resolutions": {
|
|
129
|
+
"@opentelemetry/core": "1.30.1",
|
|
130
|
+
"@opentelemetry/exporter-metrics-otlp-grpc": "0.57.2",
|
|
131
|
+
"@opentelemetry/exporter-metrics-otlp-http": "0.57.2",
|
|
132
|
+
"@opentelemetry/exporter-logs-otlp-grpc": "0.57.2",
|
|
133
|
+
"@opentelemetry/exporter-logs-otlp-http": "0.57.2",
|
|
134
|
+
"@opentelemetry/exporter-trace-otlp-grpc": "0.57.2",
|
|
135
|
+
"@opentelemetry/exporter-trace-otlp-http": "0.57.2",
|
|
136
|
+
"@opentelemetry/instrumentation": "0.57.2",
|
|
137
|
+
"@opentelemetry/instrumentation-http": "0.57.2",
|
|
138
|
+
"@opentelemetry/instrumentation-grpc": "0.57.2",
|
|
139
|
+
"@opentelemetry/instrumentation-net": "0.43.1",
|
|
140
|
+
"@opentelemetry/propagator-b3": "1.30.1",
|
|
141
|
+
"@opentelemetry/resource-detector-aws": "1.12.0",
|
|
142
|
+
"@opentelemetry/resources": "1.30.1",
|
|
143
|
+
"@opentelemetry/sdk-node": "0.57.2",
|
|
144
|
+
"@opentelemetry/sdk-logs": "0.57.2",
|
|
145
|
+
"@opentelemetry/sdk-metrics": "1.30.1",
|
|
146
|
+
"@opentelemetry/sdk-trace-base": "1.30.1",
|
|
147
|
+
"@opentelemetry/sdk-trace-node": "1.30.1"
|
|
126
148
|
}
|
|
127
149
|
}
|