1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2026-06-03 18:35:08 +02:00

sdk/log/observ: guard LogProcessed with Enabled (#7848)

Guards SLP.LogProcessed with processed.Enabled(ctx) to avoid building
metric
options/attributes when the processed counter is disabled.

BenchmarkSLP (noop MeterProvider):

LogProcessedWithError: ~106 ns/op, 232 B/op, 3 allocs/op -> ~0.46 ns/op,
0 B/op, 0 allocs/op
No behavior change when enabled; existing tests cover enabled path.
I don't believe this is a "notable" change, so doesn't need a CHANGELOG
entry.
Issue: #7800

Co-authored-by: Robert Pająk <pellared@hotmail.com>
Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
This commit is contained in:
Nesterov Yehor
2026-02-03 22:43:20 +01:00
committed by GitHub
parent 4401cf2d6e
commit e0ad47f3fe
@@ -104,7 +104,9 @@ func NewSLP(id int64) (*SLP, error) {
// LogProcessed records that a log has been processed by the SimpleLogProcessor.
// If err is non-nil, it records the processing error as an attribute.
func (slp *SLP) LogProcessed(ctx context.Context, err error) {
slp.processed.Add(ctx, 1, slp.addOption(err)...)
if slp.processed.Enabled(ctx) {
slp.processed.Add(ctx, 1, slp.addOption(err)...)
}
}
func (slp *SLP) addOption(err error) []metric.AddOption {