def reporting(on): """ Enable or disable sending crash reports to Activeloop AI. """ report = Report( title="Consent change", tags=hub_reporter.system_tags(), content="Consent? `{}`".format(on), ) hub_reporter.publish(report) configure_reporting(on)
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)
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)