Skip to content

Commit 4f53725

Browse files
committed
add parameter valied check
1 parent 604ba65 commit 4f53725

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

pkg/gofr/gofr.go

+12-10
Original file line numberDiff line numberDiff line change
@@ -317,13 +317,25 @@ func (a *App) initTracer() {
317317
tracerHost := a.Config.Get("TRACER_HOST")
318318
tracerPort := a.Config.GetOrDefault("TRACER_PORT", "9411")
319319

320+
if traceExporter == "" {
321+
a.Logger().Errorf("missing TRACE_EXPORTER config, should be provided with TRACER_URL to enable tracing")
322+
323+
return
324+
}
325+
326+
if tracerHost == "" && tracerURL == "" && traceExporter != traceExporterGoFr {
327+
a.Logger().Errorf("missing TRACER_URL config, should be provided with TRACE_EXPORTER to enable tracing")
328+
return
329+
}
330+
320331
if tracerURL == "" && tracerHost != "" {
321332
a.Logger().Warn("TRACER_HOST and TRACER_PORT are deprecated, use TRACER_URL instead")
322333

323334
tracerURL = fmt.Sprintf("%s:%s", tracerHost, tracerPort)
324335
}
325336

326337
exporter, err := a.getExporter(context.Background(), traceExporter, tracerURL, authHeader)
338+
327339
if err != nil {
328340
a.container.Error(err)
329341
}
@@ -339,16 +351,6 @@ func (a *App) initTracer() {
339351
func (a *App) getExporter(ctx context.Context, name, url, authHeader string) (sdktrace.SpanExporter, error) {
340352
var exporter sdktrace.SpanExporter
341353

342-
if name == "" {
343-
a.Logger().Errorf("missing TRACE_EXPORTER config, should be provided with TRACER_URL to enable tracing")
344-
return exporter, nil
345-
}
346-
347-
if url == "" && name != traceExporterGoFr {
348-
a.Logger().Errorf("missing TRACER_URL config, should be provided with TRACE_EXPORTER to enable tracing")
349-
return exporter, nil
350-
}
351-
352354
switch strings.ToLower(name) {
353355
case traceExporterOTLP:
354356
return a.buildOpenTelemetryProtocol(ctx, url, strings.ToLower(name), authHeader)

0 commit comments

Comments
 (0)