Skip to content

Commit 6626a0d

Browse files
committed
telemetry: expose Mode and SetMode
Gopls needs to be able to query and set the current telemetry mode. Expose the Mode and SetMode APIs for this purpose. For golang/go#62576 Change-Id: I1f9aa03595cfa1b60c88ebe8a560c5ac6a1b1b40 Reviewed-on: https://go-review.googlesource.com/c/telemetry/+/527717 LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Peter Weinberger <[email protected]>
1 parent d440a24 commit 6626a0d

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

internal/telemetry/mode.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func init() {
4141
}
4242

4343
// SetMode updates the telemetry mode with the given mode.
44-
// Acceptable values for mode are "on", "off", "local", or https:// urls.
44+
// Acceptable values for mode are "on", "off", or "local".
4545
func SetMode(mode string) error {
4646
return ModeFile.SetMode(mode)
4747
}

mode.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Copyright 2023 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 telemetry
6+
7+
import (
8+
it "golang.org/x/telemetry/internal/telemetry"
9+
)
10+
11+
// Mode returns the current telemetry mode.
12+
//
13+
// The telemetry mode is a global value that controls both the collection and
14+
// uploading of telemetry data. When collection is enabled, telemetry counters
15+
// and stack information are written to the local file system and may be
16+
// inspected with the [gotelemetry] command. When uploading is enabled, this
17+
// anonymous data is periodically uploaded to remote servers.
18+
//
19+
// Possible mode values are:
20+
// - "on": both collection and uploading are enabled
21+
// - "local": telemetry collection is enabled, but uploading is disabled
22+
// - "off": both collection and uploading are disabled
23+
//
24+
// If an error occurs while reading the telemetry mode from the file system,
25+
// Mode returns the default value "local".
26+
//
27+
// [gotelemetry]: https://pkg.go.dev/golang.org/x/telemetry/cmd/gotelemetry
28+
func Mode() string {
29+
return it.Mode()
30+
}
31+
32+
// SetMode sets the global telemetry mode to the given value.
33+
//
34+
// See the documentation of [Mode] for a description of the supported mode
35+
// values.
36+
//
37+
// An error is returned if the provided mode value is invalid, or if an error
38+
// occurs while persisting the mode value to the file system.
39+
func SetMode(mode string) error {
40+
return it.SetMode(mode)
41+
}

0 commit comments

Comments
 (0)