10BC0 [vertex-ai] App Version for AI Monitoring by paulb777 · Pull Request #14568 · firebase/firebase-ios-sdk · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions FirebaseVertexAI/Sources/GenerativeAIService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,12 @@ struct GenerativeAIService {
urlRequest.setValue("Firebase \(authToken)", forHTTPHeaderField: "Authorization")
}

// TODO: wait for release approval.
// if firebaseInfo.app.isDataCollectionDefaultEnabled {
// urlRequest.setValue(firebaseInfo.googleAppID, forHTTPHeaderField: "X-Firebase-AppId")
// }
if firebaseInfo.app.isDataCollectionDefaultEnabled {
urlRequest.setValue(firebaseInfo.googleAppID, forHTTPHeaderField: "X-Firebase-AppId")
if let appVersion = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String {
urlRequest.setValue(appVersion, forHTTPHeaderField: "X-Firebase-AppVersion")
}
}

let encoder = JSONEncoder()
urlRequest.httpBody = try encoder.encode(request)
Expand Down
11 changes: 8 additions & 3 deletions FirebaseVertexAI/Tests/Unit/GenerativeModelTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1492,7 +1492,7 @@
#if os(watchOS)
throw XCTSkip("Custom URL protocols are unsupported in watchOS 2 and later.")
#endif // os(watchOS)
return { request in

Check warning on line 1495 in FirebaseVertexAI/Tests/Unit/GenerativeModelTests.swift

View workflow job for this annotation

GitHub Actions / spm-unit (macos-15, Xcode_16.2, watchOS)

code after 'throw' will never be executed
// This is *not* an HTTPURLResponse
let response = URLResponse(
url: request.url!,
Expand All @@ -1519,7 +1519,7 @@
#if os(watchOS)
throw XCTSkip("Custom URL protocols are unsupported in watchOS 2 and later.")
#endif // os(watchOS)
let bundle = BundleTestUtil.bundle()

Check warning on line 1522 in FirebaseVertexAI/Tests/Unit/GenerativeModelTests.swift

View workflow job for this annotation

GitHub Actions / spm-unit (macos-15, Xcode_16.2, watchOS)

code after 'throw' will never be executed
let fileURL = try XCTUnwrap(bundle.url(forResource: name, withExtension: ext))
return { request in
let requestURL = try XCTUnwrap(request.url)
Expand All @@ -1530,9 +1530,14 @@
XCTAssert(apiClientTags.contains(GenerativeAIService.languageTag))
XCTAssert(apiClientTags.contains(GenerativeAIService.firebaseVersionTag))
XCTAssertEqual(request.value(forHTTPHeaderField: "X-Firebase-AppCheck"), appCheckToken)
// TODO: Wait for release approval
// let googleAppID = request.value(forHTTPHeaderField: "X-Firebase-AppId")
// XCTAssertEqual(googleAppID, dataCollection ? "My app ID" : nil)

let googleAppID = request.value(forHTTPHeaderField: "X-Firebase-AppId")
let appVersion = request.value(forHTTPHeaderField: "X-Firebase-AppVersion")
let expectedAppVersion =
try? XCTUnwrap(Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String)
XCTAssertEqual(googleAppID, dataCollection ? "My app ID" : nil)
XCTAssertEqual(appVersion, dataCollection ? expectedAppVersion : nil)

if let authToken {
XCTAssertEqual(request.value(forHTTPHeaderField: "Authorization"), "Firebase \(authToken)")
} else {
Expand Down
Loading
0