Просмотр исходного кода

refactor(otel-attributes-cleanup): remove os.totalmem from OS resource attributes

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Yuki Takei 13 часов назад
Родитель
Сommit
75d8812d24

+ 1 - 1
.kiro/specs/otel-attributes-cleanup/tasks.md

@@ -1,7 +1,7 @@
 # Implementation Plan
 
 - [ ] 1. Resource Attribute cleanup
-- [ ] 1.1 (P) Remove os.totalmem from OS resource attributes
+- [x] 1.1 (P) Remove os.totalmem from OS resource attributes
   - `os-resource-attributes.ts` の `osInfo` オブジェクトおよび返り値 attributes から `totalmem` 関連の行を削除する。`os.type` / `os.platform` / `os.arch` は維持する。
   - `os-resource-attributes.spec.ts` の `vi.mock('node:os')` のスタブから `totalmem: vi.fn()` を除去し、3 つの既存テストケースから `os.totalmem` 関連の期待値および `mockOs.totalmem` 呼び出し検証を削除する。
   - 完了状態: `pnpm vitest run os-resource-attributes.spec` がパスし、`getOsResourceAttributes()` の戻り値が `os.type` / `os.platform` / `os.arch` の 3 キーのみとなる。

+ 2 - 12
apps/app/src/features/opentelemetry/server/custom-resource-attributes/os-resource-attributes.spec.ts

@@ -5,7 +5,6 @@ vi.mock('node:os', () => ({
   type: vi.fn(),
   platform: vi.fn(),
   arch: vi.fn(),
-  totalmem: vi.fn(),
 }));
 
 describe('getOsResourceAttributes', () => {
@@ -13,7 +12,6 @@ describe('getOsResourceAttributes', () => {
     type: ReturnType<typeof vi.fn>;
     platform: ReturnType<typeof vi.fn>;
     arch: ReturnType<typeof vi.fn>;
-    totalmem: ReturnType<typeof vi.fn>;
   };
 
   beforeEach(async () => {
@@ -28,13 +26,11 @@ describe('getOsResourceAttributes', () => {
       type: 'Linux',
       platform: 'linux' as const,
       arch: 'x64',
-      totalmem: 16777216000,
     };
 
     mockOs.type.mockReturnValue(mockOsData.type);
     mockOs.platform.mockReturnValue(mockOsData.platform);
     mockOs.arch.mockReturnValue(mockOsData.arch);
-    mockOs.totalmem.mockReturnValue(mockOsData.totalmem);
 
     const result = getOsResourceAttributes();
 
@@ -42,8 +38,8 @@ describe('getOsResourceAttributes', () => {
       'os.type': 'Linux',
       'os.platform': 'linux',
       'os.arch': 'x64',
-      'os.totalmem': 16777216000,
     });
+    expect(result).not.toHaveProperty('os.totalmem');
   });
 
   it('should call all required os module functions', () => {
@@ -51,14 +47,12 @@ describe('getOsResourceAttributes', () => {
     mockOs.type.mockReturnValue('Linux');
     mockOs.platform.mockReturnValue('linux');
     mockOs.arch.mockReturnValue('x64');
-    mockOs.totalmem.mockReturnValue(16777216000);
 
     getOsResourceAttributes();
 
     expect(mockOs.type).toHaveBeenCalledOnce();
     expect(mockOs.platform).toHaveBeenCalledOnce();
     expect(mockOs.arch).toHaveBeenCalledOnce();
-    expect(mockOs.totalmem).toHaveBeenCalledOnce();
   });
 
   it('should handle different OS types correctly', () => {
@@ -68,13 +62,11 @@ describe('getOsResourceAttributes', () => {
           type: 'Windows_NT',
           platform: 'win32',
           arch: 'x64',
-          totalmem: 8589934592,
         },
         expected: {
           'os.type': 'Windows_NT',
           'os.platform': 'win32',
           'os.arch': 'x64',
-          'os.totalmem': 8589934592,
         },
       },
       {
@@ -82,13 +74,11 @@ describe('getOsResourceAttributes', () => {
           type: 'Darwin',
           platform: 'darwin',
           arch: 'arm64',
-          totalmem: 17179869184,
         },
         expected: {
           'os.type': 'Darwin',
           'os.platform': 'darwin',
           'os.arch': 'arm64',
-          'os.totalmem': 17179869184,
         },
       },
     ];
@@ -97,10 +87,10 @@ describe('getOsResourceAttributes', () => {
       mockOs.type.mockReturnValue(input.type);
       mockOs.platform.mockReturnValue(input.platform as NodeJS.Platform);
       mockOs.arch.mockReturnValue(input.arch);
-      mockOs.totalmem.mockReturnValue(input.totalmem);
 
       const result = getOsResourceAttributes();
       expect(result).toEqual(expected);
+      expect(result).not.toHaveProperty('os.totalmem');
     });
   });
 });

+ 0 - 2
apps/app/src/features/opentelemetry/server/custom-resource-attributes/os-resource-attributes.ts

@@ -18,14 +18,12 @@ export function getOsResourceAttributes(): Attributes {
     type: os.type(),
     platform: os.platform(),
     arch: os.arch(),
-    totalmem: os.totalmem(),
   };
 
   const attributes: Attributes = {
     'os.type': osInfo.type,
     'os.platform': osInfo.platform,
     'os.arch': osInfo.arch,
-    'os.totalmem': osInfo.totalmem,
   };
 
   logger.info({ attributes }, 'OS resource attributes collected');