Skip to content

Commit 7b7fc02

Browse files
committed
fix: start tracing only if enabled and endpoint exists
Signed-off-by: ferhat elmas <elmas.ferhat@gmail.com>
1 parent 228c507 commit 7b7fc02

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

src/internal/monitoring/otel-tracing.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,20 +56,22 @@ if (tracingEnabled && endpoint) {
5656
})
5757
}
5858

59-
// Create a BatchSpanProcessor using the trace exporter
60-
const batchProcessor = traceExporter ? new BatchSpanProcessor(traceExporter) : undefined
61-
6259
const spanProcessors: SpanProcessor[] = []
6360

64-
if (tracingEnabled) {
61+
if (tracingEnabled && traceExporter) {
6562
spanProcessors.push(new TenantSpanProcessor())
63+
spanProcessors.push(new BatchSpanProcessor(traceExporter))
64+
} else if (tracingEnabled) {
65+
logSchema.warning(
66+
logger,
67+
'[Otel] TRACING_ENABLED=true but no OTLP trace endpoint configured; skipping tracing SDK startup',
68+
{
69+
type: 'otel',
70+
}
71+
)
6672
}
6773

68-
if (batchProcessor) {
69-
spanProcessors.push(batchProcessor)
70-
}
71-
72-
if (tracingEnabled && spanProcessors.length > 0) {
74+
if (tracingEnabled && traceExporter && spanProcessors.length > 0) {
7375
// Configure the OpenTelemetry Node SDK
7476
const sdk = new NodeSDK({
7577
resource: resourceFromAttributes({

0 commit comments

Comments
 (0)