| 1 |
// Code generated by gotmpl. DO NOT MODIFY. |
| 2 |
// source: internal/shared/otlp/partialsuccess.go |
| 3 |
|
| 4 |
// Copyright The OpenTelemetry Authors |
| 5 |
// SPDX-License-Identifier: Apache-2.0 |
| 6 |
|
| 7 |
package internal // import "go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp/internal" |
| 8 |
|
| 9 |
import "fmt" |
| 10 |
|
| 11 |
// PartialSuccess represents the underlying error for all handling |
| 12 |
// OTLP partial success messages. Use `errors.Is(err, |
| 13 |
// PartialSuccess{})` to test whether an error passed to the OTel |
| 14 |
// error handler belongs to this category. |
| 15 |
type PartialSuccess struct { |
| 16 |
ErrorMessage string |
| 17 |
RejectedItems int64 |
| 18 |
RejectedKind string |
| 19 |
} |
| 20 |
|
| 21 |
var _ error = PartialSuccess{} |
| 22 |
|
| 23 |
// Error implements the error interface. |
| 24 |
func (ps PartialSuccess) Error() string { |
| 25 |
msg := ps.ErrorMessage |
| 26 |
if msg == "" { |
| 27 |
msg = "empty message" |
| 28 |
} |
| 29 |
return fmt.Sprintf("OTLP partial success: %s (%d %s rejected)", msg, ps.RejectedItems, ps.RejectedKind) |
| 30 |
} |
| 31 |
|
| 32 |
// As returns true if ps can be assigned to target and makes the assignment. |
| 33 |
// Otherwise, it returns false. This supports the errors.As() interface. |
| 34 |
func (ps PartialSuccess) As(target any) bool { |
| 35 |
t, ok := target.(*PartialSuccess) |
| 36 |
if !ok { |
| 37 |
return false |
| 38 |
} |
| 39 |
*t = ps |
| 40 |
return true |
| 41 |
} |
| 42 |
|
| 43 |
// Is supports the errors.Is() interface. |
| 44 |
func (ps PartialSuccess) Is(err error) bool { |
| 45 |
_, ok := err.(PartialSuccess) |
| 46 |
return ok |
| 47 |
} |
| 48 |
|
| 49 |
// TracePartialSuccessError returns an error describing a partial success |
| 50 |
// response for the trace signal. |
| 51 |
func TracePartialSuccessError(itemsRejected int64, errorMessage string) error { |
| 52 |
return PartialSuccess{ |
| 53 |
ErrorMessage: errorMessage, |
| 54 |
RejectedItems: itemsRejected, |
| 55 |
RejectedKind: "spans", |
| 56 |
} |
| 57 |
} |
| 58 |
|
| 59 |
// MetricPartialSuccessError returns an error describing a partial success |
| 60 |
// response for the metric signal. |
| 61 |
func MetricPartialSuccessError(itemsRejected int64, errorMessage string) error { |
| 62 |
return PartialSuccess{ |
| 63 |
ErrorMessage: errorMessage, |
| 64 |
RejectedItems: itemsRejected, |
| 65 |
RejectedKind: "metric data points", |
| 66 |
} |
| 67 |
} |