Skip to content

Commit 33cec70

Browse files
committed
fix : #404 : trace level shows the first kb of the payload before being decoded
1 parent dede067 commit 33cec70

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

Sources/AWSLambdaRuntime/Lambda.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,21 @@ public enum Lambda {
4444
let (invocation, writer) = try await runtimeClient.nextInvocation()
4545
logger[metadataKey: "aws-request-id"] = "\(invocation.metadata.requestID)"
4646

47+
// when log level is trace or lower, print the first Kb of the payload
48+
let bytes = invocation.event
49+
var metadata: Logger.Metadata? = nil
50+
if logger.logLevel <= .trace,
51+
let buffer = bytes.getSlice(at: 0, length: min(bytes.readableBytes, 1024))
52+
{
53+
metadata = [
54+
"Event's first bytes": .string(String(buffer: buffer) + (bytes.readableBytes > 1024 ? "..." : ""))
55+
]
56+
}
57+
logger.trace(
58+
"Sending invocation event to lambda handler",
59+
metadata: metadata
60+
)
61+
4762
do {
4863
try await handler.handle(
4964
invocation.event,

0 commit comments

Comments
 (0)