From e7743d89d44b7f106ac14f086ca32ce7d4a5884c Mon Sep 17 00:00:00 2001 From: Daniyel Rocha Date: Mon, 8 Sep 2025 15:01:10 -0300 Subject: [PATCH 1/3] Add global metrics init in startApp function This update introduces the MetricsAccumulator to the global scope, allowing both master and worker processes to access metrics --- src/service/index.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/service/index.ts b/src/service/index.ts index fd5a8373d..d531e1247 100644 --- a/src/service/index.ts +++ b/src/service/index.ts @@ -2,11 +2,16 @@ import { initializeTelemetry } from './telemetry' import cluster from 'cluster' import { HTTP_SERVER_PORT } from '../constants' +import { MetricsAccumulator } from '../metrics/MetricsAccumulator' import { getServiceJSON } from './loaders' import { LogLevel, logOnceToDevConsole } from './logger' export const startApp = async () => { await initializeTelemetry() + + // Initialize global.metrics for both master and worker processes + global.metrics = new MetricsAccumulator() + const serviceJSON = getServiceJSON() try { // if it is a master process then call setting up worker process @@ -27,3 +32,11 @@ export const startApp = async () => { export { appPath } from './loaders' +declare global { + namespace NodeJS { + interface Global { + metrics: MetricsAccumulator + } + } +} + From 8a920a7072fbed33640178765e0f353fa298f961 Mon Sep 17 00:00:00 2001 From: Daniyel Rocha Date: Mon, 8 Sep 2025 15:01:47 -0300 Subject: [PATCH 2/3] Remove global metrics declaration from worker service This change eliminates the global metrics declaration and initialization from the worker service --- src/service/worker/index.ts | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/service/worker/index.ts b/src/service/worker/index.ts index 0e64fcf29..f1a8ac607 100644 --- a/src/service/worker/index.ts +++ b/src/service/worker/index.ts @@ -267,13 +267,3 @@ export const startWorker = (serviceJSON: ServiceJSON) => { return app } - -global.metrics = new MetricsAccumulator() - -declare global { - namespace NodeJS { - interface Global { - metrics: MetricsAccumulator - } - } -} From cc0675c24e871ca06d9bac3f06365af382b3ea89 Mon Sep 17 00:00:00 2001 From: Daniyel Rocha Date: Mon, 8 Sep 2025 15:03:54 -0300 Subject: [PATCH 3/3] Release v7.2.1 --- CHANGELOG.md | 4 ++++ package.json | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3bd852e95..145e0f1c6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] +## [7.2.1] - 2025-09-08 +### Fixed +- Ensure `global.metrics` is initialized in both master and worker processes to prevent undefined errors in status tracking and metrics reporting + ## [7.2.0] - 2025-09-08 ### Changed - Add metrics instrumentation based on diagnostics lib diff --git a/package.json b/package.json index 2c9a1b25e..a4d9904da 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@vtex/api", - "version": "7.2.0", + "version": "7.2.1", "description": "VTEX I/O API client", "main": "lib/index.js", "typings": "lib/index.d.ts",