You've already forked opentelemetry-go
mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2026-06-03 18:35:08 +02:00
768e930779
a part of #7020 ```txt goos: windows goarch: amd64 pkg: go.opentelemetry.io/otel/exporters/stdout/stdoutlog/internal/observ cpu: Intel(R) Core(TM) i7-14700 │ result.txt │ │ sec/op │ InstrumentationExportLogs/NoError-28 47.68n ± 5% InstrumentationExportLogs/PartialError-28 471.6n ± 2% InstrumentationExportLogs/FullError-28 471.9n ± 10% geomean 219.7n │ result.txt │ │ B/op │ InstrumentationExportLogs/NoError-28 0.000 ± 0% InstrumentationExportLogs/PartialError-28 305.0 ± 0% InstrumentationExportLogs/FullError-28 305.0 ± 0% geomean ¹ ¹ summaries must be >0 to compute geomean │ result.txt │ │ allocs/op │ InstrumentationExportLogs/NoError-28 0.000 ± 0% InstrumentationExportLogs/PartialError-28 4.000 ± 0% InstrumentationExportLogs/FullError-28 4.000 ± 0% geomean ¹ ¹ summaries must be >0 to compute geomean ``` --------- Co-authored-by: Damien Mathieu <42@dmathieu.com>
43 lines
1.2 KiB
Go
43 lines
1.2 KiB
Go
// Copyright The OpenTelemetry Authors
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package internal // import "go.opentelemetry.io/otel/exporters/stdout/stdoutlog/internal"
|
|
|
|
import "fmt"
|
|
|
|
// PartialSuccess represents the underlying error for all handling
|
|
// stdoutlog partial success messages. Use `errors.Is(err, PartialSuccess{})`
|
|
// to test whether an error passed to the stdoutlog error handler belongs to this category.
|
|
type PartialSuccess struct {
|
|
ErrorMessage string
|
|
RejectedItems int64
|
|
RejectedKind string
|
|
}
|
|
|
|
var _ error = PartialSuccess{}
|
|
|
|
// Error implements the error interface.
|
|
func (ps PartialSuccess) Error() string {
|
|
msg := ps.ErrorMessage
|
|
if msg == "" {
|
|
msg = "empty message"
|
|
}
|
|
return fmt.Sprintf("stdoutlog partial success: %s (%d %s failed)", msg, ps.RejectedItems, ps.RejectedKind)
|
|
}
|
|
|
|
// Is supports the errors.Is() interface.
|
|
func (PartialSuccess) Is(err error) bool {
|
|
_, ok := err.(PartialSuccess)
|
|
return ok
|
|
}
|
|
|
|
// LogPartialSuccessError returns an error describing a partial success
|
|
// response for the log signal.
|
|
func LogPartialSuccessError(itemsRejected int64, errorMessage string) error {
|
|
return PartialSuccess{
|
|
ErrorMessage: errorMessage,
|
|
RejectedItems: itemsRejected,
|
|
RejectedKind: "logs",
|
|
}
|
|
}
|