Skip to content

Commit 334d720

Browse files
committed
refactor: extract common log fields and remove data from diagnosticsLog
This commit addresses PR review feedback by refactoring the logger to improve code maintainability and prevent data duplication between console and diagnostics client logs. Key changes: - Created commonLogFields object containing shared fields: __VTEX_IO_LOG, level, operationId, requestId, and traceId - Removed data field from diagnosticsLog by keeping it only in inflatedLog - Spread commonLogFields at the end of both log objects to maintain key order The refactoring ensures: 1. Console logs (inflatedLog) include all fields needed for fluent-bit/OpenSearch 2. Diagnostics client logs (diagnosticsLog) use semantic convention keys without data duplication 3. Common fields are defined once and reused consistently across both log formats Addresses review comments from @juliobguedes: - Comment 1: Remove data from diagnosticsLog to avoid duplications - Comment 2: Extract commonLogFields to reduce code duplication
1 parent 38137e8 commit 334d720

1 file changed

Lines changed: 9 additions & 10 deletions

File tree

src/service/logger/logger.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -79,17 +79,21 @@ export class Logger {
7979
cleanLog(data)
8080

8181
/* tslint:disable:object-literal-sort-keys */
82-
const inflatedLog = {
82+
const commonLogFields = {
8383
__VTEX_IO_LOG: true,
8484
level,
85+
operationId: this.operationId,
86+
requestId: this.requestId,
87+
... (this.tracingState?.isTraceSampled ? { traceId: this.tracingState.traceId } : null),
88+
}
89+
90+
const inflatedLog = {
8591
app,
8692
account: this.account,
8793
workspace: this.workspace,
8894
production: this.production,
89-
operationId: this.operationId,
90-
requestId: this.requestId,
9195
data,
92-
... (this.tracingState?.isTraceSampled ? { traceId: this.tracingState.traceId } : null),
96+
...commonLogFields,
9397
}
9498

9599
// Mark third-party apps logs to send to skidder
@@ -103,17 +107,12 @@ export class Logger {
103107
console.log(JSON.stringify(inflatedLog))
104108

105109
const diagnosticsLog = {
106-
__VTEX_IO_LOG: true,
107-
level,
108110
[AttributeKeys.VTEX_IO_APP_ID]: app,
109111
[AttributeKeys.VTEX_ACCOUNT_NAME]: this.account,
110112
[AttributeKeys.VTEX_IO_WORKSPACE_NAME]: this.workspace,
111113
[AttributeKeys.VTEX_IO_WORKSPACE_TYPE]: this.production ? 'production' : 'development',
112114
[AttributeKeys.VTEX_IO_APP_AUTHOR_TYPE]: APP.IS_THIRD_PARTY() ? '3p' : '1p',
113-
operationId: this.operationId,
114-
requestId: this.requestId,
115-
data,
116-
... (this.tracingState?.isTraceSampled ? { traceId: this.tracingState.traceId } : null),
115+
...commonLogFields,
117116
}
118117

119118
if (this.logClient) {

0 commit comments

Comments
 (0)