Add Sentry frame rewriting for Element Desktop integration (#34667)

* Add Sentry frame rewriting for Element Desktop integration

This change introduces the Sentry `rewriteFramesIntegration` to normalize stack frames for crashes occurring in Element Desktop. It ensures that stack traces from the custom `vector://vector/webapp` origin are grouped and symbolicated correctly, aligning them with the web app's release. This enhancement improves error tracking and debugging for users on the desktop platform.

* Refactor Sentry test file for improved readability and consistency

This update enhances the formatting of the `sentry-test.ts` file by aligning code for better readability. Changes include consistent indentation and spacing in mock function definitions and test cases. These adjustments aim to improve code maintainability and clarity without altering functionality.

* Add copyright notice and SPDX license to Sentry test file

This update introduces a copyright notice and SPDX license declaration at the top of the `sentry-test.ts` file. The addition clarifies the ownership and licensing terms for the file, ensuring compliance with legal requirements and improving documentation for future reference.

* Update copyright notice in Sentry test file

This commit updates the copyright notice in the `sentry-test.ts` file to reflect the new ownership under PrinceXDev. The change ensures that the file's legal attribution is accurate and up-to-date.

* Refactor Sentry test file for improved code consistency

This commit streamlines the formatting in the `sentry-test.ts` file by consolidating mock function definitions and enhancing the readability of the test cases. The changes include removing unnecessary line breaks and ensuring consistent spacing, which contributes to better maintainability without altering the functionality of the tests.
This commit is contained in:
Prince Panchani
2026-08-12 18:46:19 +05:30
committed by GitHub
parent 41c7ffaf54
commit 59561e615a
2 changed files with 89 additions and 0 deletions
+8
View File
@@ -197,6 +197,14 @@ export async function initSentry(sentryConfig: IConfigOptions["sentry"]): Promis
Sentry.breadcrumbsIntegration(),
Sentry.httpContextIntegration(),
Sentry.dedupeIntegration(),
// Element Desktop serves the app from the custom `vector://vector/webapp` origin rather
// than a normal web origin, so its stack frames don't match Element Web's and end up
// ungrouped and unsymbolicated. Normalize both to the same relative form so desktop
// crashes group with, and source-map against, the same release as the web app.
Sentry.rewriteFramesIntegration({
root: "vector://vector/webapp",
prefix: "app://",
}),
];
Sentry.init({
+81
View File
@@ -0,0 +1,81 @@
/*
Copyright 2026 PrinceXDev <princepanchani890@gmail.com>
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
Please see LICENSE files in the repository root for full details.
*/
import * as Sentry from "@sentry/browser";
import { initSentry } from "../../src/sentry";
jest.mock("@sentry/browser", () => ({
init: jest.fn(),
inboundFiltersIntegration: jest.fn().mockReturnValue({ name: "InboundFilters" }),
functionToStringIntegration: jest.fn().mockReturnValue({ name: "FunctionToString" }),
breadcrumbsIntegration: jest.fn().mockReturnValue({ name: "Breadcrumbs" }),
httpContextIntegration: jest.fn().mockReturnValue({ name: "HttpContext" }),
dedupeIntegration: jest.fn().mockReturnValue({ name: "Dedupe" }),
rewriteFramesIntegration: jest.fn().mockReturnValue({ name: "RewriteFrames" }),
}));
describe("initSentry", () => {
afterEach(() => {
jest.clearAllMocks();
});
it("does nothing if no sentry config is given", async () => {
await initSentry(undefined);
expect(Sentry.init).not.toHaveBeenCalled();
});
it("normalizes Element Desktop's vector:// stack frames so they group with Element Web", async () => {
await initSentry({
dsn: "https://examplePublicKey@o0.ingest.sentry.io/0",
environment: "test",
});
expect(Sentry.rewriteFramesIntegration).toHaveBeenCalledWith({
root: "vector://vector/webapp",
prefix: "app://",
});
const { integrations } = jest.mocked(Sentry.init).mock.calls[0][0]!;
expect(integrations).toEqual(expect.arrayContaining([{ name: "RewriteFrames" }]));
});
});
describe("rewriteFramesIntegration output", () => {
// Uses the real Sentry SDK integration (not the mock above) to verify the actual rewritten
// path, since it's easy to get the exact prefix/slash count wrong (e.g. `app:///` here would
// double up with the leading slash already present in the frame, producing `app:////...`).
// Relies on this test file's jsdom environment providing a real `window`, which is what makes
// the SDK's browser root/prefix substitution apply in the first place.
it("rewrites a vector:// frame to a clean app:/// path", async () => {
const RealSentry = jest.requireActual<typeof Sentry>("@sentry/browser");
const integration = RealSentry.rewriteFramesIntegration({
root: "vector://vector/webapp",
prefix: "app://",
});
const event: any = {
exception: {
values: [
{
stacktrace: {
frames: [
{
filename: "vector://vector/webapp/bundles/abc123/bundle.js",
},
],
},
},
],
},
};
const processed = integration.processEvent!(event, {}, {} as any) as any;
expect(processed.exception.values[0].stacktrace.frames[0].filename).toBe("app:///bundles/abc123/bundle.js");
});
});