Skip to content

Commit a28fcd2

Browse files
committed
refactor(otel): get configuration from outside of initialization process
1 parent 1af17e6 commit a28fcd2

2 files changed

Lines changed: 7 additions & 5 deletions

File tree

src/instrumentation.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1+
import { getOtelConfig } from "./otel/config";
2+
13
export async function register() {
24
if (process.env.NEXT_RUNTIME === "nodejs") {
5+
const otelConfig = getOtelConfig();
6+
37
// NOTE: Explicitly initialize the logger here.
48
const { logger } = await import("./utils/logger");
59
logger.info({ message: "logger initialized" });
610

711
await import("./otel/lifecycle").then(({ initializeOtel }) =>
8-
initializeOtel()
12+
initializeOtel(otelConfig)
913
);
1014
}
1115
}

src/otel/lifecycle.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,16 @@ import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-grpc";
55
import { BatchLogRecordProcessor } from "@opentelemetry/sdk-logs";
66
import { PeriodicExportingMetricReader } from "@opentelemetry/sdk-metrics";
77
import { NodeSDK } from "@opentelemetry/sdk-node";
8-
import { getOtelConfig } from "./config";
8+
import type { OtelConfig } from "./config";
99

1010
let isInitialized = false;
1111

12-
export function initializeOtel() {
12+
export function initializeOtel(config: OtelConfig) {
1313
if (isInitialized) {
1414
return;
1515
}
1616

1717
try {
18-
const config = getOtelConfig();
19-
2018
if (!config) {
2119
console.log(
2220
"OpenTelemetry configuration not found, skipping initialization"

0 commit comments

Comments
 (0)