| 1 |
// Copyright The OpenTelemetry Authors |
| 2 |
// SPDX-License-Identifier: Apache-2.0 |
| 3 |
|
| 4 |
package internal // import "go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc/internal" |
| 5 |
|
| 6 |
import "fmt" |
| 7 |
|
| 8 |
// PartialSuccess represents the underlying error for all handling |
| 9 |
// OTLP partial success messages. Use `errors.Is(err, |
| 10 |
// PartialSuccess{})` to test whether an error passed to the OTel |
| 11 |
// error handler belongs to this category. |
| 12 |
type PartialSuccess struct { |
| 13 |
ErrorMessage string |
| 14 |
RejectedItems int64 |
| 15 |
RejectedKind string |
| 16 |
} |
| 17 |
|
| 18 |
var _ error = PartialSuccess{} |
| 19 |
|
| 20 |
// Error implements the error interface. |
| 21 |
func (ps PartialSuccess) Error() string { |
| 22 |
msg := ps.ErrorMessage |
| 23 |
if msg == "" { |
| 24 |
msg = "empty message" |
| 25 |
} |
| 26 |
return fmt.Sprintf("OTLP partial success: %s (%d %s rejected)", msg, ps.RejectedItems, ps.RejectedKind) |
| 27 |
} |
| 28 |
|
| 29 |
// Is supports the errors.Is() interface. |
| 30 |
func (PartialSuccess) Is(err error) bool { |
| 31 |
_, ok := err.(PartialSuccess) |
| 32 |
return ok |
| 33 |
} |
| 34 |
|
| 35 |
// LogPartialSuccessError returns an error describing a partial success |
| 36 |
// response for the log signal. |
| 37 |
func LogPartialSuccessError(itemsRejected int64, errorMessage string) error { |
| 38 |
return PartialSuccess{ |
| 39 |
ErrorMessage: errorMessage, |
| 40 |
RejectedItems: itemsRejected, |
| 41 |
RejectedKind: "logs", |
| 42 |
} |
| 43 |
} |