@@ -8,19 +8,12 @@ import Glean from "@mozilla/glean/web";
88import { benchmark } from "./generated/pings.js" ;
99import * as metrics from "./generated/sample.js" ;
1010
11- Glean . setSourceTags ( [ "automation" ] ) ;
12- Glean . initialize ( "glean-compat-benchmark" , true , {
13- enableAutoPageLoadEvents : true
14- } ) ;
15-
16- metrics . pageLoaded . set ( ) ;
17- benchmark . submit ( ) ;
18-
1911// !BIG HACK!
2012//
2113// Overwrite the console.info function in order to know when (and if) the benchmark ping was sent.
2214// If a success ping message is logged we show that in the document.
2315let pingSubmissionCount = 0 ;
16+ let sessionId = "" ;
2417console . info = function ( ) {
2518 var message = "" ;
2619 for ( var i = 0 ; i < arguments . length ; i ++ ) {
@@ -30,6 +23,7 @@ console.info = function () {
3023 message += " " ;
3124 }
3225 }
26+
3327 console . log ( message ) ;
3428 if ( / s u c c e s s f u l l y s e n t 2 0 0 .$ / . test ( message ) ) {
3529 pingSubmissionCount ++ ;
@@ -38,8 +32,40 @@ console.info = function () {
3832 // 1. The built-in page_load event, which submits an events ping.
3933 // 2. The benchmark ping.
4034 if ( pingSubmissionCount == 2 ) {
41- var elem = document . getElementById ( "msg " ) ;
35+ var elem = document . getElementById ( "ping_msg " ) ;
4236 elem . innerHTML = "Pings submitted successfully." ;
4337 }
4438 }
39+
40+ const sessionRegex = / " s e s s i o n _ i d " : .+ " / ;
41+ const sessionInfo = sessionRegex . exec ( message ) ;
42+ if ( ! ! sessionInfo ) {
43+ const currSessionId = sessionInfo ?. [ 0 ] . split ( `"` ) ?. [ 3 ] ;
44+ if ( ! ! sessionId ) {
45+ if ( currSessionId !== sessionId ) {
46+ var elem = document . getElementById ( "session_msg" ) ;
47+ elem . innerHTML = "Session IDs updated successfully." ;
48+ } else {
49+ console . log ( "Something went wrong..." ) ;
50+ }
51+ }
52+
53+ sessionId = currSessionId ;
54+ }
4555}
56+
57+ Glean . setSourceTags ( [ "automation" ] ) ;
58+
59+ // This needs to be set so we can pull the session ID from the log messages.
60+ Glean . setLogPings ( true ) ;
61+
62+ Glean . initialize ( "glean-compat-benchmark" , true , {
63+ enableAutoPageLoadEvents : true ,
64+ // Setting the override to 0 means every action will trigger
65+ // a new session. We use this to check that the session ID
66+ // changes whenever a session has expired.
67+ sessionLengthInMinutesOverride : 0
68+ } ) ;
69+
70+ metrics . pageLoaded . set ( ) ;
71+ benchmark . submit ( ) ;
0 commit comments