From 41371248075a6cce9b83e37a58dbff61c3ab2c90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Taveira=20Ara=C3=BAjo?= Date: Tue, 28 May 2024 13:06:04 -0700 Subject: [PATCH] fix(tracing): gate lambda resource detector The lambda resource detector will error if executed from outside a lambda. We must gate it since we will want to use this tracing instrumentation in CLI tools. --- tracing/tracing.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tracing/tracing.go b/tracing/tracing.go index d3b8a199..6f945451 100644 --- a/tracing/tracing.go +++ b/tracing/tracing.go @@ -50,10 +50,14 @@ func NewTracerProvider(ctx context.Context) (*trace.TracerProvider, error) { return nil, fmt.Errorf("failed to handle OTLP endpoint auth: %w", err) } - res, err := resource.New(ctx, - resource.WithDetectors(lambda.NewResourceDetector()), + options := []resource.Option{ resource.WithFromEnv(), - ) + } + if os.Getenv("AWS_LAMBDA_FUNCTION_NAME") != "" { + options = append(options, resource.WithDetectors(lambda.NewResourceDetector())) + } + + res, err := resource.New(ctx, options...) if err != nil { return nil, fmt.Errorf("failed to create resource: %w", err) }