@@ -44,11 +44,9 @@ func NewCBOR[T CBORMarshalUnmarshaler]() *CBOR[T] {
44
44
45
45
func (c * CBOR [T ]) Encode (m T ) (_ []byte , _err error ) {
46
46
defer func (start time.Time ) {
47
- if _err != nil {
48
- metrics .encodingTime .Record (context .Background (),
49
- time .Since (start ).Seconds (),
50
- metric .WithAttributeSet (attrSetCborEncode ))
51
- }
47
+ metrics .encodingTime .Record (context .Background (),
48
+ time .Since (start ).Seconds (),
49
+ metric .WithAttributes (attrCodecCbor , attrActionEncode , attrSuccessFromErr (_err )))
52
50
}(time .Now ())
53
51
var out bytes.Buffer
54
52
if err := m .MarshalCBOR (& out ); err != nil {
@@ -59,11 +57,9 @@ func (c *CBOR[T]) Encode(m T) (_ []byte, _err error) {
59
57
60
58
func (c * CBOR [T ]) Decode (v []byte , t T ) (_err error ) {
61
59
defer func (start time.Time ) {
62
- if _err != nil {
63
- metrics .encodingTime .Record (context .Background (),
64
- time .Since (start ).Seconds (),
65
- metric .WithAttributeSet (attrSetCborDecode ))
66
- }
60
+ metrics .encodingTime .Record (context .Background (),
61
+ time .Since (start ).Seconds (),
62
+ metric .WithAttributes (attrCodecCbor , attrActionDecode , attrSuccessFromErr (_err )))
67
63
}(time .Now ())
68
64
r := bytes .NewReader (v )
69
65
return t .UnmarshalCBOR (r )
@@ -100,7 +96,7 @@ func (c *ZSTD[T]) Encode(t T) (_ []byte, _err error) {
100
96
defer func (start time.Time ) {
101
97
metrics .encodingTime .Record (context .Background (),
102
98
time .Since (start ).Seconds (),
103
- metric .WithAttributeSet ( attrSetZstdEncode ))
99
+ metric .WithAttributes ( attrCodecZstd , attrActionEncode , attrSuccessFromErr ( _err ) ))
104
100
}(time .Now ())
105
101
decompressed , err := c .cborEncoding .Encode (t )
106
102
if len (decompressed ) > maxDecompressedSize {
@@ -117,11 +113,9 @@ func (c *ZSTD[T]) Encode(t T) (_ []byte, _err error) {
117
113
118
114
func (c * ZSTD [T ]) Decode (compressed []byte , t T ) (_err error ) {
119
115
defer func (start time.Time ) {
120
- if _err != nil {
121
- metrics .encodingTime .Record (context .Background (),
122
- time .Since (start ).Seconds (),
123
- metric .WithAttributeSet (attrSetZstdDecode ))
124
- }
116
+ metrics .encodingTime .Record (context .Background (),
117
+ time .Since (start ).Seconds (),
118
+ metric .WithAttributes (attrCodecZstd , attrActionDecode , attrSuccessFromErr (_err )))
125
119
}(time .Now ())
126
120
buf := bufferPool .Get ().(* []byte )
127
121
defer bufferPool .Put (buf )
0 commit comments