MCPcopy Index your code
hub / github.com/docker/cli / attributesFromError

Function attributesFromError

cli/command/telemetry_utils.go:113–130  ·  view source on GitHub ↗
(err error)

Source from the content-addressed store, hash-verified

111}
112
113func attributesFromError(err error) []attribute.KeyValue {
114 attrs := []attribute.KeyValue{}
115 exitCode := 0
116 if err != nil {
117 exitCode = 1
118 if stderr, ok := err.(statusError); ok {
119 // StatusError should only be used for errors, and all errors should
120 // have a non-zero exit status, so only set this here if this value isn't 0
121 if stderr.StatusCode != 0 {
122 exitCode = stderr.StatusCode
123 }
124 }
125 attrs = append(attrs, attribute.String("command.error.type", otelErrorType(err)))
126 }
127 attrs = append(attrs, attribute.Int("command.status.code", exitCode))
128
129 return attrs
130}
131
132// otelErrorType returns an attribute for the error type based on the error category.
133func otelErrorType(err error) string {

Callers 2

TestAttributesFromErrorFunction · 0.85
startCobraCommandTimerFunction · 0.85

Calls 2

otelErrorTypeFunction · 0.85
StringMethod · 0.65

Tested by 1

TestAttributesFromErrorFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…