| 1 |
// Copyright 2024 The Go Authors. All rights reserved. |
| 2 |
// Use of this source code is governed by a BSD-style |
| 3 |
// license that can be found in the LICENSE file. |
| 4 |
|
| 5 |
// Package telemetrycmd implements the "go telemetry" command. |
| 6 |
package telemetrycmd |
| 7 |
|
| 8 |
import ( |
| 9 |
"context" |
| 10 |
"fmt" |
| 11 |
"os" |
| 12 |
|
| 13 |
"cmd/go/internal/base" |
| 14 |
"cmd/internal/telemetry" |
| 15 |
) |
| 16 |
|
| 17 |
var CmdTelemetry = &base.Command{ |
| 18 |
UsageLine: "go telemetry [off|local|on]", |
| 19 |
Short: "manage telemetry data and settings", |
| 20 |
Long: `Telemetry is used to manage Go telemetry data and settings. |
| 21 |
|
| 22 |
Telemetry can be in one of three modes: off, local, or on. |
| 23 |
|
| 24 |
When telemetry is in local mode, counter data is written to the local file |
| 25 |
system, but will not be uploaded to remote servers. |
| 26 |
|
| 27 |
When telemetry is off, local counter data is neither collected nor uploaded. |
| 28 |
|
| 29 |
When telemetry is on, telemetry data is written to the local file system |
| 30 |
and periodically sent to https://telemetry.go.dev/. Uploaded data is used to |
| 31 |
help improve the Go toolchain and related tools, and it will be published as |
| 32 |
part of a public dataset. |
| 33 |
|
| 34 |
For more details, see https://telemetry.go.dev/privacy. |
| 35 |
This data is collected in accordance with the Google Privacy Policy |
| 36 |
(https://policies.google.com/privacy). |
| 37 |
|
| 38 |
To view the current telemetry mode, run "go telemetry". |
| 39 |
To disable telemetry uploading, but keep local data collection, run |
| 40 |
"go telemetry local". |
| 41 |
To enable both collection and uploading, run “go telemetry on”. |
| 42 |
To disable both collection and uploading, run "go telemetry off". |
| 43 |
|
| 44 |
The current telemetry mode is also available as the value of the |
| 45 |
non-settable "GOTELEMETRY" go env variable. The directory in the |
| 46 |
local file system that telemetry data is written to is available |
| 47 |
as the value of the non-settable "GOTELEMETRYDIR" go env variable. |
| 48 |
|
| 49 |
See https://go.dev/doc/telemetry for more information on telemetry. |
| 50 |
`, |
| 51 |
Run: runTelemetry, |
| 52 |
} |
| 53 |
|
| 54 |
func init() { |
| 55 |
base.AddChdirFlag(&CmdTelemetry.Flag) |
| 56 |
} |
| 57 |
|
| 58 |
func runTelemetry(ctx context.Context, cmd *base.Command, args []string) { |
| 59 |
if len(args) == 0 { |
| 60 |
fmt.Println(telemetry.Mode()) |
| 61 |
return |
| 62 |
} |
| 63 |
|
| 64 |
if len(args) != 1 { |
| 65 |
cmd.Usage() |
| 66 |
} |
| 67 |
|
| 68 |
mode := args[0] |
| 69 |
if mode != "local" && mode != "off" && mode != "on" { |
| 70 |
cmd.Usage() |
| 71 |
} |
| 72 |
if old := telemetry.Mode(); old == mode { |
| 73 |
return |
| 74 |
} |
| 75 |
|
| 76 |
if err := telemetry.SetMode(mode); err != nil { |
| 77 |
base.Fatalf("go: failed to set the telemetry mode to %s: %v", mode, err) |
| 78 |
} |
| 79 |
if mode == "on" { |
| 80 |
fmt.Fprintln(os.Stderr, telemetryOnMessage()) |
| 81 |
} |
| 82 |
} |
| 83 |
|
| 84 |
func telemetryOnMessage() string { |
| 85 |
return `Telemetry uploading is now enabled and data will be periodically sent to |
| 86 |
https://telemetry.go.dev/. Uploaded data is used to help improve the Go |
| 87 |
toolchain and related tools, and it will be published as part of a public |
| 88 |
dataset. |
| 89 |
|
| 90 |
For more details, see https://telemetry.go.dev/privacy. |
| 91 |
This data is collected in accordance with the Google Privacy Policy |
| 92 |
(https://policies.google.com/privacy). |
| 93 |
|
| 94 |
To disable telemetry uploading, but keep local data collection, run |
| 95 |
“go telemetry local”. |
| 96 |
To disable both collection and uploading, run “go telemetry off“.` |
| 97 |
} |