From c8b3f05f905be15f69bea97ea7afa1eda245229a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Paj=C4=85k?= Date: Tue, 5 Dec 2023 17:33:58 +0100 Subject: [PATCH] Encapsulate Record fields --- log/DESIGN.md | 14 ++++++ log/benchmark/bench_test.go | 25 ++++++++--- log/benchmark/logr_test.go | 7 ++- log/benchmark/slog_test.go | 9 +++- log/benchmark/writer_logger_test.go | 13 +++--- log/record.go | 69 +++++++++++++++++++++++------ 6 files changed, 109 insertions(+), 28 deletions(-) diff --git a/log/DESIGN.md b/log/DESIGN.md index 25f8d93a702..0ec2073dea9 100644 --- a/log/DESIGN.md +++ b/log/DESIGN.md @@ -228,6 +228,20 @@ if it will occur that it could be helpful in some scenarios. However, without a strong reason, we prefer to hide the implementation detail and have smaller API surface. +### Rejected Alternative: Record with exported fields + +There was a proposal that the timestamp, +observed timestamp, severity number, severity text, +body properties of the [Emit](https://opentelemetry.io/docs/specs/otel/logs/bridge-api/#emit-a-logrecord) +are exposed as exported fields of `Record` type. +This was inspired by [`slog.Record`](https://pkg.go.dev/log/slog#Record) +design. + +We find that exposing all properties via methods is be more consistent. +Having access to attributes via methods +and access to other properities via fields +could be more confusing for the users. + ## Open issues (if applicable)