Skip to content

Commit

Permalink
recording: network logs not counting the request transferSize but onl…
Browse files Browse the repository at this point in the history
…y the response transferSize (#193)
  • Loading branch information
marandaneto authored Sep 12, 2024
1 parent 91326f7 commit ef274d6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## Next

- 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

- chore: add Is Emulator support ([#190](https://github.com/PostHog/posthog-ios/pull/190))
Expand Down
7 changes: 6 additions & 1 deletion PostHog/Replay/URLSessionExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,14 @@
"name": request?.url?.absoluteString ?? (response?.url?.absoluteString ?? ""),
"initiatorType": "fetch",
"entryType": "resource",
"transferSize": 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
}
Expand Down
7 changes: 5 additions & 2 deletions PostHog/Replay/URLSessionInterceptor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit ef274d6

Please sign in to comment.