diff --git a/package.json b/package.json index 63d975e6a..a55cc14af 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@vtex/api", - "version": "7.2.2", + "version": "7.2.3-beta.0", "description": "VTEX I/O API client", "main": "lib/index.js", "typings": "lib/index.d.ts", diff --git a/src/service/logger/logger.ts b/src/service/logger/logger.ts index 1edbac51a..d4f45f9da 100644 --- a/src/service/logger/logger.ts +++ b/src/service/logger/logger.ts @@ -79,20 +79,23 @@ export class Logger { cleanLog(data) /* tslint:disable:object-literal-sort-keys */ - const inflatedLog = { + const commonLogFields = { __VTEX_IO_LOG: true, level, - [AttributeKeys.VTEX_IO_APP_ID]: app, - [AttributeKeys.VTEX_ACCOUNT_NAME]: this.account, - [AttributeKeys.VTEX_IO_WORKSPACE_NAME]: this.workspace, - [AttributeKeys.VTEX_IO_WORKSPACE_TYPE]: this.production ? 'production' : 'development', - [AttributeKeys.VTEX_IO_APP_AUTHOR_TYPE]: APP.IS_THIRD_PARTY() ? '3p' : '1p', operationId: this.operationId, requestId: this.requestId, - data, ... (this.tracingState?.isTraceSampled ? { traceId: this.tracingState.traceId } : null), } + const inflatedLog = { + app, + account: this.account, + workspace: this.workspace, + production: this.production, + data, + ...commonLogFields, + } + // Mark third-party apps logs to send to skidder if (APP.IS_THIRD_PARTY()) { Object.assign(inflatedLog, { @@ -101,30 +104,40 @@ export class Logger { }); } + console.log(JSON.stringify(inflatedLog)) + + const diagnosticsLog = { + [AttributeKeys.VTEX_IO_APP_ID]: app, + [AttributeKeys.VTEX_ACCOUNT_NAME]: this.account, + [AttributeKeys.VTEX_IO_WORKSPACE_NAME]: this.workspace, + [AttributeKeys.VTEX_IO_WORKSPACE_TYPE]: this.production ? 'production' : 'development', + [AttributeKeys.VTEX_IO_APP_AUTHOR_TYPE]: APP.IS_THIRD_PARTY() ? '3p' : '1p', + ...commonLogFields, + } + if (this.logClient) { try { let logMessage = typeof data === 'string' ? data : JSON.stringify(data) switch (level) { case LogLevel.Debug: - this.logClient.debug(logMessage, inflatedLog); + this.logClient.debug(logMessage, diagnosticsLog); break; case LogLevel.Info: - this.logClient.info(logMessage, inflatedLog); + this.logClient.info(logMessage, diagnosticsLog); break; case LogLevel.Warn: - this.logClient.warn(logMessage, inflatedLog); + this.logClient.warn(logMessage, diagnosticsLog); break; case LogLevel.Error: - this.logClient.error(logMessage, inflatedLog); + this.logClient.error(logMessage, diagnosticsLog); break; default: - this.logClient.info(logMessage, inflatedLog); + this.logClient.info(logMessage, diagnosticsLog); } } catch (e) { console.error('Error using diagnostics client for logging:', e); } } - console.log(JSON.stringify(inflatedLog)) } } diff --git a/src/service/metrics/otelRequestMetricsMiddleware.ts b/src/service/metrics/otelRequestMetricsMiddleware.ts index 6bfee65bd..7ebb453b1 100644 --- a/src/service/metrics/otelRequestMetricsMiddleware.ts +++ b/src/service/metrics/otelRequestMetricsMiddleware.ts @@ -52,7 +52,10 @@ export const addOtelRequestMetricsMiddleware = () => { if (responseLength && instruments) { instruments.responseSizes.record( responseLength, - { [RequestsMetricLabels.REQUEST_HANDLER]: ctx.requestHandlerName } + { + [RequestsMetricLabels.REQUEST_HANDLER]: ctx.requestHandlerName, + [RequestsMetricLabels.STATUS_CODE]: ctx.response.status, + } ) } @@ -72,6 +75,7 @@ export const addOtelRequestMetricsMiddleware = () => { hrToMillisFloat(process.hrtime(start)), { [RequestsMetricLabels.REQUEST_HANDLER]: ctx.requestHandlerName, + [RequestsMetricLabels.STATUS_CODE]: ctx.response.status, } )