Telemetry¶
A simple pre-configured --telemetry/--no-telemetry option flag, that is respecting the proposed DO_NOT_TRACK environment variable as a unified standard to opt-out of telemetry for TUI/console apps.
It does nothing else.
from click_extra import command, context, echo, pass_context, telemetry_option
@command
@telemetry_option
@pass_context
def orchard(ctx):
"""Count the apple trees."""
echo(f"Telemetry: {context.get(ctx, context.TELEMETRY)}")
DO_NOT_TRACK precedence¶
A truthy DO_NOT_TRACK turns telemetry off. Most specific first:
--telemetryor--no-telemetryon the command line;DO_NOT_TRACKin the environment;<CLI>_TELEMETRYin the environment;telemetryin the CLI’s configuration file;the built-in default, off.
This ranks DO_NOT_TRACK above the variable of the option and above the configuration file, where the other machine-wide variables, like CLICK_EXTRA_THEME, rank below both. DO_NOT_TRACK is a consumer-protection opt-out: a user exports it once to refuse tracking from every tool, and a configuration file a project ships, or a variable a wrapper sets, must not opt that user back in. Only the command line, which the user types, outranks it:
$ orchard
Telemetry: False
$ orchard --telemetry
Telemetry: True
click_extra.telemetry API¶
classDiagram
ExtraOption <|-- TelemetryOption
Telemetry utilities.
- class click_extra.telemetry.TelemetryOption(param_decls=None, *, default=False, expose_value=False, envvar=None, show_envvar=True, help='Collect telemetry and usage data.', **kwargs)[source]
Bases:
ExtraOptionA pre-configured
--telemetry/--no-telemetryoption flag.Respects the proposed DO_NOT_TRACK environment variable as a unified standard to opt-out of telemetry for TUI/console apps: a truthy
DO_NOT_TRACKforces telemetry off, overriding the user-defined environment variables, the auto-generated values, and configuration files. Only an explicit--telemetryon the command line outranks it.The resolved value is stored in
ctx.meta[click_extra.context.TELEMETRY].See also
- set_telemetry(ctx, param, value)[source]
Reconcile the flag with
DO_NOT_TRACKand store the result onctx.meta.An explicit
--telemetry/--no-telemetryon the command line wins. Otherwise a truthyDO_NOT_TRACK(bare presence, or any value not parseable as false, seeparse_envvar_flag()) forces telemetry off. Read viaclick_extra.context.get(ctx, click_extra.context.TELEMETRY).Important
DO_NOT_TRACKbreaks the rule of the other machine-wide variables, which a configuration file and the option’s own variable outrank (seemachine_envvars_apply()). It is a consumer-protection opt-out: a user exports it once to refuse tracking from every tool, and a configuration file a project ships, or a<CLI>_TELEMETRYvariable a wrapper or a CI job sets, must not opt that user back in. Only the command line, which the user types, outranks it.Note
DO_NOT_TRACKis read here rather than wired through the option’senvvar: Click’s environment plumbing feeds the raw value straight to the boolean flag, soDO_NOT_TRACK=1would enable telemetry, inverting the convention. Reading it manually keeps the opt-out meaning, mirroring howColorOptionreadsNO_COLORand friends.- Return type: