refactor: Initialize telemetry with correct service name in Telemetry and InfrastructureStatus

This refactor updates the Telemetry and InfrastructureStatus components to initialize telemetry with the correct service name. By using the APP_NAME constant defined in the Index.ts file, the service name is now dynamically set, ensuring accurate telemetry tracking.

Files modified:
- App/Index.ts
- CommonServer/Utils/Telemetry.ts
This commit is contained in:
Simon Larsen
2024-08-02 16:47:55 -06:00
parent c9e67311e7
commit e60b06d014
3 changed files with 11 additions and 18 deletions

View File

@@ -22,11 +22,12 @@ const APP_NAME: string = "app";
const init: PromiseVoidFunction = async (): Promise<void> => {
try {
// Initialize telemetry
Telemetry.init({
serviceName: APP_NAME,
});
const statusCheck: PromiseVoidFunction = async (): Promise<void> => {
// Check the status of infrastructure components
return await InfrastructureStatus.checkStatus({

View File

@@ -102,6 +102,7 @@ export default class Telemetry {
}
public static init(data: { serviceName: string }): opentelemetry.NodeSDK {
if (!this.sdk) {
const headers: Dictionary<string> = this.getHeaders();
@@ -149,7 +150,7 @@ export default class Telemetry {
logs.setGlobalLoggerProvider(loggerProvider);
this.logger = logs.getLogger("default");
const nodeSdkConfiguration: Partial<opentelemetry.NodeSDKConfiguration> =
{
@@ -189,10 +190,10 @@ export default class Telemetry {
public static getLogger(): Logger {
if (!this.logger) {
throw new Error("Logger not initialized");
this.logger = logs.getLogger("default");
}
return this.logger!;
return this.logger;
}
public static getMeterProvider(): MeterProvider {

View File

@@ -47,6 +47,9 @@ x-common-variables: &common-variables
ADMIN_DASHBOARD_PORT: ${ADMIN_DASHBOARD_PORT}
ISOLATED_VM_PORT: ${ISOLATED_VM_PORT}
OPENTELEMETRY_EXPORTER_OTLP_ENDPOINT: ${OPENTELEMETRY_EXPORTER_OTLP_ENDPOINT}
OPENTELEMETRY_EXPORTER_OTLP_HEADERS: ${OPENTELEMETRY_EXPORTER_OTLP_HEADERS}
x-common-ui-variables: &common-ui-variables
<<: *common-variables
IS_SERVER: "false"
@@ -172,8 +175,6 @@ services:
environment:
<<: *common-ui-variables
PORT: ${ACCOUNTS_PORT}
OPENTELEMETRY_EXPORTER_OTLP_ENDPOINT: ${OPENTELEMETRY_EXPORTER_OTLP_ENDPOINT}
OPENTELEMETRY_EXPORTER_OTLP_HEADERS: ${OPENTELEMETRY_EXPORTER_OTLP_HEADERS}
logging:
driver: "local"
@@ -204,8 +205,7 @@ services:
environment:
<<: *common-ui-variables
PORT: ${ADMIN_DASHBOARD_PORT}
OPENTELEMETRY_EXPORTER_OTLP_ENDPOINT: ${OPENTELEMETRY_EXPORTER_OTLP_ENDPOINT}
OPENTELEMETRY_EXPORTER_OTLP_HEADERS: ${OPENTELEMETRY_EXPORTER_OTLP_HEADERS}
logging:
driver: "local"
options:
@@ -218,8 +218,7 @@ services:
environment:
<<: *common-ui-variables
PORT: ${DASHBOARD_PORT}
OPENTELEMETRY_EXPORTER_OTLP_ENDPOINT: ${OPENTELEMETRY_EXPORTER_OTLP_ENDPOINT}
OPENTELEMETRY_EXPORTER_OTLP_HEADERS: ${OPENTELEMETRY_EXPORTER_OTLP_HEADERS}
logging:
driver: "local"
options:
@@ -234,8 +233,6 @@ services:
environment:
<<: *common-ui-variables
PORT: ${STATUS_PAGE_PORT}
OPENTELEMETRY_EXPORTER_OTLP_ENDPOINT: ${OPENTELEMETRY_EXPORTER_OTLP_ENDPOINT}
OPENTELEMETRY_EXPORTER_OTLP_HEADERS: ${OPENTELEMETRY_EXPORTER_OTLP_HEADERS}
logging:
driver: "local"
options:
@@ -270,8 +267,6 @@ services:
INTERNAL_SMTP_EMAIL: ${INTERNAL_SMTP_EMAIL}
INTERNAL_SMTP_FROM_NAME: ${INTERNAL_SMTP_FROM_NAME}
INTERNAL_SMTP_PASSWORD: ${INTERNAL_SMTP_PASSWORD}
OPENTELEMETRY_EXPORTER_OTLP_ENDPOINT: ${OPENTELEMETRY_EXPORTER_OTLP_ENDPOINT}
OPENTELEMETRY_EXPORTER_OTLP_HEADERS: ${OPENTELEMETRY_EXPORTER_OTLP_HEADERS}
logging:
driver: "local"
options:
@@ -292,8 +287,6 @@ services:
PROBE_CUSTOM_CODE_MONITOR_SCRIPT_TIMEOUT_IN_MS: ${GLOBAL_PROBE_1_CUSTOM_CODE_MONITOR_SCRIPT_TIMEOUT_IN_MS}
ONEUPTIME_URL: ${GLOBAL_PROBE_1_ONEUPTIME_URL}
PROBE_MONITOR_FETCH_LIMIT: ${GLOBAL_PROBE_1_MONITOR_FETCH_LIMIT}
OPENTELEMETRY_EXPORTER_OTLP_ENDPOINT: ${OPENTELEMETRY_EXPORTER_OTLP_ENDPOINT}
OPENTELEMETRY_EXPORTER_OTLP_HEADERS: ${OPENTELEMETRY_EXPORTER_OTLP_HEADERS}
logging:
driver: "local"
options:
@@ -314,8 +307,6 @@ services:
PROBE_SYNTHETIC_MONITOR_SCRIPT_TIMEOUT_IN_MS: ${GLOBAL_PROBE_2_SYNTHETIC_MONITOR_SCRIPT_TIMEOUT_IN_MS}
PROBE_CUSTOM_CODE_MONITOR_SCRIPT_TIMEOUT_IN_MS: ${GLOBAL_PROBE_2_CUSTOM_CODE_MONITOR_SCRIPT_TIMEOUT_IN_MS}
PROBE_MONITOR_FETCH_LIMIT: ${GLOBAL_PROBE_2_MONITOR_FETCH_LIMIT}
OPENTELEMETRY_EXPORTER_OTLP_ENDPOINT: ${OPENTELEMETRY_EXPORTER_OTLP_ENDPOINT}
OPENTELEMETRY_EXPORTER_OTLP_HEADERS: ${OPENTELEMETRY_EXPORTER_OTLP_HEADERS}
logging:
driver: "local"
options: