Skip to content

Commit

Permalink
Merge branch 'main' into log-scope-attr
Browse files Browse the repository at this point in the history
  • Loading branch information
pellared authored Oct 30, 2024
2 parents 4921d87 + ee56fb9 commit d7764dd
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 28 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- `go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc` now keeps the metadata already present in the context when `WithHeaders` is used. (#5892)
- `go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc` now keeps the metadata already present in the context when `WithHeaders` is used. (#5911)
- `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 `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 -->
Expand Down
1 change: 1 addition & 0 deletions internal/global/meter.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ func (p *meterProvider) Meter(name string, opts ...metric.MeterOption) metric.Me
name: name,
version: c.InstrumentationVersion(),
schema: c.SchemaURL(),
attrs: c.InstrumentationAttributes(),
}

if p.meters == nil {
Expand Down
21 changes: 12 additions & 9 deletions internal/global/meter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/metric/noop"
)
Expand Down Expand Up @@ -397,17 +398,18 @@ func TestRegistrationDelegation(t *testing.T) {
}

func TestMeterIdentity(t *testing.T) {
type id struct{ name, ver, url string }
type id struct{ name, ver, url, attr string }

ids := []id{
{"name-a", "version-a", "url-a"},
{"name-a", "version-a", "url-b"},
{"name-a", "version-b", "url-a"},
{"name-a", "version-b", "url-b"},
{"name-b", "version-a", "url-a"},
{"name-b", "version-a", "url-b"},
{"name-b", "version-b", "url-a"},
{"name-b", "version-b", "url-b"},
{"name-a", "version-a", "url-a", ""},
{"name-a", "version-a", "url-a", "attr"},
{"name-a", "version-a", "url-b", ""},
{"name-a", "version-b", "url-a", ""},
{"name-a", "version-b", "url-b", ""},
{"name-b", "version-a", "url-a", ""},
{"name-b", "version-a", "url-b", ""},
{"name-b", "version-b", "url-a", ""},
{"name-b", "version-b", "url-b", ""},
}

provider := &meterProvider{}
Expand All @@ -416,6 +418,7 @@ func TestMeterIdentity(t *testing.T) {
i.name,
metric.WithInstrumentationVersion(i.ver),
metric.WithSchemaURL(i.url),
metric.WithInstrumentationAttributes(attribute.String("key", i.attr)),
)
}

Expand Down
8 changes: 7 additions & 1 deletion internal/global/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ func (p *tracerProvider) Tracer(name string, opts ...trace.TracerOption) trace.T
name: name,
version: c.InstrumentationVersion(),
schema: c.SchemaURL(),
attrs: c.InstrumentationAttributes(),
}

if p.tracers == nil {
Expand All @@ -102,7 +103,12 @@ func (p *tracerProvider) Tracer(name string, opts ...trace.TracerOption) trace.T
return t
}

type il struct{ name, version, schema string }
type il struct {
name string
version string
schema string
attrs attribute.Set
}

// tracer is a placeholder for a trace.Tracer.
//
Expand Down
21 changes: 12 additions & 9 deletions internal/global/trace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/stretchr/testify/assert"

"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/trace"
"go.opentelemetry.io/otel/trace/embedded"
"go.opentelemetry.io/otel/trace/noop"
Expand Down Expand Up @@ -237,17 +238,18 @@ func TestSpanContextPropagatedWithNonRecordingSpan(t *testing.T) {
}

func TestTracerIdentity(t *testing.T) {
type id struct{ name, ver, url string }
type id struct{ name, ver, url, attr string }

ids := []id{
{"name-a", "version-a", "url-a"},
{"name-a", "version-a", "url-b"},
{"name-a", "version-b", "url-a"},
{"name-a", "version-b", "url-b"},
{"name-b", "version-a", "url-a"},
{"name-b", "version-a", "url-b"},
{"name-b", "version-b", "url-a"},
{"name-b", "version-b", "url-b"},
{"name-a", "version-a", "url-a", ""},
{"name-a", "version-a", "url-a", "attr"},
{"name-a", "version-a", "url-b", ""},
{"name-a", "version-b", "url-a", ""},
{"name-a", "version-b", "url-b", ""},
{"name-b", "version-a", "url-a", ""},
{"name-b", "version-a", "url-b", ""},
{"name-b", "version-b", "url-a", ""},
{"name-b", "version-b", "url-b", ""},
}

provider := &tracerProvider{}
Expand All @@ -256,6 +258,7 @@ func TestTracerIdentity(t *testing.T) {
i.name,
trace.WithInstrumentationVersion(i.ver),
trace.WithSchemaURL(i.url),
trace.WithInstrumentationAttributes(attribute.String("key", i.attr)),
)
}

Expand Down
8 changes: 5 additions & 3 deletions sdk/metric/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,17 @@ func (mp *MeterProvider) Meter(name string, options ...metric.MeterOption) metri

c := metric.NewMeterConfig(options...)
s := instrumentation.Scope{
Name: name,
Version: c.InstrumentationVersion(),
SchemaURL: c.SchemaURL(),
Name: name,
Version: c.InstrumentationVersion(),
SchemaURL: c.SchemaURL(),
Attributes: c.InstrumentationAttributes(),
}

global.Info("Meter created",
"Name", s.Name,
"Version", s.Version,
"SchemaURL", s.SchemaURL,
"Attributes", s.Attributes,
)

return mp.meters.Lookup(s, func() *meter {
Expand Down
2 changes: 1 addition & 1 deletion sdk/metric/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func TestMeterProviderReturnsSameMeter(t *testing.T) {

assert.Same(t, mtr, mp.Meter(""))
assert.NotSame(t, mtr, mp.Meter("diff"))
assert.Same(t, mtr, mp.Meter("", api.WithInstrumentationAttributes(attribute.String("k", "v")))) // TODO (#3368): Change to assert.NotSame.
assert.NotSame(t, mtr, mp.Meter("", api.WithInstrumentationAttributes(attribute.String("k", "v"))))
}

func TestEmptyMeterName(t *testing.T) {
Expand Down
9 changes: 5 additions & 4 deletions sdk/trace/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,10 @@ func (p *TracerProvider) Tracer(name string, opts ...trace.TracerOption) trace.T
name = defaultTracerName
}
is := instrumentation.Scope{
Name: name,
Version: c.InstrumentationVersion(),
SchemaURL: c.SchemaURL(),
Name: name,
Version: c.InstrumentationVersion(),
SchemaURL: c.SchemaURL(),
Attributes: c.InstrumentationAttributes(),
}

t, ok := func() (trace.Tracer, bool) {
Expand All @@ -168,7 +169,7 @@ func (p *TracerProvider) Tracer(name string, opts ...trace.TracerOption) trace.T
// slowing down all tracing consumers.
// - Logging code may be instrumented with tracing and deadlock because it could try
// acquiring the same non-reentrant mutex.
global.Info("Tracer created", "name", name, "version", is.Version, "schemaURL", is.SchemaURL)
global.Info("Tracer created", "name", name, "version", is.Version, "schemaURL", is.SchemaURL, "attributes", is.Attributes)
}
return t
}
Expand Down
2 changes: 1 addition & 1 deletion sdk/trace/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ func TestTracerProviderReturnsSameTracer(t *testing.T) {

t0, t1, t2 := p.Tracer("t0"), p.Tracer("t1"), p.Tracer("t0", trace.WithInstrumentationAttributes(attribute.String("foo", "bar")))
assert.NotSame(t, t0, t1)
assert.Same(t, t0, t2) // TODO (#3368): Change to assert.NotSame.
assert.NotSame(t, t0, t2)
assert.NotSame(t, t1, t2)

t3, t4, t5 := p.Tracer("t0"), p.Tracer("t1"), p.Tracer("t0", trace.WithInstrumentationAttributes(attribute.String("foo", "bar")))
Expand Down

0 comments on commit d7764dd

Please sign in to comment.