Skip to content
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

RUMM-1924 Fix bug with WebView logs not appearing in Logs Explorer #723

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
2 changes: 1 addition & 1 deletion Datadog/Example/Debugging/DebugWebviewViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class WebviewViewController: UIViewController {
super.viewDidLoad()

let controller = WKUserContentController()
controller.addDatadogMessageHandler(allowedWebViewHosts: ["datadoghq.dev"])
controller.addDatadogMessageHandler(allowedWebViewHosts: [request.url!.host!])
let config = WKWebViewConfiguration()
config.userContentController = controller

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ internal class DefaultWebLogEventConsumer: WebLogEventConsumer {
mutableEvent[Constants.ddTagsKey] = ddTags
}

if let date = mutableEvent[Constants.dateKey] as? Int {
let serverTimeOffsetInNs = dateCorrector.currentCorrection.serverTimeOffset.toInt64Nanoseconds
let correctedDate = Int64(date) + serverTimeOffsetInNs
mutableEvent[Constants.dateKey] = correctedDate
if let timestampInMs = mutableEvent[Constants.dateKey] as? Int {
let serverTimeOffsetInMs = dateCorrector.currentCorrection.serverTimeOffset.toInt64Milliseconds
let correctedTimestamp = Int64(timestampInMs) + serverTimeOffsetInMs
mutableEvent[Constants.dateKey] = correctedTimestamp
}

if let context = rumContextProvider?.context {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class WebLogEventConsumerTests: XCTestCase {
let mockContextProvider = RUMContextProviderMock(context: .mockWith(rumApplicationID: "123456"))

func testWhenValidWebLogEventPassed_itDecoratesAndPassesToWriter() throws {
let mockSessionID = UUID(uuidString: "e9796469-c2a1-43d6-b0f6-65c47d33cf5f")!
let mockSessionID: UUID = .mockRandom()
mockContextProvider.context.sessionID = RUMUUID(rawValue: mockSessionID)
mockDateCorrector.correctionOffset = 123
let applicationVersion = String.mockRandom()
Expand All @@ -37,7 +37,7 @@ class WebLogEventConsumerTests: XCTestCase {
"view": ["referrer": "", "url": "https://datadoghq.dev/browser-sdk-test-playground"]
]
let expectedWebLogEvent: JSON = [
"date": 1_635_932_927_012 + 123.toInt64Nanoseconds,
"date": 1_635_932_927_012 + 123.toInt64Milliseconds,
"error": ["origin": "console"],
"message": "console error: error",
"application_id": "123456",
Expand All @@ -58,7 +58,7 @@ class WebLogEventConsumerTests: XCTestCase {
}

func testWhenValidWebInternalLogEventPassed_itDecoratesAndPassesToWriter() throws {
let mockSessionID = UUID(uuidString: "e9796469-c2a1-43d6-b0f6-65c47d33cf5f")!
let mockSessionID: UUID = .mockRandom()
mockContextProvider.context.sessionID = RUMUUID(rawValue: mockSessionID)
mockDateCorrector.correctionOffset = 123
let applicationVersion = String.mockRandom()
Expand All @@ -81,7 +81,7 @@ class WebLogEventConsumerTests: XCTestCase {
"view": ["referrer": "", "url": "https://datadoghq.dev/browser-sdk-test-playground"]
]
let expectedWebLogEvent: JSON = [
"date": 1_635_932_927_012 + 123.toInt64Nanoseconds,
"date": 1_635_932_927_012 + 123.toInt64Milliseconds,
"error": ["origin": "console"],
"message": "console error: error",
"application_id": "123456",
Expand Down