Skip to content

Commit

Permalink
fix(tracing): record error on mux (#304)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jta authored Jun 14, 2024
1 parent 7a20ec7 commit 3a6c024
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion pkg/tracing/mux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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
}

0 comments on commit 3a6c024

Please sign in to comment.