Skip to content

Commit

Permalink
design: log value accessors must not panic (#4948)
Browse files Browse the repository at this point in the history
  • Loading branch information
pellared authored Feb 21, 2024
1 parent dd3b00f commit c2fdbca
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions log/DESIGN.md
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,18 @@ and the API is mostly inspired by
The benchmarks[^1] show that the implementation is more performant than
[`attribute.Value`](https://pkg.go.dev/go.opentelemetry.io/otel/attribute#Value).

The value accessors (`func (v Value) As[Kind]` methods) must not panic,
as it would violate the [specification](https://opentelemetry.io/docs/specs/otel/error-handling/):

> API methods MUST NOT throw unhandled exceptions when used incorrectly by end
> users. The API and SDK SHOULD provide safe defaults for missing or invalid
> arguments. [...] Whenever the library suppresses an error that would otherwise
> have been exposed to the user, the library SHOULD log the error using
> language-specific conventions.

Therefore, the value accessors should return a zero value
and log an error when a bad accessor is called.

The `Severity`, `Kind`, `Value`, `KeyValue` may implement
the [`fmt.Stringer`](https://pkg.go.dev/fmt#Stringer) interface.
However, it is not needed for the first stable release
Expand Down

0 comments on commit c2fdbca

Please sign in to comment.