32 lines
926 B
TypeScript
32 lines
926 B
TypeScript
import { getProcessInstanceId } from '../config/instance-id.js';
|
|
|
|
export type ServiceIdentity = {
|
|
readonly serviceName: string;
|
|
readonly serviceVersion: string;
|
|
readonly instanceId: string;
|
|
};
|
|
|
|
function fromEnv(defaultServiceName: string): ServiceIdentity {
|
|
const serviceName = process.env.OTEL_SERVICE_NAME?.trim() || defaultServiceName;
|
|
const prefix = serviceName.toLowerCase().includes('worker') ? 'wrk' : 'rep';
|
|
return {
|
|
serviceName,
|
|
serviceVersion: process.env.SERVICE_VERSION?.trim() || 'dev',
|
|
instanceId: getProcessInstanceId(prefix),
|
|
};
|
|
}
|
|
|
|
let current = fromEnv('messenger');
|
|
|
|
/** service.name / service.version / service.instance.id, общие для всех сигналов. */
|
|
export function serviceIdentity(): ServiceIdentity {
|
|
return current;
|
|
}
|
|
|
|
export function resolveServiceIdentity(
|
|
defaultServiceName: string,
|
|
): ServiceIdentity {
|
|
current = fromEnv(defaultServiceName);
|
|
return current;
|
|
}
|