From f01fb8f40eb176645a3cf51b9063016aff81be4f Mon Sep 17 00:00:00 2001 From: David Hontecillas Date: Wed, 15 May 2024 22:04:26 +0200 Subject: [PATCH] improve error messages --- exporter/otelcollector/otelcollector.go | 4 ++-- state/state.go | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/exporter/otelcollector/otelcollector.go b/exporter/otelcollector/otelcollector.go index 239cd56..e2801c5 100644 --- a/exporter/otelcollector/otelcollector.go +++ b/exporter/otelcollector/otelcollector.go @@ -61,13 +61,13 @@ func httpExporterWithOptions(ctx context.Context, cfg config.OTLPExporter, tOpts = append(tOpts, otlptracehttp.WithEndpoint(endpoint)) exporter, err := otlptracehttp.New(ctx, tOpts...) if err != nil { - return nil, errors.New("cannot create http trace exporter") + return nil, errors.New("cannot create http trace exporter:" + err.Error()) } mOpts = append(mOpts, otlpmetrichttp.WithEndpoint(endpoint)) metricExporter, err := otlpmetrichttp.New(ctx, mOpts...) if err != nil { - return nil, errors.New("cannot create http metric exporter") + return nil, errors.New("cannot create http metric exporter:" + err.Error()) } return &OtelCollector{ diff --git a/state/state.go b/state/state.go index 5d51748..cd0dd22 100644 --- a/state/state.go +++ b/state/state.go @@ -131,14 +131,23 @@ func (s *OTELState) Tracer() trace.Tracer { // Meter returns a meter to create metric instruments. func (s *OTELState) Meter() metric.Meter { + if s == nil { + return nil + } return s.meter } func (s *OTELState) MeterProvider() metric.MeterProvider { + if s == nil { + return nil + } return s.meterProvider } func (s *OTELState) TracerProvider() trace.TracerProvider { + if s == nil { + return nil + } return s.tracerProvider } @@ -153,6 +162,9 @@ func (s *OTELState) Propagator() propagation.TextMapPropagator { // Shutdown performs the clean shutdown to be able to // flush pending traces and / or metrics. func (s *OTELState) Shutdown(ctx context.Context) { + if s == nil { + return + } if s.sdkTracerProvider != nil { s.sdkTracerProvider.Shutdown(ctx) }