os-resource-attributes.ts 852 B

12345678910111213141516171819202122232425262728293031323334
  1. import * as os from 'node:os';
  2. import type { Attributes } from '@opentelemetry/api';
  3. import loggerFactory from '~/utils/logger';
  4. const logger = loggerFactory(
  5. 'growi:opentelemetry:custom-resource-attributes:os',
  6. );
  7. /**
  8. * Get OS information as OpenTelemetry Resource Attributes
  9. * These attributes are static and set once during application startup
  10. */
  11. export function getOsResourceAttributes(): Attributes {
  12. logger.info('Collecting OS resource attributes');
  13. const osInfo = {
  14. type: os.type(),
  15. platform: os.platform(),
  16. arch: os.arch(),
  17. totalmem: os.totalmem(),
  18. };
  19. const attributes: Attributes = {
  20. 'os.type': osInfo.type,
  21. 'os.platform': osInfo.platform,
  22. 'os.arch': osInfo.arch,
  23. 'os.totalmem': osInfo.totalmem,
  24. };
  25. logger.info({ attributes }, 'OS resource attributes collected');
  26. return attributes;
  27. }