(err error)
| 111 | } |
| 112 | |
| 113 | func 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. |
| 133 | func otelErrorType(err error) string { |
searching dependent graphs…