application-resource-attributes.ts 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import type { Attributes } from '@opentelemetry/api';
  2. import loggerFactory from '~/utils/logger';
  3. const logger = loggerFactory(
  4. 'growi:opentelemetry:custom-resource-attributes:application',
  5. );
  6. /**
  7. * Get application fixed information as OpenTelemetry Resource Attributes
  8. * These attributes are static and set once during application startup
  9. */
  10. export async function getApplicationResourceAttributes(): Promise<Attributes> {
  11. logger.info('Collecting application resource attributes');
  12. try {
  13. // Dynamic import to avoid circular dependencies
  14. const { growiInfoService } = await import('~/server/service/growi-info');
  15. const growiInfo = await growiInfoService.getGrowiInfo({});
  16. const attributes: Attributes = {
  17. // Service configuration (rarely changes after system setup)
  18. 'growi.service.type': growiInfo.type,
  19. 'growi.deployment.type': growiInfo.deploymentType,
  20. };
  21. logger.info({ attributes }, 'Application resource attributes collected');
  22. return attributes;
  23. } catch (error) {
  24. logger.error(
  25. { err: error },
  26. 'Failed to collect application resource attributes',
  27. );
  28. return {};
  29. }
  30. }