From e9b4f08d933c2b94d07700672466d2aa8ebd9527 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Taveira=20Ara=C3=BAjo?= Date: Fri, 14 Jun 2024 09:42:22 -0700 Subject: [PATCH] fix(tracing): record error on mux The otellambda wrapper does not record an error when the invoked lambda fails. We need to do it ourselves for now, otherwise the respective KPIs will be skewed. --- pkg/tracing/mux.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/pkg/tracing/mux.go b/pkg/tracing/mux.go index c82b7172..3d308959 100644 --- a/pkg/tracing/mux.go +++ b/pkg/tracing/mux.go @@ -6,6 +6,7 @@ import ( "github.com/aws/aws-lambda-go/lambda" "go.opentelemetry.io/contrib/instrumentation/github.com/aws/aws-lambda-go/otellambda" "go.opentelemetry.io/otel/attribute" + "go.opentelemetry.io/otel/codes" sdktrace "go.opentelemetry.io/otel/sdk/trace" "go.opentelemetry.io/otel/trace" ) @@ -27,6 +28,14 @@ type LambdaHandler struct { func (h *LambdaHandler) Invoke(ctx context.Context, payload []byte) ([]byte, error) { span := trace.SpanFromContext(ctx) span.SetAttributes(payloadKey.String(string(payload))) + resp, err := h.Handler.Invoke(ctx, payload) + + // surprisingly, otellambda wrapper does not emit the error + if err != nil { + span.RecordError(err) + span.SetStatus(codes.Error, err.Error()) + } + // nolint: wrapcheck - return h.Handler.Invoke(ctx, payload) + return resp, err }