Revert "Add logGroupName and logStreamName to LambdaContext (#663)"

This reverts commit e13b94177e.
This commit is contained in:
Sebastien Stormacq
2026-05-11 20:05:26 +02:00
parent e13b94177e
commit 0d160f931b
3 changed files with 7 additions and 98 deletions
+1 -6
View File
@@ -85,9 +85,6 @@ public enum Lambda {
) async throws where Handler: StreamingLambdaHandler {
var handler = handler
let logGroupName = Lambda.env("AWS_LAMBDA_LOG_GROUP_NAME")
let logStreamName = Lambda.env("AWS_LAMBDA_LOG_STREAM_NAME")
do {
while !Task.isCancelled {
@@ -131,9 +128,7 @@ public enum Lambda {
deadline: LambdaClock.Instant(
millisecondsSinceEpoch: invocation.metadata.deadlineInMillisSinceEpoch
),
logger: requestLogger,
logGroupName: logGroupName,
logStreamName: logStreamName
logger: requestLogger
)
)
requestLogger.trace("Handler finished processing invocation")
+6 -30
View File
@@ -99,8 +99,6 @@ public struct LambdaContext: CustomDebugStringConvertible, Sendable {
let cognitoIdentity: String?
let clientContext: ClientContext?
let logger: Logger
let logGroupName: String?
let logStreamName: String?
init(
requestID: String,
@@ -110,9 +108,7 @@ public struct LambdaContext: CustomDebugStringConvertible, Sendable {
deadline: LambdaClock.Instant,
cognitoIdentity: String?,
clientContext: ClientContext?,
logger: Logger,
logGroupName: String?,
logStreamName: String?
logger: Logger
) {
self.requestID = requestID
self.traceID = traceID
@@ -122,8 +118,6 @@ public struct LambdaContext: CustomDebugStringConvertible, Sendable {
self.cognitoIdentity = cognitoIdentity
self.clientContext = clientContext
self.logger = logger
self.logGroupName = logGroupName
self.logStreamName = logStreamName
}
}
@@ -175,7 +169,7 @@ public struct LambdaContext: CustomDebugStringConvertible, Sendable {
*,
deprecated,
message:
"This method will be removed in a future major version update. Use init(requestID:traceID:tenantID:invokedFunctionARN:deadline:cognitoIdentity:clientContext:logger:logGroupName:logStreamName) instead."
"This method will be removed in a future major version update. Use init(requestID:traceID:tenantID:invokedFunctionARN:deadline:cognitoIdentity:clientContext:logger) instead."
)
public init(
requestID: String,
@@ -205,9 +199,7 @@ public struct LambdaContext: CustomDebugStringConvertible, Sendable {
deadline: LambdaClock.Instant,
cognitoIdentity: String? = nil,
clientContext: ClientContext? = nil,
logger: Logger,
logGroupName: String? = nil,
logStreamName: String? = nil
logger: Logger
) {
self.storage = _Storage(
requestID: requestID,
@@ -217,22 +209,10 @@ public struct LambdaContext: CustomDebugStringConvertible, Sendable {
deadline: deadline,
cognitoIdentity: cognitoIdentity,
clientContext: clientContext,
logger: logger,
logGroupName: logGroupName,
logStreamName: logStreamName
logger: logger
)
}
/// The name of the Amazon CloudWatch Logs group for the function.
public var logGroupName: String? {
self.storage.logGroupName
}
/// The name of the Amazon CloudWatch Logs stream for the current invocation of the function.
public var logStreamName: String? {
self.storage.logStreamName
}
public func getRemainingTime() -> Duration {
let deadline = self.deadline
return LambdaClock().now.duration(to: deadline)
@@ -250,9 +230,7 @@ public struct LambdaContext: CustomDebugStringConvertible, Sendable {
tenantID: String?,
invokedFunctionARN: String,
timeout: Duration,
logger: Logger,
logGroupName: String? = nil,
logStreamName: String? = nil
logger: Logger
) -> LambdaContext {
LambdaContext(
requestID: requestID,
@@ -260,9 +238,7 @@ public struct LambdaContext: CustomDebugStringConvertible, Sendable {
tenantID: tenantID,
invokedFunctionARN: invokedFunctionARN,
deadline: LambdaClock().now.advanced(by: timeout),
logger: logger,
logGroupName: logGroupName,
logStreamName: logStreamName
logger: logger
)
}
}
@@ -136,66 +136,4 @@ struct LambdaContextTests {
#expect(remainingTime <= Duration.seconds(31), "Remaining time should be approximately 30 seconds")
#expect(remainingTime >= Duration.seconds(-29), "Remaining time should be approximately -30 seconds")
}
@Test("logGroupName returns the value passed at initialization")
@available(LambdaSwift 2.0, *)
func logGroupNameReturnsInitializedValue() {
let context = LambdaContext.__forTestsOnly(
requestID: "test-request",
traceID: "test-trace",
tenantID: nil,
invokedFunctionARN: "test-arn",
timeout: .seconds(30),
logger: Logger(label: "test"),
logGroupName: "/aws/lambda/my-function"
)
#expect(context.logGroupName == "/aws/lambda/my-function")
}
@Test("logStreamName returns the value passed at initialization")
@available(LambdaSwift 2.0, *)
func logStreamNameReturnsInitializedValue() {
let context = LambdaContext.__forTestsOnly(
requestID: "test-request",
traceID: "test-trace",
tenantID: nil,
invokedFunctionARN: "test-arn",
timeout: .seconds(30),
logger: Logger(label: "test"),
logStreamName: "2024/01/01/[$LATEST]abcdef1234567890"
)
#expect(context.logStreamName == "2024/01/01/[$LATEST]abcdef1234567890")
}
@Test("logGroupName defaults to nil")
@available(LambdaSwift 2.0, *)
func logGroupNameDefaultsToNil() {
let context = LambdaContext.__forTestsOnly(
requestID: "test-request",
traceID: "test-trace",
tenantID: nil,
invokedFunctionARN: "test-arn",
timeout: .seconds(30),
logger: Logger(label: "test")
)
#expect(context.logGroupName == nil)
}
@Test("logStreamName defaults to nil")
@available(LambdaSwift 2.0, *)
func logStreamNameDefaultsToNil() {
let context = LambdaContext.__forTestsOnly(
requestID: "test-request",
traceID: "test-trace",
tenantID: nil,
invokedFunctionARN: "test-arn",
timeout: .seconds(30),
logger: Logger(label: "test")
)
#expect(context.logStreamName == nil)
}
}