Skip to content
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

Update Glean debugging docs (Fixes #13876) #13877

Merged
merged 1 commit into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 13 additions & 17 deletions docs/attribution/0001-analytics.rst
Original file line number Diff line number Diff line change
Expand Up @@ -350,12 +350,19 @@ to measure.
Debugging pings
---------------

For all non-production environments, bedrock will automatically set a debug
view tag for all pings. This means that when running on localhost, on a demo,
or on a staging environment, ping data will be viewable in the
`Glean debug dashboard`_ which can be used to test that pings are working
correctly. All bedrock debug pings will register in the debug dashboard with
the tag name ``bedrock``.
Glean supports debugging pings via a set of flags that can be enabled directly
in the browser's web console.

- ``window.Glean.setLogPings(true)`` (enable verbose ping logging in the web console).
- ``window.Glean.setDebugViewTag('bedrock')`` (send pings to the `Glean debug dashboard`_ with the tag name ``bedrock``).

.. Note::

After enabling Glean debugging in the web console, it will be remembered
when navigating across pages using ``sessionStorage``. To stop debugging,
you need to either close the browser tab, or delete the items from
``sessionStorage``. You can disable ping logging by calling
``window.Glean.setLogPings(false)``.

Filtering out non-production pings
----------------------------------
Expand All @@ -365,17 +372,6 @@ Bedrock will also set an ``app_channel`` tag with a value of either ``prod`` or
``client_info`` section, and is useful for filtering out non-production data
in telemetry dashboards.

Logging pings in the console
----------------------------

When running bedrock locally, you can also set the following environment variable
in your ``.env``` file to automatically log pings in the browser's web console.
This can be especially useful when making updates to analytics code.

.. code-block::

GLEAN_LOG_PINGS=True

Defining metrics and pings
--------------------------

Expand Down
6 changes: 0 additions & 6 deletions glean/metrics.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ page:
type: datetime
lifetime: application
send_in_pings:
- page-view
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note for reviewer: these are leftover from #13689 and can be removed.

- events
description: |
The time a page was viewed.
Expand All @@ -23,7 +22,6 @@ page:
type: string
lifetime: application
send_in_pings:
- page-view
- events
description: |
The URL path of the page that was viewed, excluding locale.
Expand All @@ -40,7 +38,6 @@ page:
type: string
lifetime: application
send_in_pings:
- page-view
- events
description: |
The locale of the page that was viewed.
Expand All @@ -57,7 +54,6 @@ page:
type: labeled_string
lifetime: application
send_in_pings:
- page-view
- events
description: |
Query parameters associated with the URL of
Expand All @@ -84,7 +80,6 @@ page:
type: string
lifetime: application
send_in_pings:
- page-view
- events
description: |
The referring URL that linked to the page that was viewed.
Expand All @@ -103,7 +98,6 @@ page:
The HTTP status code of the page.
lifetime: application
send_in_pings:
- page-view
- events
data_sensitivity:
- technical
Expand Down
23 changes: 5 additions & 18 deletions media/js/glean/init.es6.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,22 @@
*/

import Glean from '@mozilla/glean/web';

import { initPageView, pageEvent } from './page.es6';
import { clickEvent } from './elements.es6';
import Utils from './utils.es6';

const shouldInitialize = Utils.hasValidURLScheme(window.location.href);

function initGlean() {
const pageUrl = window.location.href;
const endpoint = 'https://www.mozilla.org';
const channel =
window.location.href.indexOf('https://www.mozilla.org/') === -1
? 'non-prod'
: 'prod';

// Automatically console.log() pings.
// eslint-disable-next-line no-undef
if (process.env.GLEAN_LOG_PINGS === 'True') {
Glean.setLogPings(true);
}

// Enable debug view for all non-production environments.
// https://debug-ping-preview.firebaseapp.com/
if (channel === 'non-prod') {
Glean.setDebugViewTag('bedrock');
}
const channel = pageUrl.startsWith('https://www.mozilla.org/')
? 'prod'
: 'non-prod';

// Ensure telemetry coming from automated testing is tagged
// https://mozilla.github.io/glean/book/reference/debug/sourceTags.html
if (window.location.href.indexOf('automation=true') !== -1) {
if (pageUrl.includes('automation=true')) {
Glean.setSourceTags(['automation']);
}

Expand Down
4 changes: 2 additions & 2 deletions media/js/glean/utils.es6.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ const Utils = {

// Ensure we don't include tokens in newsletter page pings
// Issue https://github.com/mozilla/bedrock/issues/13583
if (pathName.indexOf('/newsletter/existing/') !== -1) {
if (pathName.includes('/newsletter/existing/')) {
pathName = '/newsletter/existing/';
}

if (pathName.indexOf('/newsletter/country/') !== -1) {
if (pathName.includes('/newsletter/country/')) {
pathName = '/newsletter/country/';
}

Expand Down