Debian Codegraph @

exporters/otlp/otlplog/otlploghttp/internal/partialsuccess.go

raw
1 // Copyright The OpenTelemetry Authors
2 // SPDX-License-Identifier: Apache-2.0
3
4 package internal // import "go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp/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 func LogPartialSuccessError(itemsRejected int64, errorMessage string) error {
37 return PartialSuccess{
38 ErrorMessage: errorMessage,
39 RejectedItems: itemsRejected,
40 RejectedKind: "logs",
41 }
42 }