mirror of
https://github.com/hanzoai/telemetry.git
synced 2026-10-30 20:01:49 +00:00
#### Description The last remaining part of #12676 is to implement the `outcome: failure` part of the Pipeline Component Telemetry RFC ([see here](https://github.com/open-telemetry/opentelemetry-collector/blob/main/docs/rfcs/component-universal-telemetry.md#auto-instrumented-metrics)). This is done by introducing a `downstream` error wrapper struct, to distinguish between errors coming from the next component from errors bubbled from further downstream. #### Important note This PR implements things slightly differently from what the text of the RFC describes. If a pipeline contains components `A → B` and an error occurs in B, this PR records: - `otelcol.component.outcome = failure` in the `otelcol.*.consumed.*` metric for B - `otelcol.component.outcome = refused` in the `otelcol.*.produced.*` metric for A whereas the RFC would set both `outcome`s to `failure`. This is programmatically simpler — no need to have different behavior between the `obsconsumer` around the output of A and the one around the input of B — but more importantly, I think it is clearer for users as well: `outcome = failure` only occurs on metrics associated with the component where the failure actually occurred. This subtlety wasn't discussed in-depth in #11956 which introduced `outcome = refused`, so I took the liberty to make this change. If necessary, I can file another RFC amendment to match, or, if there are objections, implement the RFC as-is instead. #### Link to tracking issue Fixes #12676 #### Testing I've updated the existing tests in `obsconsumer` to expect a `downstream`-wrapped error to exit the `obsconsumer` layer. I may add more tests later. #### Documentation None. --------- Co-authored-by: Alex Boten <[email protected]> Co-authored-by: Pablo Baeyens <[email protected]>
45 lines
1.4 KiB
Go
45 lines
1.4 KiB
Go
// Copyright The OpenTelemetry Authors
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package consumererror
|
|
|
|
import (
|
|
"errors"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
//nolint:testifylint // Testing properties of errors, no reason to use require
|
|
func TestDownstream(t *testing.T) {
|
|
err1 := errors.New("test error")
|
|
assert.False(t, IsDownstream(err1))
|
|
err2 := errors.New("test error 2")
|
|
assert.False(t, IsDownstream(err2))
|
|
|
|
errDownstream1 := NewDownstream(err1)
|
|
assert.True(t, IsDownstream(errDownstream1))
|
|
assert.Equal(t, err1.Error(), errDownstream1.Error())
|
|
assert.ErrorIs(t, errDownstream1, err1)
|
|
assert.NotErrorIs(t, errDownstream1, err2)
|
|
|
|
// we can access downstream wrappers through other wrappers
|
|
errWrapDownstream := NewRetryableError(errDownstream1)
|
|
assert.True(t, IsDownstream(errWrapDownstream))
|
|
errorStruct := new(Error)
|
|
assert.ErrorAs(t, errWrapDownstream, &errorStruct)
|
|
|
|
// we can access other wrappers through downstream wrappers
|
|
errDownstreamWrap := NewDownstream(NewRetryableError(err1))
|
|
assert.True(t, IsDownstream(errDownstreamWrap))
|
|
assert.ErrorAs(t, errDownstreamWrap, &errorStruct)
|
|
|
|
// downstream + downstream = downstream
|
|
errJoin2 := errors.Join(errDownstream1, NewDownstream(err2))
|
|
assert.True(t, IsDownstream(errJoin2))
|
|
|
|
// downstream + not downstream = downstream
|
|
errJoin1 := errors.Join(errDownstream1, err2)
|
|
assert.True(t, IsDownstream(errJoin1))
|
|
}
|