Skip to content

Commit

Permalink
capitalize recursion detection trace ID var name
Browse files Browse the repository at this point in the history
  • Loading branch information
Tianyi Wang committed Apr 22, 2023
1 parent 6f80948 commit 75061a4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
10 changes: 5 additions & 5 deletions aws/middleware/recursion_detection.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
)

const envAwsLambdaFunctionName = "AWS_LAMBDA_FUNCTION_NAME"
const envAmznTraceId = "_X_AMZN_TRACE_ID"
const amznTraceIdHeader = "X-Amzn-Trace-Id"
const envAmznTraceID = "_X_AMZN_TRACE_ID"
const amznTraceIDHeader = "X-Amzn-Trace-Id"

// AddRecursionDetection adds recursionDetection to the middleware stack
func AddRecursionDetection(stack *middleware.Stack) error {
Expand Down Expand Up @@ -38,15 +38,15 @@ func (m *RecursionDetection) HandleBuild(
}

_, hasLambdaEnv := os.LookupEnv(envAwsLambdaFunctionName)
xAmznTraceID, hasTraceID := os.LookupEnv(envAmznTraceId)
value := req.Header.Get(amznTraceIdHeader)
xAmznTraceID, hasTraceID := os.LookupEnv(envAmznTraceID)
value := req.Header.Get(amznTraceIDHeader)
// only set the X-Amzn-Trace-Id header when it is not set initially, the
// current environment is Lambda and the _X_AMZN_TRACE_ID env variable exists
if value != "" || !hasLambdaEnv || !hasTraceID {
return next.HandleBuild(ctx, in)
}

req.Header.Set(amznTraceIdHeader, percentEncode(xAmznTraceID))
req.Header.Set(amznTraceIDHeader, percentEncode(xAmznTraceID))
return next.HandleBuild(ctx, in)
}

Expand Down
6 changes: 3 additions & 3 deletions aws/middleware/recursion_detection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ func TestRecursionDetection(t *testing.T) {
defer restoreEnv()

setEnvVar(t, envAwsLambdaFunctionName, c.LambdaFuncName)
setEnvVar(t, envAmznTraceId, c.TraceID)
setEnvVar(t, envAmznTraceID, c.TraceID)

req := smithyhttp.NewStackRequest().(*smithyhttp.Request)
if c.HeaderBefore != "" {
req.Header.Set(amznTraceIdHeader, c.HeaderBefore)
req.Header.Set(amznTraceIDHeader, c.HeaderBefore)
}
var updatedRequest *smithyhttp.Request
m := RecursionDetection{}
Expand All @@ -69,7 +69,7 @@ func TestRecursionDetection(t *testing.T) {
t.Fatalf("expect no error, got %v", err)
}

if e, a := c.HeaderAfter, updatedRequest.Header.Get(amznTraceIdHeader); e != a {
if e, a := c.HeaderAfter, updatedRequest.Header.Get(amznTraceIDHeader); e != a {
t.Errorf("expect header value %v found, got %v", e, a)
}
})
Expand Down

0 comments on commit 75061a4

Please sign in to comment.