github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/sql/sqltelemetry/report.go (about) 1 // Copyright 2019 The Cockroach Authors. 2 // 3 // Use of this software is governed by the Business Source License 4 // included in the file licenses/BSL.txt. 5 // 6 // As of the Change Date specified in that file, in accordance with 7 // the Business Source License, use of this software will be governed 8 // by the Apache License, Version 2.0, included in the file 9 // licenses/APL.txt. 10 11 package sqltelemetry 12 13 import ( 14 "context" 15 16 "github.com/cockroachdb/cockroach/pkg/server/telemetry" 17 "github.com/cockroachdb/cockroach/pkg/settings" 18 "github.com/cockroachdb/cockroach/pkg/sql/pgwire/pgcode" 19 "github.com/cockroachdb/cockroach/pkg/sql/pgwire/pgerror" 20 "github.com/cockroachdb/cockroach/pkg/util/log" 21 "github.com/cockroachdb/errors" 22 ) 23 24 // RecordError processes a SQL error. This includes both incrementing 25 // telemetry counters, and sending a sentry report for internal 26 // (assertion) errors. 27 func RecordError(ctx context.Context, err error, sv *settings.Values) { 28 // In any case, record the counters. 29 telemetry.RecordError(err) 30 31 code := pgerror.GetPGCode(err) 32 switch { 33 case code == pgcode.Uncategorized: 34 // For compatibility with 19.1 telemetry, keep track of the number 35 // of occurrences of errors without code in telemetry. Over time, 36 // we'll want this count to go down (i.e. more errors becoming 37 // qualified with a code). 38 // 39 // TODO(knz): figure out if this telemetry is still useful. 40 telemetry.Inc(UncategorizedErrorCounter) 41 42 case code == pgcode.Internal || errors.HasAssertionFailure(err): 43 // This is an assertion failure / crash. 44 // 45 // Note: not all assertion failures end up with code "internal". 46 // For example, an assertion failure "underneath" a schema change 47 // failure during a COMMIT for a multi-stmt txn will mask the 48 // internal code and replace it with 49 // TransactionCommittedWithSchemaChangeFailure. 50 // 51 // Conversely, not all errors with code "internal" are assertion 52 // failures, but we still want to log/register them. 53 54 // We want to log the internal error regardless of whether a 55 // report is sent to sentry below. 56 log.Errorf(ctx, "encountered internal error:\n%+v", err) 57 58 if log.ShouldSendReport(sv) { 59 event, extraDetails := errors.BuildSentryReport(err) 60 log.SendReport(ctx, log.ReportTypeError, event, extraDetails) 61 } 62 } 63 }