1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2026-06-03 18:35:08 +02:00
Files
opentelemetry-go/internal/shared/otlp/partialsuccess.go.tmpl
T
Tyler Yahn 14d6372a05 Add the internal/observ package to otlptracegrpc (#7404)
- Part of #7007 
- Contains a TODO tracking features added in #7401 
- This package will be used to instrument `otlptracegrpc` in a follow-up
PR

### Benchmarks

```terminal
goos: linux
goarch: amd64
pkg: go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/internal/observ
cpu: Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz
                                          │ otlptracegrpc-internal-observ.bmark.result │
                                          │                   sec/op                   │
InstrumentationExportSpans/NoError-8                                      143.8n ±  4%
InstrumentationExportSpans/PartialError-8                                 1.747µ ±  6%
InstrumentationExportSpans/FullError-8                                    1.737µ ± 11%
geomean                                                                   758.4n

                                          │ otlptracegrpc-internal-observ.bmark.result │
                                          │                    B/op                    │
InstrumentationExportSpans/NoError-8                                      0.000 ± 0%
InstrumentationExportSpans/PartialError-8                                 753.0 ± 0%
InstrumentationExportSpans/FullError-8                                    753.0 ± 0%
geomean                                                                              ¹
¹ summaries must be >0 to compute geomean

                                          │ otlptracegrpc-internal-observ.bmark.result │
                                          │                 allocs/op                  │
InstrumentationExportSpans/NoError-8                                      0.000 ± 0%
InstrumentationExportSpans/PartialError-8                                 4.000 ± 0%
InstrumentationExportSpans/FullError-8                                    4.000 ± 0%
geomean                                                                              ¹
¹ summaries must be >0 to compute geomean
```

---------

Co-authored-by: Robert Pająk <pellared@hotmail.com>
2025-10-06 11:08:29 -07:00

68 lines
1.8 KiB
Cheetah

// Code generated by gotmpl. DO NOT MODIFY.
// source: internal/shared/otlp/partialsuccess.go
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package internal
import "fmt"
// PartialSuccess represents the underlying error for all handling
// OTLP partial success messages. Use `errors.Is(err,
// PartialSuccess{})` to test whether an error passed to the OTel
// 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("OTLP partial success: %s (%d %s rejected)", msg, ps.RejectedItems, ps.RejectedKind)
}
// As returns true if ps can be assigned to target and makes the assignment.
// Otherwise, it returns false. This supports the errors.As() interface.
func (ps PartialSuccess) As(target any) bool {
t, ok := target.(*PartialSuccess)
if !ok {
return false
}
*t = ps
return true
}
// Is supports the errors.Is() interface.
func (ps PartialSuccess) Is(err error) bool {
_, ok := err.(PartialSuccess)
return ok
}
// TracePartialSuccessError returns an error describing a partial success
// response for the trace signal.
func TracePartialSuccessError(itemsRejected int64, errorMessage string) error {
return PartialSuccess{
ErrorMessage: errorMessage,
RejectedItems: itemsRejected,
RejectedKind: "spans",
}
}
// MetricPartialSuccessError returns an error describing a partial success
// response for the metric signal.
func MetricPartialSuccessError(itemsRejected int64, errorMessage string) error {
return PartialSuccess{
ErrorMessage: errorMessage,
RejectedItems: itemsRejected,
RejectedKind: "metric data points",
}
}