You've already forked opentelemetry-go
mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2026-06-03 18:35:08 +02:00
Make scope attributes as identifying for Logger (#5925)
Towards https://github.com/open-telemetry/opentelemetry-go/issues/3368
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/log"
|
||||
"go.opentelemetry.io/otel/log/embedded"
|
||||
)
|
||||
@@ -15,7 +16,12 @@ import (
|
||||
// instLib defines the instrumentation library a logger is created for.
|
||||
//
|
||||
// Do not use sdk/instrumentation (API cannot depend on the SDK).
|
||||
type instLib struct{ name, version, schemaURL string }
|
||||
type instLib struct {
|
||||
name string
|
||||
version string
|
||||
schemaURL string
|
||||
attrs attribute.Set
|
||||
}
|
||||
|
||||
type loggerProvider struct {
|
||||
embedded.LoggerProvider
|
||||
@@ -41,6 +47,7 @@ func (p *loggerProvider) Logger(name string, options ...log.LoggerOption) log.Lo
|
||||
name: name,
|
||||
version: cfg.InstrumentationVersion(),
|
||||
schemaURL: cfg.SchemaURL(),
|
||||
attrs: cfg.InstrumentationAttributes(),
|
||||
}
|
||||
|
||||
if p.loggers == nil {
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/log"
|
||||
"go.opentelemetry.io/otel/log/embedded"
|
||||
"go.opentelemetry.io/otel/log/noop"
|
||||
@@ -128,6 +129,9 @@ func TestDelegation(t *testing.T) {
|
||||
alt := provider.Logger("alt")
|
||||
assert.NotSame(t, pre0, alt)
|
||||
|
||||
alt2 := provider.Logger(preName, log.WithInstrumentationAttributes(attribute.String("k", "v")))
|
||||
assert.NotSame(t, pre0, alt2)
|
||||
|
||||
delegate := &testLoggerProvider{}
|
||||
provider.setDelegate(delegate)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user