You've already forked opentelemetry-go
mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2025-11-25 22:41:46 +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:
@@ -31,6 +31,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
|
|||||||
- `go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc` now keeps the metadata already present in the context when `WithHeaders` is used. (#5915)
|
- `go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc` now keeps the metadata already present in the context when `WithHeaders` is used. (#5915)
|
||||||
- Support scope attributes and make them as identifying for `Tracer` in `go.opentelemetry.io/otel` and `go.opentelemetry.io/otel/sdk/trace`. (#5924)
|
- Support scope attributes and make them as identifying for `Tracer` in `go.opentelemetry.io/otel` and `go.opentelemetry.io/otel/sdk/trace`. (#5924)
|
||||||
- Support scope attributes and make them as identifying for `Meter` in `go.opentelemetry.io/otel` and `go.opentelemetry.io/otel/sdk/metric`. (#5926)
|
- Support scope attributes and make them as identifying for `Meter` in `go.opentelemetry.io/otel` and `go.opentelemetry.io/otel/sdk/metric`. (#5926)
|
||||||
|
- Support scope attributes and make them as identifying for `Logger` in `go.opentelemetry.io/otel` and `go.opentelemetry.io/otel/sdk/log`. (#5925)
|
||||||
|
|
||||||
<!-- Released section -->
|
<!-- Released section -->
|
||||||
<!-- Don't change this section unless doing release -->
|
<!-- Don't change this section unless doing release -->
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
|
|
||||||
|
"go.opentelemetry.io/otel/attribute"
|
||||||
"go.opentelemetry.io/otel/log"
|
"go.opentelemetry.io/otel/log"
|
||||||
"go.opentelemetry.io/otel/log/embedded"
|
"go.opentelemetry.io/otel/log/embedded"
|
||||||
)
|
)
|
||||||
@@ -15,7 +16,12 @@ import (
|
|||||||
// instLib defines the instrumentation library a logger is created for.
|
// instLib defines the instrumentation library a logger is created for.
|
||||||
//
|
//
|
||||||
// Do not use sdk/instrumentation (API cannot depend on the SDK).
|
// 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 {
|
type loggerProvider struct {
|
||||||
embedded.LoggerProvider
|
embedded.LoggerProvider
|
||||||
@@ -41,6 +47,7 @@ func (p *loggerProvider) Logger(name string, options ...log.LoggerOption) log.Lo
|
|||||||
name: name,
|
name: name,
|
||||||
version: cfg.InstrumentationVersion(),
|
version: cfg.InstrumentationVersion(),
|
||||||
schemaURL: cfg.SchemaURL(),
|
schemaURL: cfg.SchemaURL(),
|
||||||
|
attrs: cfg.InstrumentationAttributes(),
|
||||||
}
|
}
|
||||||
|
|
||||||
if p.loggers == nil {
|
if p.loggers == nil {
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import (
|
|||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
|
"go.opentelemetry.io/otel/attribute"
|
||||||
"go.opentelemetry.io/otel/log"
|
"go.opentelemetry.io/otel/log"
|
||||||
"go.opentelemetry.io/otel/log/embedded"
|
"go.opentelemetry.io/otel/log/embedded"
|
||||||
"go.opentelemetry.io/otel/log/noop"
|
"go.opentelemetry.io/otel/log/noop"
|
||||||
@@ -128,6 +129,9 @@ func TestDelegation(t *testing.T) {
|
|||||||
alt := provider.Logger("alt")
|
alt := provider.Logger("alt")
|
||||||
assert.NotSame(t, pre0, alt)
|
assert.NotSame(t, pre0, alt)
|
||||||
|
|
||||||
|
alt2 := provider.Logger(preName, log.WithInstrumentationAttributes(attribute.String("k", "v")))
|
||||||
|
assert.NotSame(t, pre0, alt2)
|
||||||
|
|
||||||
delegate := &testLoggerProvider{}
|
delegate := &testLoggerProvider{}
|
||||||
provider.setDelegate(delegate)
|
provider.setDelegate(delegate)
|
||||||
|
|
||||||
|
|||||||
@@ -124,9 +124,10 @@ func (p *LoggerProvider) Logger(name string, opts ...log.LoggerOption) log.Logge
|
|||||||
|
|
||||||
cfg := log.NewLoggerConfig(opts...)
|
cfg := log.NewLoggerConfig(opts...)
|
||||||
scope := instrumentation.Scope{
|
scope := instrumentation.Scope{
|
||||||
Name: name,
|
Name: name,
|
||||||
Version: cfg.InstrumentationVersion(),
|
Version: cfg.InstrumentationVersion(),
|
||||||
SchemaURL: cfg.SchemaURL(),
|
SchemaURL: cfg.SchemaURL(),
|
||||||
|
Attributes: cfg.InstrumentationAttributes(),
|
||||||
}
|
}
|
||||||
|
|
||||||
p.loggersMu.Lock()
|
p.loggersMu.Lock()
|
||||||
|
|||||||
@@ -302,7 +302,7 @@ func TestLoggerProviderLogger(t *testing.T) {
|
|||||||
|
|
||||||
l0, l1, l2 := p.Logger("l0"), p.Logger("l1"), p.Logger("l0", log.WithInstrumentationAttributes(attribute.String("foo", "bar")))
|
l0, l1, l2 := p.Logger("l0"), p.Logger("l1"), p.Logger("l0", log.WithInstrumentationAttributes(attribute.String("foo", "bar")))
|
||||||
assert.NotSame(t, l0, l1)
|
assert.NotSame(t, l0, l1)
|
||||||
assert.Same(t, l0, l2) // TODO (#3368): Change to assert.NotSame.
|
assert.NotSame(t, l0, l2)
|
||||||
assert.NotSame(t, l1, l2)
|
assert.NotSame(t, l1, l2)
|
||||||
|
|
||||||
l3, l4, l5 := p.Logger("l0"), p.Logger("l1"), p.Logger("l0", log.WithInstrumentationAttributes(attribute.String("foo", "bar")))
|
l3, l4, l5 := p.Logger("l0"), p.Logger("l1"), p.Logger("l0", log.WithInstrumentationAttributes(attribute.String("foo", "bar")))
|
||||||
|
|||||||
Reference in New Issue
Block a user