Skip to content

fix: [core] Hard code version number in user agent string (#98) #533

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 21, 2025

Conversation

sebsto
Copy link
Contributor

@sebsto sebsto commented Jul 21, 2025

Add a hard coded version number to the user agent string, for an eventual identification by the Lambda service

Motivation:

It's an issue that was open more than 5 years ago and was never addressed. At the time, the consensus was to pickup a version number for the Package.swift file and the maintainer at the time decided to wait for Swift to implement this.
Five years later, and several major version of Swift later, this is still not available. I decided to move on and implement a less optimal solution. This can be replaced in the future if package version ever becomes part of Package.swift.

Modifications:

Add a version enum to isolate the versioning in one place. I decided to keep it simple and not over engineering it with major, minor, patch and pre-release. At the time, it's a simple string. This is all what we need for usage in the user agent string.

Result:

User agent now identifies as Swift-Lambda/2,0 instead of Swift-Lambda/unknown

@sebsto sebsto self-assigned this Jul 21, 2025
@sebsto sebsto added the 🆕 semver/minor Adds new public API. label Jul 21, 2025
@sebsto sebsto requested review from Copilot and adam-fowler July 21, 2025 06:29
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR addresses a long-standing issue by implementing a hard-coded version number for the user agent string in AWS Lambda Runtime requests. Instead of showing "Swift-Lambda/Unknown", the runtime will now identify itself as "Swift-Lambda/2.0" to the Lambda service.

Key changes:

  • Created a new Version enum to centralize version management
  • Updated the user agent string to use the version number instead of "Unknown"

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
Sources/AWSLambdaRuntime/Version.swift New file containing a Version enum with static version string "2.0"
Sources/AWSLambdaRuntime/ControlPlaneRequestEncoder.swift Updated user agent string to interpolate the version from Version.current

@@ -93,7 +93,7 @@ struct ControlPlaneRequestEncoder: _EmittingChannelHandler {
extension String {
static let CRLF: String = "\r\n"

static let userAgent = "Swift-Lambda/Unknown"
static let userAgent = "Swift-Lambda/\(Version.current)"
Copy link
Preview

Copilot AI Jul 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

String interpolation is performed every time this static property is accessed. Consider using a computed property or pre-computing the string to avoid repeated interpolation overhead.

Suggested change
static let userAgent = "Swift-Lambda/\(Version.current)"
static let userAgent: String = {
return "Swift-Lambda/\(Version.current)"
}()

Copilot uses AI. Check for mistakes.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't think this is true.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think neither. Typical hallucination :-)


/// The version of the AWS Lambda Runtime.
///
/// This is used in the User Agent header when making requests to the AWS Lambda data Plane.
Copy link
Preview

Copilot AI Jul 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"data Plane" should be "Data Plane" - both words should be capitalized when referring to the AWS Lambda Data Plane as a proper noun.

Suggested change
/// This is used in the User Agent header when making requests to the AWS Lambda data Plane.
/// This is used in the User Agent header when making requests to the AWS Lambda Data Plane.

Copilot uses AI. Check for mistakes.

@@ -93,7 +93,7 @@ struct ControlPlaneRequestEncoder: _EmittingChannelHandler {
extension String {
static let CRLF: String = "\r\n"

static let userAgent = "Swift-Lambda/Unknown"
static let userAgent = "Swift-Lambda/\(Version.current)"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't think this is true.

@sebsto sebsto merged commit e786f2f into swift-server:main Jul 21, 2025
32 checks passed
@sebsto sebsto deleted the sebsto/useragent branch July 21, 2025 18:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🆕 semver/minor Adds new public API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants