Skip to content

Commit f6ed039

Browse files
authored
Fix undefined errors in metrics reports (#607)
* 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 * Remove global metrics declaration from worker service This change eliminates the global metrics declaration and initialization from the worker service * Release v7.2.1
1 parent f8265a7 commit f6ed039

File tree

4 files changed

+18
-11
lines changed

4 files changed

+18
-11
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
77

88
## [Unreleased]
99

10+
## [7.2.1] - 2025-09-08
11+
### Fixed
12+
- Ensure `global.metrics` is initialized in both master and worker processes to prevent undefined errors in status tracking and metrics reporting
13+
1014
## [7.2.0] - 2025-09-08
1115
### Changed
1216
- Add metrics instrumentation based on diagnostics lib

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@vtex/api",
3-
"version": "7.2.0",
3+
"version": "7.2.1",
44
"description": "VTEX I/O API client",
55
"main": "lib/index.js",
66
"typings": "lib/index.d.ts",

src/service/index.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,16 @@ import { initializeTelemetry } from './telemetry'
22
import cluster from 'cluster'
33

44
import { HTTP_SERVER_PORT } from '../constants'
5+
import { MetricsAccumulator } from '../metrics/MetricsAccumulator'
56
import { getServiceJSON } from './loaders'
67
import { LogLevel, logOnceToDevConsole } from './logger'
78

89
export const startApp = async () => {
910
await initializeTelemetry()
11+
12+
// Initialize global.metrics for both master and worker processes
13+
global.metrics = new MetricsAccumulator()
14+
1015
const serviceJSON = getServiceJSON()
1116
try {
1217
// if it is a master process then call setting up worker process
@@ -27,3 +32,11 @@ export const startApp = async () => {
2732

2833
export { appPath } from './loaders'
2934

35+
declare global {
36+
namespace NodeJS {
37+
interface Global {
38+
metrics: MetricsAccumulator
39+
}
40+
}
41+
}
42+

src/service/worker/index.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -267,13 +267,3 @@ export const startWorker = (serviceJSON: ServiceJSON) => {
267267

268268
return app
269269
}
270-
271-
global.metrics = new MetricsAccumulator()
272-
273-
declare global {
274-
namespace NodeJS {
275-
interface Global {
276-
metrics: MetricsAccumulator
277-
}
278-
}
279-
}

0 commit comments

Comments
 (0)