Skip to content

Commit

Permalink
refactor: Initialize telemetry with correct service name in Telemetry…
Browse files Browse the repository at this point in the history
… 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
  • Loading branch information
simlarsen committed Aug 2, 2024
1 parent c9e6731 commit e60b06d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 18 deletions.
3 changes: 2 additions & 1 deletion App/Index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
7 changes: 4 additions & 3 deletions CommonServer/Utils/Telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -149,7 +150,7 @@ export default class Telemetry {

logs.setGlobalLoggerProvider(loggerProvider);

this.logger = logs.getLogger("default");


const nodeSdkConfiguration: Partial<opentelemetry.NodeSDKConfiguration> =
{
Expand Down Expand Up @@ -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 {
Expand Down
19 changes: 5 additions & 14 deletions docker-compose.base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand Down

0 comments on commit e60b06d

Please sign in to comment.