mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2025-01-30 04:40:41 +02:00
Format log message before logging with logr (#4143)
* Format log message before logging with logr Fixes #4141 The logr calling convention does not support fmt semantics for message formatting. Format the message before it is sent to logr for logging. * Add change to changelog * Fix lint Don't shadow the log pkg. * Replace buflogr with funcr * Run make * Update exporters/zipkin/zipkin_test.go Co-authored-by: Robert Pająk <pellared@hotmail.com> --------- Co-authored-by: Robert Pająk <pellared@hotmail.com>
This commit is contained in:
parent
5e69812435
commit
1b02c9122d
@ -22,6 +22,10 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
|
||||
- `NewPeriodicReader` in `go.opentelemetry.io/otel/sdk/metric` returns `*PeriodicReader` instead of `Reader`. (#4244)
|
||||
- Count the Collect time in the PeriodicReader timeout. (#4221)
|
||||
|
||||
### Fixed
|
||||
|
||||
- Correctly format log messages from the `go.opentelemetry.io/otel/exporters/zipkin` exporter. (#4143)
|
||||
|
||||
## [1.16.0/0.39.0] 2023-05-18
|
||||
|
||||
This release contains the first stable release of the OpenTelemetry Go [metric API].
|
||||
|
@ -181,7 +181,7 @@ func (e *Exporter) Shutdown(ctx context.Context) error {
|
||||
|
||||
func (e *Exporter) logf(format string, args ...interface{}) {
|
||||
if e.logger != emptyLogger {
|
||||
e.logger.Info(format, args)
|
||||
e.logger.Info(fmt.Sprintf(format, args...))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -15,6 +15,7 @@
|
||||
package zipkin
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
@ -28,6 +29,7 @@ import (
|
||||
|
||||
ottest "go.opentelemetry.io/otel/internal/internaltest"
|
||||
|
||||
"github.com/go-logr/logr/funcr"
|
||||
zkmodel "github.com/openzipkin/zipkin-go/model"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
@ -364,3 +366,21 @@ func TestErrorOnExportShutdownExporter(t *testing.T) {
|
||||
assert.NoError(t, exp.Shutdown(context.Background()))
|
||||
assert.NoError(t, exp.ExportSpans(context.Background(), nil))
|
||||
}
|
||||
|
||||
func TestLogrFormatting(t *testing.T) {
|
||||
format := "string %q, int %d"
|
||||
args := []interface{}{"s", 1}
|
||||
|
||||
var buf bytes.Buffer
|
||||
l := funcr.New(func(prefix, args string) {
|
||||
_, _ = buf.WriteString(fmt.Sprint(prefix, args))
|
||||
}, funcr.Options{})
|
||||
exp, err := New("", WithLogr(l))
|
||||
require.NoError(t, err)
|
||||
|
||||
exp.logf(format, args...)
|
||||
|
||||
want := "\"level\"=0 \"msg\"=\"string \\\"s\\\", int 1\""
|
||||
got := buf.String()
|
||||
assert.Equal(t, want, got)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user