From 5abfb4f5b1e15cf405c1afff92727cad935c74d1 Mon Sep 17 00:00:00 2001 From: Sam Calder-Mason Date: Tue, 3 Oct 2023 16:39:27 +1000 Subject: [PATCH] Fix(cannon): Fix nil next panic (#222) * Fix(cannon): Fix nil next panic * refactor: Simplify NewResource function --- pkg/cannon/iterator/checkpoint_iterator.go | 10 +++++----- pkg/observability/tracing.go | 12 +----------- 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/pkg/cannon/iterator/checkpoint_iterator.go b/pkg/cannon/iterator/checkpoint_iterator.go index fe4617d2..7dab9b09 100644 --- a/pkg/cannon/iterator/checkpoint_iterator.go +++ b/pkg/cannon/iterator/checkpoint_iterator.go @@ -60,11 +60,11 @@ func (c *CheckpointIterator) Next(ctx context.Context) (next *xatu.CannonLocatio defer func() { if err != nil { span.RecordError(err) - } - - epoch, err := c.getEpochFromLocation(next) - if err == nil { - span.SetAttributes(attribute.Int64("next", int64(epoch))) + } else { + epoch, err := c.getEpochFromLocation(next) + if err == nil { + span.SetAttributes(attribute.Int64("next", int64(epoch))) + } } span.End() diff --git a/pkg/observability/tracing.go b/pkg/observability/tracing.go index 4ef63227..bf511bea 100644 --- a/pkg/observability/tracing.go +++ b/pkg/observability/tracing.go @@ -46,17 +46,7 @@ func SetupOTelSDK(ctx context.Context, tracerProvider *trace.TracerProvider) (sh } func NewResource(serviceName, serviceVersion string) (*resource.Resource, error) { - res, err := resource.New(context.Background(), - resource.WithFromEnv(), - resource.WithProcess(), - resource.WithOS(), - resource.WithContainer(), - resource.WithHost()) - if err != nil { - return nil, fmt.Errorf("creating resource: %w", err) - } - - return resource.Merge(res, + return resource.Merge(resource.Default(), resource.NewWithAttributes(semconv.SchemaURL, semconv.ServiceName(serviceName), semconv.ServiceVersion(serviceVersion),