Example #1
0
def reporting_off():
    hub_reporter.consent = HumbugConsent(False)
Example #2
0
    def __call__(
        self,
        *,
        started_workunits: tuple[Workunit, ...],
        completed_workunits: tuple[Workunit, ...],
        finished: bool,
        context: StreamingWorkunitContext,
    ) -> None:
        if not finished:
            return

        # Assemble and send the telemetry.
        # Note that this method is called with finished=True only after the
        # StreamingWorkunitHandler context ends, i.e., after end_run() has been called,
        # so the RunTracker will have had a chance to finalize its state.
        telemetry_data = context.run_tracker.get_anonymous_telemetry_data(self._unhashed_repo_id)
        # TODO: Add information about any errors that occurred.

        reporter = HumbugReporter(
            name="pantsbuild/pants",
            # We've already established consent at this point.
            consent=HumbugConsent(True),
            session_id=str(telemetry_data.get("run_id", uuid.uuid4())),
            bugout_token=_bugout_access_token,
            timeout_seconds=5,
            # We don't want to spawn a thread in the engine, and we're
            # already running in a background thread in pantsd.
            mode=Modes.SYNCHRONOUS,
        )

        # This is copied from humbug code, to ensure that future changes to humbug
        # don't add tags that inadvertently violate our anonymity promise.
        system_tags = [
            f"source:{reporter.name}",
            f"os:{reporter.system_information.os}",
            f"arch:{reporter.system_information.machine}",
            f"python:{reporter.system_information.python_version_major}",
            "python:{}.{}".format(
                reporter.system_information.python_version_major,
                reporter.system_information.python_version_minor,
            ),
            f"python:{reporter.system_information.python_version}",
            f"session:{reporter.session_id}",
        ]
        tags = (
            system_tags
            + [
                f"pants_version:{telemetry_data.get('pants_version')}",
                # This is hashed, unlike the contents of the unhashed_repo_id var.
                f"repo:{telemetry_data.get('repo_id', 'UNKNOWN')}",
                f"user:{telemetry_data.get('user_id', 'UNKNOWN')}",
                f"machine:{telemetry_data.get('machine_id', 'UNKNOWN')}",
                f"duration:{telemetry_data.get('duration', '0')}",
                f"outcome:{telemetry_data.get('outcome', 'UNKNOWN')}",
            ]
            + [f"goal:{goal}" for goal in telemetry_data.get("standard_goals", [])]
        )

        report = Report(
            title=f"pants run {reporter.session_id}",
            tags=tags,
            content=json.dumps(telemetry_data, sort_keys=True),
        )
        reporter.publish(report)
Example #3
0
    reporting_config = {}
    try:
        if not os.path.exists(REPORT_CONSENT_FILE_PATH):
            client_id = str(uuid.uuid4())
            reporting_config["client_id"] = client_id
            configure_reporting(True, client_id)
        with open(REPORT_CONSENT_FILE_PATH, "r") as ifp:
            reporting_config = json.load(ifp)
    except Exception:
        pass
    return reporting_config


session_id = str(uuid.uuid4())

hub_consent = HumbugConsent(hub_consent_from_file)
hub_reporter = Reporter(
    "activeloopai/Hub",
    hub_consent,
    client_id=get_reporting_config().get("client_id"),
    session_id=session_id,
    bugout_token=HUMBUG_TOKEN,
    bugout_journal_id=HUMBUG_KB_ID,
    timeout_seconds=5,
)


hub_version_tag = "version:{}".format(hub_version)
hub_tags = [hub_version_tag]

hub_user = get_reporting_config().get("username")
Example #4
0
    confirm = input("Continue? [Y/n]")
    if confirm.lower() == "n":
        print("Okay, exiting")
        sys.exit(1)

"""
This script uses a consent flow in which consent is granted to report errors by default but users
can opt out of reporting by setting an environment variable:
BUGOUT_DEMO_REPORTING_ENABLED=0

To learn more about consent mechanisms available in the Humbug Python library, read the consent
section in:
https://github.com/bugout-dev/humbug/blob/main/python/README.md
"""
consent = HumbugConsent(
    environment_variable_opt_out("BUGOUT_DEMO_REPORTING_ENABLED", no)
)

"""
Now we create a Humbug reporter object to send reports.
"""
session_id = str(uuid.uuid4())
reporter = HumbugReporter(
    "recipes/error_reporting",
    consent,
    session_id=session_id,
    bugout_token=bugout_access_token,
)

"""
There are a few ways to report errors from a Python program. If you are writing your own exception
Example #5
0
    def __call__(
        self,
        *,
        started_workunits: tuple[Workunit, ...],
        completed_workunits: tuple[Workunit, ...],
        finished: bool,
        context: StreamingWorkunitContext,
    ) -> None:
        if not finished:
            return

        if self._anonymous_telemetry.options.is_default("enabled"):
            logger.warning(
                f"Please either set `enabled = true` in the [anonymous-telemetry] section of "
                f"pants.toml to enable sending anonymous stats to the Pants project to aid "
                f"development, or set `enabled = false` to disable it. No telemetry sent "
                f"for this run. An explicit setting will get rid of this message. "
                f"{_telemetry_docs_referral}.")

        if self._anonymous_telemetry.enabled:
            repo_id = self._anonymous_telemetry.repo_id
            if repo_id is None:
                logger.error(
                    f'Please set `repo_id = "<uuid>"` in the [anonymous-telemetry] section '
                    f"of pants.toml, where `<uuid>` is some fixed random identifier, such as "
                    f"one generated by uuidgen. No telemetry sent for this run. "
                    f"{_telemetry_docs_referral}.")
            elif self.validate_repo_id(repo_id):
                # Assemble and send the telemetry.
                # Note that this method is called with finished=True only after the
                # StreamingWorkunitHandler context ends, i.e., after end_run() has been called,
                # so the RunTracker will have had a chance to finalize its state.
                telemetry_data = context.run_tracker.get_anonymous_telemetry_data(
                    repo_id)
                # TODO: Add information about any errors that occurred.

                reporter = Reporter(
                    name="pantsbuild/pants",
                    # We've already established consent at this point.
                    consent=HumbugConsent(True),
                    session_id=telemetry_data.get("run_id", str(uuid.uuid4())),
                    bugout_token=_bugout_access_token,
                    bugout_journal_id=_bugout_journal_id,
                    timeout_seconds=5,
                    # We don't want to spawn a thread in the engine, and we're
                    # already running in a background thread in pantsd.
                    mode=Modes.SYNCHRONOUS,
                )

                # This is copied from humbug code, to ensure that future changes to humbug
                # don't add tags that inadvertently violate our anonymity promise.
                system_tags = [
                    "humbug",
                    "source:{}".format(reporter.name),
                    "os:{}".format(reporter.system_information.os),
                    "arch:{}".format(reporter.system_information.machine),
                    "python:{}".format(
                        reporter.system_information.python_version_major),
                    "python:{}.{}".format(
                        reporter.system_information.python_version_major,
                        reporter.system_information.python_version_minor,
                    ),
                    "python:{}".format(
                        reporter.system_information.python_version),
                    "session:{}".format(reporter.session_id),
                ]
                tags = (system_tags + [
                    f"pants_version:{telemetry_data.get('pants_version')}",
                    f"repo:{repo_id}",
                    f"user:{telemetry_data.get('user_id', 'UNKNOWN')}",
                    f"machine:{telemetry_data.get('machine_id', 'UNKNOWN')}",
                    f"duration:{telemetry_data.get('duration', '0')}",
                    f"outcome:{telemetry_data.get('outcome', 'UNKNOWN')}",
                ] + [
                    f"goal:{goal}"
                    for goal in telemetry_data.get("standard_goals", [])
                ])

                report = Report(
                    title=f"pants run {reporter.session_id}",
                    tags=tags,
                    content=json.dumps(telemetry_data, sort_keys=True),
                )
                reporter.publish(report)