diff --git a/pkg/BUILD.bazel b/pkg/BUILD.bazel index 058bdb1cd73a..52b19b4455e8 100644 --- a/pkg/BUILD.bazel +++ b/pkg/BUILD.bazel @@ -2419,6 +2419,7 @@ GO_TARGETS = [ "//pkg/util/sdnotify:sdnotify_test", "//pkg/util/search:search", "//pkg/util/search:search_test", + "//pkg/util/sentryutil:sentryutil", "//pkg/util/shuffle:shuffle", "//pkg/util/shuffle:shuffle_test", "//pkg/util/slidingwindow:slidingwindow", diff --git a/pkg/sql/BUILD.bazel b/pkg/sql/BUILD.bazel index de7cb6f6f44d..70e91c05f24e 100644 --- a/pkg/sql/BUILD.bazel +++ b/pkg/sql/BUILD.bazel @@ -564,6 +564,7 @@ go_library( "//pkg/util/rangedesc", "//pkg/util/retry", "//pkg/util/ring", + "//pkg/util/sentryutil", "//pkg/util/startup", "//pkg/util/stop", "//pkg/util/syncutil", diff --git a/pkg/sql/conn_executor.go b/pkg/sql/conn_executor.go index b015539186bd..db87075d9c87 100644 --- a/pkg/sql/conn_executor.go +++ b/pkg/sql/conn_executor.go @@ -80,6 +80,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/util/log/severity" "github.com/cockroachdb/cockroach/pkg/util/metric" "github.com/cockroachdb/cockroach/pkg/util/mon" + "github.com/cockroachdb/cockroach/pkg/util/sentryutil" "github.com/cockroachdb/cockroach/pkg/util/stop" "github.com/cockroachdb/cockroach/pkg/util/syncutil" "github.com/cockroachdb/cockroach/pkg/util/timeutil" @@ -3776,7 +3777,7 @@ func (ex *connExecutor) txnStateTransitionsApplyWrapper( errors.Safe(advInfo.txnEvent.eventType.String()), res.Err()) log.Errorf(ex.Ctx(), "%v", err) - errorutil.SendReport(ex.Ctx(), &ex.server.cfg.Settings.SV, err) + sentryutil.SendReport(ex.Ctx(), &ex.server.cfg.Settings.SV, err) return advanceInfo{}, err } diff --git a/pkg/sql/opt/norm/BUILD.bazel b/pkg/sql/opt/norm/BUILD.bazel index f5cc59b47bad..5cf9b2c64ab4 100644 --- a/pkg/sql/opt/norm/BUILD.bazel +++ b/pkg/sql/opt/norm/BUILD.bazel @@ -57,6 +57,7 @@ go_library( "//pkg/util/errorutil", "//pkg/util/intsets", "//pkg/util/json", + "//pkg/util/sentryutil", "@com_github_cockroachdb_apd_v3//:apd", "@com_github_cockroachdb_errors//:errors", "@com_github_cockroachdb_redact//:redact", diff --git a/pkg/sql/opt/norm/factory.go b/pkg/sql/opt/norm/factory.go index fa636e130935..a92f82b998a4 100644 --- a/pkg/sql/opt/norm/factory.go +++ b/pkg/sql/opt/norm/factory.go @@ -27,6 +27,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/util/buildutil" "github.com/cockroachdb/cockroach/pkg/util/errorutil" "github.com/cockroachdb/cockroach/pkg/util/intsets" + "github.com/cockroachdb/cockroach/pkg/util/sentryutil" "github.com/cockroachdb/errors" "github.com/cockroachdb/redact" ) @@ -411,7 +412,7 @@ func (f *Factory) onMaxConstructorStackDepthExceeded() { if buildutil.CrdbTestBuild { panic(err) } - errorutil.SendReport(f.ctx, &f.evalCtx.Settings.SV, err) + sentryutil.SendReport(f.ctx, &f.evalCtx.Settings.SV, err) } // onConstructRelational is called as a final step by each factory method that diff --git a/pkg/sql/stats/BUILD.bazel b/pkg/sql/stats/BUILD.bazel index 8fa7dc7c0338..a269c542ea2a 100644 --- a/pkg/sql/stats/BUILD.bazel +++ b/pkg/sql/stats/BUILD.bazel @@ -55,6 +55,7 @@ go_library( "//pkg/util/log/logcrash", "//pkg/util/mon", "//pkg/util/protoutil", + "//pkg/util/sentryutil", "//pkg/util/stop", "//pkg/util/syncutil", "//pkg/util/timeutil", diff --git a/pkg/sql/stats/forecast.go b/pkg/sql/stats/forecast.go index 32e7f226cb33..7d3b15e2dbd9 100644 --- a/pkg/sql/stats/forecast.go +++ b/pkg/sql/stats/forecast.go @@ -28,6 +28,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/util/errorutil" "github.com/cockroachdb/cockroach/pkg/util/log" "github.com/cockroachdb/cockroach/pkg/util/log/logcrash" + "github.com/cockroachdb/cockroach/pkg/util/sentryutil" "github.com/cockroachdb/errors" "github.com/cockroachdb/redact" ) @@ -343,7 +344,7 @@ func forecastColumnStatistics( "forecasted histogram had first bucket with non-zero NumRange or DistinctRange: %s", debugging, ) - errorutil.SendReport(ctx, sv, err) + sentryutil.SendReport(ctx, sv, err) return nil, err } if bucket.UpperBound != tree.DNull { diff --git a/pkg/util/errorutil/BUILD.bazel b/pkg/util/errorutil/BUILD.bazel index 0039476c297f..9d4db9556cf1 100644 --- a/pkg/util/errorutil/BUILD.bazel +++ b/pkg/util/errorutil/BUILD.bazel @@ -12,9 +12,7 @@ go_library( importpath = "github.com/cockroachdb/cockroach/pkg/util/errorutil", visibility = ["//visibility:public"], deps = [ - "//pkg/settings", "//pkg/util/errorutil/unimplemented", - "//pkg/util/log/logcrash", "@com_github_cockroachdb_errors//:errors", ], ) diff --git a/pkg/util/errorutil/error.go b/pkg/util/errorutil/error.go index 48c8618bcb40..11f68f38c185 100644 --- a/pkg/util/errorutil/error.go +++ b/pkg/util/errorutil/error.go @@ -11,11 +11,8 @@ package errorutil import ( - "context" "fmt" - "github.com/cockroachdb/cockroach/pkg/settings" - "github.com/cockroachdb/cockroach/pkg/util/log/logcrash" "github.com/cockroachdb/errors" ) @@ -37,14 +34,3 @@ func UnexpectedWithIssueErrorf(issue int, format string, args ...interface{}) er issue)) return err } - -// SendReport creates a Sentry report about the error, if the settings allow. -// The format string will be reproduced ad litteram in the report; the arguments -// will be sanitized. -func SendReport(ctx context.Context, sv *settings.Values, err error) { - if !logcrash.ShouldSendReport(sv) { - return - } - event, extraDetails := errors.BuildSentryReport(err) - logcrash.SendReport(ctx, logcrash.ReportTypeError, event, extraDetails) -} diff --git a/pkg/util/sentryutil/BUILD.bazel b/pkg/util/sentryutil/BUILD.bazel new file mode 100644 index 000000000000..730451ff50ad --- /dev/null +++ b/pkg/util/sentryutil/BUILD.bazel @@ -0,0 +1,13 @@ +load("@io_bazel_rules_go//go:def.bzl", "go_library") + +go_library( + name = "sentryutil", + srcs = ["sentry.go"], + importpath = "github.com/cockroachdb/cockroach/pkg/util/sentryutil", + visibility = ["//visibility:public"], + deps = [ + "//pkg/settings", + "//pkg/util/log/logcrash", + "@com_github_cockroachdb_errors//:errors", + ], +) diff --git a/pkg/util/sentryutil/sentry.go b/pkg/util/sentryutil/sentry.go new file mode 100644 index 000000000000..c7ceccc0327a --- /dev/null +++ b/pkg/util/sentryutil/sentry.go @@ -0,0 +1,30 @@ +// Copyright 2023 The Cockroach Authors. +// +// Use of this software is governed by the Business Source License +// included in the file licenses/BSL.txt. +// +// As of the Change Date specified in that file, in accordance with +// the Business Source License, use of this software will be governed +// by the Apache License, Version 2.0, included in the file +// licenses/APL.txt. + +package sentryutil + +import ( + "context" + + "github.com/cockroachdb/cockroach/pkg/settings" + "github.com/cockroachdb/cockroach/pkg/util/log/logcrash" + "github.com/cockroachdb/errors" +) + +// SendReport creates a Sentry report about the error, if the settings allow. +// The format string will be reproduced ad litteram in the report; the arguments +// will be sanitized. +func SendReport(ctx context.Context, sv *settings.Values, err error) { + if !logcrash.ShouldSendReport(sv) { + return + } + event, extraDetails := errors.BuildSentryReport(err) + logcrash.SendReport(ctx, logcrash.ReportTypeError, event, extraDetails) +}