Skip to content

Commit b138f33

Browse files
authored
Merge pull request #1970 from rosahbruno/live-sessions
Add window.Glean.debugSession() web API
2 parents 5a2b170 + 0129a55 commit b138f33

File tree

4 files changed

+23
-1
lines changed

4 files changed

+23
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
[Full changelog](https://github.com/mozilla/glean.js/compare/v5.0.2...main)
44

5+
* [#1970](https://github.com/mozilla/glean.js/pull/1970): Add `window.Glean.debugSession` API for automatically opening a link to the Debug Ping Viewer with your current session selected.
6+
57
# v5.0.2 (2024-05-23)
68

79
[Full changelog](https://github.com/mozilla/glean.js/compare/v5.0.1...v5.0.2)

automation/compat/tests/utils.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ export async function runWebTest(driver) {
8282
window.Glean &&
8383
window.Glean.setDebugViewTag &&
8484
window.Glean.setLogPings &&
85-
window.Glean.setSourceTags
85+
window.Glean.setSourceTags &&
86+
window.Glean.debugSession
8687
) {
8788
return true;
8889
}

documentation/src/content/docs/debugging/browser.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ window.Glean.setDebugViewTag("example-tag");
2020

2121
// Tag pings with source tags.
2222
window.Glean.setSourceTags(["my-tag", "your-tag", "our-tag"]);
23+
24+
// Open a new tab in the browser showing the Debug Ping Viewer with the active session in focus.
25+
window.Glean.debugSession();
2326
```
2427

2528
## Try it out

glean/src/core/glean.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,7 @@ declare global {
527527
setLogPings: (flag: boolean) => void;
528528
setDebugViewTag: (value: string) => void;
529529
setSourceTags: (value: string[]) => void;
530+
debugSession: () => void;
530531
};
531532
}
532533
}
@@ -558,6 +559,21 @@ if (
558559
"Pings will be given the specified tags until the tab is closed."
559560
);
560561
},
562+
debugSession: () => {
563+
const sessionId = Context.metricsDatabase.getMetric(
564+
CLIENT_INFO_STORAGE,
565+
Context.coreMetrics.sessionId
566+
);
567+
568+
if (!!sessionId && typeof sessionId === "string" && !!Context.config.debugViewTag) {
569+
window.open(
570+
`https://debug-ping-preview.firebaseapp.com/stream/${Context.config.debugViewTag}#${sessionId}`,
571+
"_blank"
572+
);
573+
} else {
574+
console.info("You must set a debug tag via `window.Glean.setDebugViewTag` before debugging your session.");
575+
}
576+
}
561577
};
562578
}
563579

0 commit comments

Comments
 (0)