From 3ef77aad749232a41439ca3b28badbb46e70b68a Mon Sep 17 00:00:00 2001 From: Manoel Aranda Neto Date: Thu, 12 Sep 2024 14:54:25 +0200 Subject: [PATCH 1/6] recording: add missing starttime for network logs --- PostHog/Replay/NetworkSample.swift | 4 +++- PostHog/Replay/URLSessionExtension.swift | 6 ++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/PostHog/Replay/NetworkSample.swift b/PostHog/Replay/NetworkSample.swift index 842d0ad06..5b1cdc9df 100644 --- a/PostHog/Replay/NetworkSample.swift +++ b/PostHog/Replay/NetworkSample.swift @@ -24,8 +24,10 @@ } func toDict() -> [String: Any] { + let originMillis = timeOrigin.toMillis() var dict: [String: Any] = [ - "timestamp": timeOrigin.toMillis(), + "timestamp": originMillis, + "startTime": originMillis, "entryType": entryType, "initiatorType": initiatorType, ] diff --git a/PostHog/Replay/URLSessionExtension.swift b/PostHog/Replay/URLSessionExtension.swift index bae7339c5..20331bc69 100644 --- a/PostHog/Replay/URLSessionExtension.swift +++ b/PostHog/Replay/URLSessionExtension.swift @@ -115,13 +115,15 @@ PostHogReplayIntegration.dispatchQueue.async { var snapshotsData: [Any] = [] + let timestampMillis = timestamp.toMillis() var requestsData: [String: Any] = ["duration": currentEnd - start, "method": request?.httpMethod ?? "GET", "name": request?.url?.absoluteString ?? (response?.url?.absoluteString ?? ""), "initiatorType": "fetch", "entryType": "resource", - "transferSize": response?.expectedContentLength ?? 0, - "timestamp": timestamp.toMillis()] + "transferSize": Int64(request?.httpBody?.count ?? 0) + (response?.expectedContentLength ?? 0), + "timestamp": timestampMillis, + "startTime": timestampMillis] if let urlResponse = response as? HTTPURLResponse { requestsData["responseStatus"] = urlResponse.statusCode From e6367be213ceba23e0d4f694c60ad136768b768d Mon Sep 17 00:00:00 2001 From: Manoel Aranda Neto Date: Thu, 12 Sep 2024 14:55:17 +0200 Subject: [PATCH 2/6] fix --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ad8566089..3df6bc140 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ ## Next +- recording: missing startTime for network logs ([#193](https://github.com/PostHog/posthog-ios/pull/193)) + ## 3.12.0 - 2024-09-12 - chore: add Is Emulator support ([#190](https://github.com/PostHog/posthog-ios/pull/190)) From 8632481863f0114fed2c094dfe89bdde288aec6e Mon Sep 17 00:00:00 2001 From: Manoel Aranda Neto Date: Thu, 12 Sep 2024 16:10:43 +0200 Subject: [PATCH 3/6] fix --- CHANGELOG.md | 2 +- PostHog/Replay/URLSessionExtension.swift | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3df6bc140..356dcec6f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ ## Next -- recording: missing startTime for network logs ([#193](https://github.com/PostHog/posthog-ios/pull/193)) +- recording: network logs not counting the request transferSize buy only the response transferSize ([#193](https://github.com/PostHog/posthog-ios/pull/193)) ## 3.12.0 - 2024-09-12 diff --git a/PostHog/Replay/URLSessionExtension.swift b/PostHog/Replay/URLSessionExtension.swift index 20331bc69..93f5cbf3e 100644 --- a/PostHog/Replay/URLSessionExtension.swift +++ b/PostHog/Replay/URLSessionExtension.swift @@ -115,15 +115,13 @@ PostHogReplayIntegration.dispatchQueue.async { var snapshotsData: [Any] = [] - let timestampMillis = timestamp.toMillis() var requestsData: [String: Any] = ["duration": currentEnd - start, "method": request?.httpMethod ?? "GET", "name": request?.url?.absoluteString ?? (response?.url?.absoluteString ?? ""), "initiatorType": "fetch", "entryType": "resource", "transferSize": Int64(request?.httpBody?.count ?? 0) + (response?.expectedContentLength ?? 0), - "timestamp": timestampMillis, - "startTime": timestampMillis] + "timestamp": timestamp.toMillis()] if let urlResponse = response as? HTTPURLResponse { requestsData["responseStatus"] = urlResponse.statusCode From 822a95720609207586f131a0e82653d8f4195966 Mon Sep 17 00:00:00 2001 From: Manoel Aranda Neto Date: Thu, 12 Sep 2024 16:15:08 +0200 Subject: [PATCH 4/6] fix --- PostHog/Replay/NetworkSample.swift | 4 +--- PostHog/Replay/URLSessionExtension.swift | 7 ++++++- PostHog/Replay/URLSessionInterceptor.swift | 7 +++++-- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/PostHog/Replay/NetworkSample.swift b/PostHog/Replay/NetworkSample.swift index 5b1cdc9df..842d0ad06 100644 --- a/PostHog/Replay/NetworkSample.swift +++ b/PostHog/Replay/NetworkSample.swift @@ -24,10 +24,8 @@ } func toDict() -> [String: Any] { - let originMillis = timeOrigin.toMillis() var dict: [String: Any] = [ - "timestamp": originMillis, - "startTime": originMillis, + "timestamp": timeOrigin.toMillis(), "entryType": entryType, "initiatorType": initiatorType, ] diff --git a/PostHog/Replay/URLSessionExtension.swift b/PostHog/Replay/URLSessionExtension.swift index 93f5cbf3e..61a3c4ecc 100644 --- a/PostHog/Replay/URLSessionExtension.swift +++ b/PostHog/Replay/URLSessionExtension.swift @@ -120,9 +120,14 @@ "name": request?.url?.absoluteString ?? (response?.url?.absoluteString ?? ""), "initiatorType": "fetch", "entryType": "resource", - "transferSize": Int64(request?.httpBody?.count ?? 0) + (response?.expectedContentLength ?? 0), "timestamp": timestamp.toMillis()] + // the UI special case if the transferSize is 0 as coming from cache + let transferSize = Int64(request?.httpBody?.count ?? 0) + (response?.expectedContentLength ?? 0) + if transferSize >= 0 { + requestsData["transferSize"] = transferSize + } + if let urlResponse = response as? HTTPURLResponse { requestsData["responseStatus"] = urlResponse.statusCode } diff --git a/PostHog/Replay/URLSessionInterceptor.swift b/PostHog/Replay/URLSessionInterceptor.swift index 6108f29d2..c372b1def 100644 --- a/PostHog/Replay/URLSessionInterceptor.swift +++ b/PostHog/Replay/URLSessionInterceptor.swift @@ -80,8 +80,11 @@ sample.httpMethod = request.httpMethod sample.initiatorType = "fetch" sample.duration = (date.toMillis() - sample.timeOrigin.toMillis()) - if let response = task.response { - sample.decodedBodySize = response.expectedContentLength + + // the UI special case if the transferSize is 0 as coming from cache + let transferSize = Int64(request.httpBody?.count ?? 0) + (task.response?.expectedContentLength ?? 0) + if transferSize >= 0 { + sample.decodedBodySize = transferSize } self.finish(task: task, sample: sample) From 1f85257a63827a087a806e63c2ec3a3f14a0ec41 Mon Sep 17 00:00:00 2001 From: Manoel Aranda Neto Date: Thu, 12 Sep 2024 16:16:37 +0200 Subject: [PATCH 5/6] fix --- PostHog/Replay/URLSessionExtension.swift | 2 +- PostHog/Replay/URLSessionInterceptor.swift | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/PostHog/Replay/URLSessionExtension.swift b/PostHog/Replay/URLSessionExtension.swift index 61a3c4ecc..00c1fc2fc 100644 --- a/PostHog/Replay/URLSessionExtension.swift +++ b/PostHog/Replay/URLSessionExtension.swift @@ -124,7 +124,7 @@ // the UI special case if the transferSize is 0 as coming from cache let transferSize = Int64(request?.httpBody?.count ?? 0) + (response?.expectedContentLength ?? 0) - if transferSize >= 0 { + if transferSize > 0 { requestsData["transferSize"] = transferSize } diff --git a/PostHog/Replay/URLSessionInterceptor.swift b/PostHog/Replay/URLSessionInterceptor.swift index c372b1def..5d6a7c223 100644 --- a/PostHog/Replay/URLSessionInterceptor.swift +++ b/PostHog/Replay/URLSessionInterceptor.swift @@ -83,7 +83,7 @@ // the UI special case if the transferSize is 0 as coming from cache let transferSize = Int64(request.httpBody?.count ?? 0) + (task.response?.expectedContentLength ?? 0) - if transferSize >= 0 { + if transferSize > 0 { sample.decodedBodySize = transferSize } From b507016159657cc460267f669713c97d78037e67 Mon Sep 17 00:00:00 2001 From: Manoel Aranda Neto <5731772+marandaneto@users.noreply.github.com> Date: Thu, 12 Sep 2024 16:17:52 +0200 Subject: [PATCH 6/6] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 356dcec6f..7c47eb201 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ ## Next -- recording: network logs not counting the request transferSize buy only the response transferSize ([#193](https://github.com/PostHog/posthog-ios/pull/193)) +- recording: network logs not counting the request transferSize but only the response transferSize ([#193](https://github.com/PostHog/posthog-ios/pull/193)) ## 3.12.0 - 2024-09-12