Toggling upload status

The Glean SDKs provide an API for toggling Glean's upload status after initialization.

Applications instrumented with Glean are expected to provide some form of user interface to allow for toggling the upload status.

Disabling upload

When upload is disabled, the Glean SDK will perform the following tasks:

  1. Submit a deletion-request ping.
  2. Cancel scheduled ping uploads.
  3. Clear metrics and pings data from the client, except for the first_run_date and first_run_hour metrics.

While upload is disabled, metrics aren't recorded and no data is uploaded.

Enabling upload

When upload is enabled, the Glean SDK will re-initialize its core metrics. The only core metrics that are not re-initialized are the first_run_date and first_run_hour metrics.

While upload is enabled all metrics are recorded as expected and pings are sent to the telemetry servers.

API

Glean.setUploadEnabled(boolean)

Enables or disables upload.

If called prior to initialize this function is a no-op.

If the upload state is not actually changed in between calls to this function, it is also a no-op.

import mozilla.telemetry.glean.Glean

open class MainActivity : AppCompatActivity() {
    override fun onCreate() {
        // ...

        uploadSwitch.setOnCheckedChangeListener { _, isChecked ->
            if (isChecked) {
                Glean.setUploadEnabled(true)
            } else {
                Glean.setUploadEnabled(false)
            }
        }
    }
}
import mozilla.telemetry.glean.Glean

Glean.INSTANCE.setUploadEnabled(false);
import Glean
import UIKit

class ViewController: UIViewController {
    @IBOutlet var enableSwitch: UISwitch!

    // ...

    @IBAction func enableToggled(_: Any) {
        Glean.shared.setUploadEnabled(enableSwitch.isOn)
    }
}
from glean import Glean

Glean.set_upload_enabled(false)
use glean;

glean::set_upload_enabled(false);
import Glean from "@mozilla/glean/web";

const uploadSwitch = document.querySelector("input[type=checkbox].upload-switch");
uploadSwitch.addEventListener("change", event => {
    if (event.target.checked) {
        Glean.setUploadEnabled(true);
    } else {
        Glean.setUploadEnabled(false);
    }
});

Reference