From 9baf3687b52d15589cab7f9fc16e13f7cf979298 Mon Sep 17 00:00:00 2001 From: Horst Gutmann Date: Wed, 13 Sep 2023 11:00:55 +0200 Subject: [PATCH] fix: Disable tracing if OTEL_EXPORTER_OTLP_ENDPOINT is not set (#163) --- otel/otel.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/otel/otel.go b/otel/otel.go index c616d1d8..32aa856d 100644 --- a/otel/otel.go +++ b/otel/otel.go @@ -17,6 +17,13 @@ import ( ) func Setup(ctx context.Context) func(context.Context) error { + endpoint := os.Getenv("OTEL_EXPORTER_OTLP_ENDPOINT") + if endpoint == "" { + log.Print("OTEL_EXPORTER_OTLP_ENDPOINT not set. Disabling tracing.") + return func(ctx context.Context) error { + return nil + } + } client := otlptracehttp.NewClient() exporter, err := otlptrace.New(ctx, client) if err != nil {