-
Notifications
You must be signed in to change notification settings - Fork 25
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
e2e test for background error telemetry #8717
Merged
Merged
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
10cbeb1
e2e test for background error telemetry
fungairino 3212d25
pr feedback
fungairino 8f36be1
Merge remote-tracking branch 'origin/main' into e2e-background
fungairino 89beeef
rename
fungairino 15b06ea
Merge branch 'main' into e2e-background
fungairino 311482c
fix error not being emitted in bg
fungairino 9454929
Merge branch 'main' into e2e-background
fungairino File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,54 +26,59 @@ async function waitForBackgroundPageRequest( | |
return offscreenPage?.waitForRequest(errorServiceEndpoint); | ||
} | ||
|
||
const ERROR_SERVICE_ENDPOINT = "https://browser-intake-datadoghq.com/api/v2/*"; | ||
|
||
async function getSentErrors(extensionId: string, context: BrowserContext) { | ||
// TODO: due to Datadog SDK implementation, it will take ~30 seconds for the | ||
// request to be sent. We should figure out a way to induce the request to be sent sooner. | ||
// See this datadog support request: https://help.datadoghq.com/hc/en-us/requests/1754158 | ||
const request = await waitForBackgroundPageRequest( | ||
context, | ||
extensionId, | ||
ERROR_SERVICE_ENDPOINT, | ||
); | ||
|
||
return request | ||
?.postData() | ||
?.split("\n") | ||
.map((log) => JSON.parse(log)); | ||
} | ||
|
||
test.use({ | ||
additionalRequiredEnvVariables: [ | ||
"DATADOG_CLIENT_TOKEN", | ||
"DEV_EVENT_TELEMETRY", | ||
], | ||
}); | ||
|
||
test("can report application error to telemetry service", async ({ | ||
test("can report errors to telemetry service", async ({ | ||
page, | ||
context, | ||
extensionId, | ||
}) => { | ||
const errorServiceEndpoint = "https://browser-intake-datadoghq.com/api/v2/*"; | ||
|
||
await context.route( | ||
"https://app.pixiebrix.com/api/extensions/", | ||
async (route) => { | ||
const endpointCalledFromExtensionConsole = | ||
"https://app.pixiebrix.com/api/extensions/"; | ||
await test.step("Mock the extensions endpoint to return a bad response, and mock errorService calls", async () => { | ||
await context.route(endpointCalledFromExtensionConsole, async (route) => { | ||
await route.fulfill({ | ||
status: 200, | ||
// Returning a bad response to trigger an error | ||
body: JSON.stringify([{}]), | ||
}); | ||
}, | ||
); | ||
}); | ||
|
||
await context.route(errorServiceEndpoint, async (route) => | ||
route.fulfill({ | ||
status: 202, | ||
}), | ||
); | ||
await context.route(ERROR_SERVICE_ENDPOINT, async (route) => | ||
route.fulfill({ | ||
status: 202, | ||
}), | ||
); | ||
}); | ||
|
||
await page.goto(getBaseExtensionConsoleUrl(extensionId)); | ||
await expect(page.getByText("Something went wrong.")).toBeVisible(); | ||
|
||
// TODO: due to Datadog SDK implementation, it will take ~30 seconds for the | ||
// request to be sent. We should figure out a way to induce the request to be sent sooner. | ||
const request = await waitForBackgroundPageRequest( | ||
context, | ||
extensionId, | ||
errorServiceEndpoint, | ||
); | ||
|
||
const errorLogsJson = request | ||
?.postData() | ||
?.split("\n") | ||
.map((log) => JSON.parse(log)); | ||
const sentErrors = await getSentErrors(extensionId, context); | ||
|
||
expect(errorLogsJson).toContainEqual( | ||
expect(sentErrors).toContainEqual( | ||
expect.objectContaining({ | ||
service: "pixiebrix-browser-extension", | ||
manifestVersion: 3, | ||
|
@@ -82,6 +87,93 @@ test("can report application error to telemetry service", async ({ | |
message: expect.any(String), | ||
kind: expect.any(String), | ||
}), | ||
stack: expect.any(String), | ||
message: expect.any(String), | ||
connectionType: expect.any(String), | ||
date: expect.any(Number), | ||
extensionVersion: expect.any(String), | ||
name: expect.any(String), | ||
origin: "logger", | ||
pageName: "options", | ||
referrer: "", | ||
runtimeId: extensionId, | ||
session_id: expect.any(String), | ||
status: "error", | ||
url: `chrome-extension://${extensionId}/options.html#/`, | ||
usr: { | ||
email: "[email protected]", | ||
id: "3f7ac0b4-5029-442c-b537-5de9f1dfdfd9", | ||
organizationId: "47f616c5-81e3-4edb-ba44-ed5dd4a78c08", | ||
}, | ||
view: { | ||
referrer: "", | ||
url: `chrome-extension://${extensionId}/offscreen.html`, | ||
}, | ||
}), | ||
); | ||
}); | ||
|
||
test("can report a service worker error to telemetry service", async ({ | ||
page, | ||
context, | ||
extensionId, | ||
}) => { | ||
const endpointCalledFromServiceWorker = | ||
"https://app.pixiebrix.com/api/registry/bricks/"; | ||
|
||
await test.step("Mock the registry endpoint to return a bad response, and mock errorService calls", async () => { | ||
await context.route(endpointCalledFromServiceWorker, async (route) => { | ||
await route.fulfill({ | ||
status: 500, | ||
body: "I'm not json!", | ||
}); | ||
}); | ||
|
||
await context.route(ERROR_SERVICE_ENDPOINT, async (route) => | ||
route.fulfill({ | ||
status: 202, | ||
}), | ||
); | ||
}); | ||
|
||
await page.goto(getBaseExtensionConsoleUrl(extensionId)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It might be too early to extract at 2x usages, but maybe if we end up adding a third test with this shape, we should extract this logic into something reusable. |
||
await expect(page.getByText("An error occurred")).toBeVisible(); | ||
|
||
const sentErrors = await getSentErrors(extensionId, context); | ||
|
||
expect(sentErrors).toContainEqual( | ||
expect.objectContaining({ | ||
code: "ERR_BAD_RESPONSE", | ||
code_version: expect.any(String), | ||
connectionType: "4g", | ||
date: expect.any(Number), | ||
error: expect.objectContaining({ | ||
kind: "AxiosError", | ||
message: expect.any(String), | ||
stack: expect.any(String), | ||
}), | ||
extensionVersion: expect.any(String), | ||
manifestVersion: 3, | ||
message: expect.any(String), | ||
name: "AxiosError", | ||
origin: "logger", | ||
pageName: "background", | ||
referrer: "", | ||
runtimeId: extensionId, | ||
service: "pixiebrix-browser-extension", | ||
session_id: expect.any(String), | ||
stack: expect.any(String), | ||
status: "error", | ||
url: "https://app.pixiebrix.com/api/registry/bricks/", | ||
usr: { | ||
email: "[email protected]", | ||
id: "3f7ac0b4-5029-442c-b537-5de9f1dfdfd9", | ||
organizationId: "47f616c5-81e3-4edb-ba44-ed5dd4a78c08", | ||
}, | ||
view: { | ||
referrer: "", | ||
url: `chrome-extension://${extensionId}/offscreen.html`, | ||
}, | ||
}), | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❤️ thanks again to reaching out to support