diff --git a/Sources/AWSLambdaRuntimeCore/ControlPlaneRequest.swift b/Sources/AWSLambdaRuntimeCore/ControlPlaneRequest.swift index 48da5237..14c5f2a7 100644 --- a/Sources/AWSLambdaRuntimeCore/ControlPlaneRequest.swift +++ b/Sources/AWSLambdaRuntimeCore/ControlPlaneRequest.swift @@ -51,14 +51,10 @@ struct Invocation: Hashable { throw Lambda.RuntimeError.invocationMissingHeader(AmazonHeaders.invokedFunctionARN) } - guard let traceID = headers.first(name: AmazonHeaders.traceID) else { - throw Lambda.RuntimeError.invocationMissingHeader(AmazonHeaders.traceID) - } - self.requestID = requestID self.deadlineInMillisSinceEpoch = unixTimeInMilliseconds self.invokedFunctionARN = invokedFunctionARN - self.traceID = traceID + self.traceID = headers.first(name: AmazonHeaders.traceID) ?? "Root=\(AmazonHeaders.generateXRayTraceID());Sampled=0" self.clientContext = headers["Lambda-Runtime-Client-Context"].first self.cognitoIdentity = headers["Lambda-Runtime-Cognito-Identity"].first } diff --git a/Tests/AWSLambdaRuntimeCoreTests/ControlPlaneRequestTests.swift b/Tests/AWSLambdaRuntimeCoreTests/ControlPlaneRequestTests.swift new file mode 100644 index 00000000..d55e0b67 --- /dev/null +++ b/Tests/AWSLambdaRuntimeCoreTests/ControlPlaneRequestTests.swift @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the SwiftAWSLambdaRuntime open source project +// +// Copyright (c) 2022 Apple Inc. and the SwiftAWSLambdaRuntime project authors +// Licensed under Apache License v2.0 +// +// See LICENSE.txt for license information +// See CONTRIBUTORS.txt for the list of SwiftAWSLambdaRuntime project authors +// +// SPDX-License-Identifier: Apache-2.0 +// +//===----------------------------------------------------------------------===// + +@testable import AWSLambdaRuntimeCore +import NIOHTTP1 +import XCTest + +class InvocationTest: XCTestCase { + func testInvocationTraceID() throws { + let headers = HTTPHeaders([ + (AmazonHeaders.requestID, "test"), + (AmazonHeaders.deadline, String(Date(timeIntervalSinceNow: 60).millisSinceEpoch)), + (AmazonHeaders.invokedFunctionARN, "arn:aws:lambda:us-east-1:123456789012:function:custom-runtime"), + ]) + + var invocation: Invocation? + + XCTAssertNoThrow(invocation = try Invocation(headers: headers)) + XCTAssertNotNil(invocation) + + guard !invocation!.traceID.isEmpty else { + XCTFail("Invocation traceID is empty") + return + } + } +} diff --git a/scripts/soundness.sh b/scripts/soundness.sh index eb9e173b..d9145903 100755 --- a/scripts/soundness.sh +++ b/scripts/soundness.sh @@ -19,7 +19,7 @@ here="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" function replace_acceptable_years() { # this needs to replace all acceptable forms with 'YEARS' - sed -e 's/2017-2018/YEARS/' -e 's/2017-2020/YEARS/' -e 's/2017-2021/YEARS/' -e 's/2020-2021/YEARS/' -e 's/2019/YEARS/' -e 's/2020/YEARS/' -e 's/2021/YEARS/' + sed -e 's/2017-2018/YEARS/' -e 's/2017-2020/YEARS/' -e 's/2017-2021/YEARS/' -e 's/2020-2021/YEARS/' -e 's/2019/YEARS/' -e 's/2020/YEARS/' -e 's/2021/YEARS/' -e 's/2022/YEARS/' } printf "=> Checking for unacceptable language... "