Skip to content

Commit 88db1fb

Browse files
committed
fix: always use a UUID for instance ID
We can't use the Heroku instance ID because it can cause conflicting metrics to be sent with the same instance ID if the app uses clustering. This is the safest thing to do and it's what EDO are suggesting.
1 parent 14b4c76 commit 88db1fb

File tree

3 files changed

+7
-20
lines changed

3 files changed

+7
-20
lines changed

packages/app-info/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ This is derived from the dyno metadata
103103

104104
### `appInfo.instanceId`
105105

106-
Get the ID of the instance that's running the application. This is derived from `process.env.HEROKU_DYNO_ID` if present, otherwise it will be set to a random UUID that identifies the currently running process.
106+
Get the unique identifier for the instance that's running the application. This will be a different UUID for each running process, including cluster workers.
107107

108108
### `appInfo.semanticConventions`
109109

packages/app-info/lib/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ exports.herokuDynoId = process.env.HEROKU_DYNO_ID || null;
156156
* @readonly
157157
* @type {string}
158158
*/
159-
exports.instanceId = process.env.HEROKU_DYNO_ID || randomUUID();
159+
exports.instanceId = randomUUID();
160160

161161
/**
162162
* @type {import('@dotcom-reliability-kit/app-info').SemanticConventions}

packages/app-info/test/unit/lib/index.spec.js

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -382,27 +382,14 @@ describe('@dotcom-reliability-kit/app-info', () => {
382382

383383
beforeEach(() => {
384384
jest.resetModules();
385-
process.env.HEROKU_DYNO_ID = 'mock-heroku-dyno-id';
385+
randomUUID = require('node:crypto').randomUUID;
386+
randomUUID.mockReturnValue('mock-generated-uuid');
386387
appInfo = require('../../../lib');
387388
});
388389

389-
it('is set to `process.env.HEROKU_DYNO_ID`', () => {
390-
expect(appInfo.instanceId).toBe('mock-heroku-dyno-id');
391-
});
392-
393-
describe('when `process.env.HEROKU_DYNO_ID` is not defined', () => {
394-
beforeEach(() => {
395-
jest.resetModules();
396-
randomUUID = require('node:crypto').randomUUID;
397-
randomUUID.mockReturnValue('mock-generated-uuid');
398-
delete process.env.HEROKU_DYNO_ID;
399-
appInfo = require('../../../lib');
400-
});
401-
402-
it('is set to a random UUID', () => {
403-
expect(randomUUID).toHaveBeenCalledTimes(1);
404-
expect(appInfo.instanceId).toBe('mock-generated-uuid');
405-
});
390+
it('is set to a random UUID', () => {
391+
expect(randomUUID).toHaveBeenCalledTimes(1);
392+
expect(appInfo.instanceId).toBe('mock-generated-uuid');
406393
});
407394
});
408395

0 commit comments

Comments
 (0)