Skip to content

Commit

Permalink
errorutil: move SendReport to new sentryutil package
Browse files Browse the repository at this point in the history
The `SendReport` function has been moved out of the errorutil package
and into a new sentryutil package. This avoids muddling the errorutil
package with a Sentry-specific function, and it breaks errorutil's
dependence on `pkg/settings` and `pkg/util/log/logcrash`.

Release note: None
  • Loading branch information
mgartner committed Sep 14, 2023
1 parent 5460e1e commit baf14a0
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 19 deletions.
1 change: 1 addition & 0 deletions pkg/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions pkg/sql/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion pkg/sql/conn_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}

Expand Down
1 change: 1 addition & 0 deletions pkg/sql/opt/norm/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion pkg/sql/opt/norm/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions pkg/sql/stats/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion pkg/sql/stats/forecast.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 0 additions & 2 deletions pkg/util/errorutil/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
)
Expand Down
14 changes: 0 additions & 14 deletions pkg/util/errorutil/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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)
}
13 changes: 13 additions & 0 deletions pkg/util/sentryutil/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -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",
],
)
30 changes: 30 additions & 0 deletions pkg/util/sentryutil/sentry.go
Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit baf14a0

Please sign in to comment.