From a08032bf51f1328cd9fc7904fe654be494772119 Mon Sep 17 00:00:00 2001 From: Moshe Immermam Date: Sun, 18 Aug 2024 22:53:50 +0300 Subject: [PATCH] chore: test fix --- telemetry/otel.go | 8 ++++++++ tests/setup/common.go | 6 +----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/telemetry/otel.go b/telemetry/otel.go index a05bbc17..a82dc52a 100644 --- a/telemetry/otel.go +++ b/telemetry/otel.go @@ -7,6 +7,7 @@ import ( "github.com/flanksource/commons/collections" "github.com/flanksource/commons/logger" + "github.com/samber/lo" "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/exporters/otlp/otlptrace" @@ -24,6 +25,13 @@ var OtelAttributes []attribute.KeyValue var OtelInsecure bool func InitTracer() func(context.Context) error { + OtelCollectorURL = lo.CoalesceOrEmpty(OtelCollectorURL, os.Getenv("OTEL_EXPORTER_OTLP_ENDPOINT")) + + if OtelCollectorURL == "" { + return func(_ context.Context) error { + return nil + } + } var secureOption otlptracegrpc.Option if !OtelInsecure { secureOption = otlptracegrpc.WithTLSCredentials(credentials.NewClientTLSFromCert(nil, "")) diff --git a/tests/setup/common.go b/tests/setup/common.go index 9effa1c9..4dc3518a 100644 --- a/tests/setup/common.go +++ b/tests/setup/common.go @@ -67,7 +67,6 @@ func MustDB() *sql.DB { var WithoutDummyData = "without_dummy_data" var WithExistingDatabase = "with_existing_database" var recreateDatabase = os.Getenv("DUTY_DB_CREATE") != "false" -var otel = os.Getenv("OTEL_EXPORTER_OTLP_ENDPOINT") var ShutdownHooks []func(ctx gocontext.Context) error @@ -96,11 +95,8 @@ func BeforeSuiteFn(args ...interface{}) context.Context { logger.Errorf("Failed to load test properties: %v", err) } - if otel != "" { - logger.Infof("Sending traces to %s", otel) + ShutdownHooks = append(ShutdownHooks, telemetry.InitTracer()) - ShutdownHooks = append(ShutdownHooks, telemetry.InitTracer("tests", otel, true)) - } var err error importDummyData := true