This is an automated email from the ASF dual-hosted git repository.
michael-s-molina pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/superset.git
The following commit(s) were added to refs/heads/master by this push:
new 029d49539bc fix(event-log): match embedded routes precisely in logger
middleware (#41942)
029d49539bc is described below
commit 029d49539bc6ebbe7f7e5372fffec79ad89b6c15
Author: Luiz Otavio <[email protected]>
AuthorDate: Mon Jul 13 08:46:23 2026 -0300
fix(event-log): match embedded routes precisely in logger middleware
(#41942)
---
superset-frontend/src/middleware/logger.test.ts | 25 ++++++++++++++++++++++
.../src/middleware/loggerMiddleware.ts | 11 +++++++++-
2 files changed, 35 insertions(+), 1 deletion(-)
diff --git a/superset-frontend/src/middleware/logger.test.ts
b/superset-frontend/src/middleware/logger.test.ts
index 5b52f3d682c..12c61633d91 100644
--- a/superset-frontend/src/middleware/logger.test.ts
+++ b/superset-frontend/src/middleware/logger.test.ts
@@ -137,6 +137,31 @@ describe('logger middleware', () => {
}
});
+ const getSourceForPath = (href: string): string | undefined => {
+ const locationSpy = jest.spyOn(window, 'location', 'get').mockReturnValue({
+ ...window.location,
+ href,
+ } as Location);
+ try {
+ (logger as Function)(mockStore)(next)(action);
+ jest.advanceTimersByTime(2000);
+ const { events } = postStub.mock.calls[0][0].postPayload;
+ return events[0].source;
+ } finally {
+ locationSpy.mockRestore();
+ }
+ };
+
+ test.each([
+ ['/dashboard/123/embedded/', 'embedded_dashboard'],
+ ['/embedded/abc-def-uuid/', 'embedded_dashboard'],
+ ['/dashboard/123/', 'dashboard'],
+ // slug is literally "embedded" - must not be treated as embedded
+ ['/dashboard/embedded/', 'dashboard'],
+ ])('classifies %s as source "%s"', (path, expectedSource) => {
+ expect(getSourceForPath(`http://localhost${path}`)).toBe(expectedSource);
+ });
+
test('should debounce a few log requests to one', () => {
(logger as Function)(mockStore)(next)(action);
(logger as Function)(mockStore)(next)(action);
diff --git a/superset-frontend/src/middleware/loggerMiddleware.ts
b/superset-frontend/src/middleware/loggerMiddleware.ts
index 6097572cc20..a89e8e694c0 100644
--- a/superset-frontend/src/middleware/loggerMiddleware.ts
+++ b/superset-frontend/src/middleware/loggerMiddleware.ts
@@ -132,6 +132,12 @@ const logMessageQueue = new
DebouncedMessageQueue<LogEventData>({
delayThreshold: 1000,
});
+// Embedded dashboards are served from `/dashboard/:idOrSlug/embedded/` and
+// `/embedded/:uuid/`. Matching these specific shapes avoids false positives
+// for regular dashboards (e.g. a dashboard whose slug is "embedded").
+const EMBEDDED_ROUTE_REGEX =
+ /\/dashboard\/[^/]+\/embedded\/|\/embedded\/[^/]+\//;
+
let lastEventId: string | number = 0;
const loggerMiddleware: Middleware<
@@ -163,7 +169,10 @@ const loggerMiddleware: Middleware<
}
const path = navPath || window?.location?.href;
- const isEmbedded = path?.includes('/embedded/');
+ // Match the actual embedded route patterns
(`/dashboard/:idOrSlug/embedded/`
+ // and `/embedded/:uuid/`) rather than any URL containing "/embedded/",
which
+ // would misclassify a regular dashboard whose slug is "embedded".
+ const isEmbedded = EMBEDDED_ROUTE_REGEX.test(path ?? '');
if (dashboardInfo?.id && (path?.includes('/dashboard/') || isEmbedded)) {
logMetadata = {
source: isEmbedded ? 'embedded_dashboard' : 'dashboard',