Skip to content

Commit 7802f71

Browse files
committed
crash_reporting: add a compile-time flag to disable crash reporting
Previously, there was a way to disable crash reporting, by disabling telemetry. One of the downside of this approach is that startup crashes are still reported, even if telemetry is disabled. This change explicitly sets the crash report URL to an empty string in case if telemetry disabled compile time. Release note: none Epic: none
1 parent c9f19bb commit 7802f71

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

pkg/settings/cluster/cluster_settings.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ type OverridesInformer interface {
6767

6868
var SettingOverrideErr = errors.New("cluster setting is overridden by system virtual cluster")
6969

70-
// telemetryOptOutCompTimeString controls wether to opt out of telemetry
70+
// telemetryOptOutCompTimeString controls whether to opt out of telemetry
7171
// (including Sentry) or not compile time. The variable is set by bazel via stamping
7272
// (`stamp.sh -d true/false`). Becuase Go only supports strings for in
7373
// `-ldflags "-X ..."`, we have to use a string representation here.

pkg/util/log/logcrash/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ go_library(
77
visibility = ["//visibility:public"],
88
x_defs = {
99
"github.com/cockroachdb/cockroach/pkg/util/log/logcrash.crashReportEnv": "{STABLE_CRASH_REPORT_ENV}",
10+
"github.com/cockroachdb/cockroach/pkg/util/log/logcrash.crashReportingDisabledString": "{STABLE_TELEMETRY_DISABLED}",
1011
},
1112
deps = [
1213
"//pkg/build",

pkg/util/log/logcrash/crash_reporting.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ package logcrash
88
import (
99
"context"
1010
"fmt"
11+
"strconv"
1112
"strings"
1213
"sync/atomic"
1314
"time"
@@ -209,6 +210,21 @@ func PanicAsError(depth int, r interface{}) error {
209210
return errors.NewWithDepthf(depth+1, "panic: %v", r)
210211
}
211212

213+
// crashReportingDisabledString controls whether to opt out of crash reporting
214+
// or not compile time. The variable is set by bazel via stamping
215+
// (`stamp.sh -d true/false`, which controls telemetry opt out). Becuase Go only
216+
// supports strings for in `-ldflags "-X ..."`, we have to use a string
217+
// representation here.
218+
var crashReportingDisabledString = "false"
219+
220+
func crashReportingDisabled() bool {
221+
ret, err := strconv.ParseBool(crashReportingDisabledString)
222+
if err != nil {
223+
return false
224+
}
225+
return ret
226+
}
227+
212228
// Crash reporting URL.
213229
//
214230
// This uses a Sentry proxy run by Cockroach Labs. The proxy
@@ -227,6 +243,9 @@ func PanicAsError(depth int, r interface{}) error {
227243
// TODO(knz): We could envision auto-selecting this alternate URL
228244
// when detecting a non-release build.
229245
var crashReportURL = func() string {
246+
if crashReportingDisabled() {
247+
return ""
248+
}
230249
var defaultURL string
231250
if build.SeemsOfficial() {
232251
defaultURL = "https://[email protected]/api/sentry/v2/1111"

0 commit comments

Comments
 (0)