From cff632e27995e67ec1501c361729633a3f003b29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Paj=C4=85k?= Date: Wed, 11 Sep 2024 12:47:51 +0200 Subject: [PATCH 01/10] instrumentation: Add Attributes to Scope and make scope attributes as identifying for Tracer, Meter, Logger --- internal/global/meter.go | 1 + internal/global/trace.go | 8 +++++++- internal/global/trace_test.go | 3 ++- log/internal/global/log.go | 9 ++++++++- log/internal/global/log_test.go | 4 ++++ log/logtest/recorder.go | 10 +++++++--- sdk/instrumentation/scope.go | 4 ++++ sdk/log/provider.go | 7 ++++--- sdk/log/provider_test.go | 2 ++ sdk/metric/provider.go | 8 +++++--- sdk/metric/provider_test.go | 2 ++ sdk/trace/provider.go | 9 +++++---- 12 files changed, 51 insertions(+), 16 deletions(-) diff --git a/internal/global/meter.go b/internal/global/meter.go index f2fc3929b11..3252606f0ec 100644 --- a/internal/global/meter.go +++ b/internal/global/meter.go @@ -66,6 +66,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 { diff --git a/internal/global/trace.go b/internal/global/trace.go index e31f442b48f..ac65262c656 100644 --- a/internal/global/trace.go +++ b/internal/global/trace.go @@ -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 { @@ -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. // diff --git a/internal/global/trace_test.go b/internal/global/trace_test.go index 0eb34e3a3f6..e83f6eec30c 100644 --- a/internal/global/trace_test.go +++ b/internal/global/trace_test.go @@ -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" @@ -209,7 +210,7 @@ func TestTraceProviderDelegatesSameInstance(t *testing.T) { gtp := TracerProvider() tracer := gtp.Tracer("abc", trace.WithInstrumentationVersion("xyz")) assert.Same(t, tracer, gtp.Tracer("abc", trace.WithInstrumentationVersion("xyz"))) - assert.Same(t, tracer, gtp.Tracer("abc", trace.WithInstrumentationVersion("xyz"))) + assert.NotSame(t, tracer, gtp.Tracer("abc", trace.WithInstrumentationVersion("xyz"), trace.WithInstrumentationAttributes(attribute.String("k", "v")))) SetTracerProvider(fnTracerProvider{ tracer: func(name string, opts ...trace.TracerOption) trace.Tracer { diff --git a/log/internal/global/log.go b/log/internal/global/log.go index acd333e8b19..e1bfe6d4871 100644 --- a/log/internal/global/log.go +++ b/log/internal/global/log.go @@ -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 { diff --git a/log/internal/global/log_test.go b/log/internal/global/log_test.go index f465abc9011..e16df5c864a 100644 --- a/log/internal/global/log_test.go +++ b/log/internal/global/log_test.go @@ -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" @@ -126,6 +127,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) diff --git a/log/logtest/recorder.go b/log/logtest/recorder.go index b3d45d647ae..e792556016f 100644 --- a/log/logtest/recorder.go +++ b/log/logtest/recorder.go @@ -7,6 +7,7 @@ import ( "context" "sync" + "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/log" "go.opentelemetry.io/otel/log/embedded" ) @@ -66,6 +67,8 @@ type ScopeRecords struct { Version string // SchemaURL of the telemetry emitted by the scope. SchemaURL string + // Attributes of the telemetry emitted by the scope. + Attributes attribute.Set // Records are the log records, and their associated context this // instrumentation scope recorded. @@ -104,9 +107,10 @@ func (r *Recorder) Logger(name string, opts ...log.LoggerOption) log.Logger { nl := &logger{ scopeRecord: &ScopeRecords{ - Name: name, - Version: cfg.InstrumentationVersion(), - SchemaURL: cfg.SchemaURL(), + Name: name, + Version: cfg.InstrumentationVersion(), + SchemaURL: cfg.SchemaURL(), + Attributes: cfg.InstrumentationAttributes(), }, enabledFn: r.enabledFn, } diff --git a/sdk/instrumentation/scope.go b/sdk/instrumentation/scope.go index 728115045bb..b17dd3ced1f 100644 --- a/sdk/instrumentation/scope.go +++ b/sdk/instrumentation/scope.go @@ -3,6 +3,8 @@ package instrumentation // import "go.opentelemetry.io/otel/sdk/instrumentation" +import "go.opentelemetry.io/otel/attribute" + // Scope represents the instrumentation scope. type Scope struct { // Name is the name of the instrumentation scope. This should be the @@ -12,4 +14,6 @@ type Scope struct { Version string // SchemaURL of the telemetry emitted by the scope. SchemaURL string + // Attributes of the teelemtry emitted by the scope + Attributes attribute.Set } diff --git a/sdk/log/provider.go b/sdk/log/provider.go index 14084ed99a8..8c825e6ab79 100644 --- a/sdk/log/provider.go +++ b/sdk/log/provider.go @@ -124,9 +124,10 @@ func (p *LoggerProvider) Logger(name string, opts ...log.LoggerOption) log.Logge cfg := log.NewLoggerConfig(opts...) scope := instrumentation.Scope{ - Name: name, - Version: cfg.InstrumentationVersion(), - SchemaURL: cfg.SchemaURL(), + Name: name, + Version: cfg.InstrumentationVersion(), + SchemaURL: cfg.SchemaURL(), + Attributes: cfg.InstrumentationAttributes(), } p.loggersMu.Lock() diff --git a/sdk/log/provider_test.go b/sdk/log/provider_test.go index cbe355c236b..cb4d0155507 100644 --- a/sdk/log/provider_test.go +++ b/sdk/log/provider_test.go @@ -302,9 +302,11 @@ func TestLoggerProviderLogger(t *testing.T) { l0, l1 := p.Logger("l0"), p.Logger("l1") l2, l3 := p.Logger("l0"), p.Logger("l1") + l4 := p.Logger("l0", log.WithInstrumentationAttributes(attribute.String("foo", "bar"))) assert.Same(t, l0, l2) assert.Same(t, l1, l3) + assert.NotSame(t, l0, l4) }) } diff --git a/sdk/metric/provider.go b/sdk/metric/provider.go index a82af538e67..1d1bbe7587a 100644 --- a/sdk/metric/provider.go +++ b/sdk/metric/provider.go @@ -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 { diff --git a/sdk/metric/provider_test.go b/sdk/metric/provider_test.go index 138bac57a22..a3c8e6c397e 100644 --- a/sdk/metric/provider_test.go +++ b/sdk/metric/provider_test.go @@ -15,6 +15,7 @@ import ( "github.com/stretchr/testify/require" "go.opentelemetry.io/otel" + "go.opentelemetry.io/otel/attribute" api "go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/metric/noop" "go.opentelemetry.io/otel/sdk/metric/metricdata" @@ -95,6 +96,7 @@ func TestMeterProviderReturnsSameMeter(t *testing.T) { assert.Same(t, mtr, mp.Meter("")) assert.NotSame(t, mtr, mp.Meter("diff")) + assert.NotSame(t, mtr, mp.Meter("", api.WithInstrumentationAttributes(attribute.String("k", "v")))) } func TestEmptyMeterName(t *testing.T) { diff --git a/sdk/trace/provider.go b/sdk/trace/provider.go index 14c2e5bebda..185aa7c08f7 100644 --- a/sdk/trace/provider.go +++ b/sdk/trace/provider.go @@ -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) { @@ -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 } From 9238189471d15cd8a9222959d6eefe9a1dce2e38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Paj=C4=85k?= Date: Wed, 11 Sep 2024 12:51:37 +0200 Subject: [PATCH 02/10] Fix typo --- sdk/instrumentation/scope.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/instrumentation/scope.go b/sdk/instrumentation/scope.go index b17dd3ced1f..e5ed1fe7bc7 100644 --- a/sdk/instrumentation/scope.go +++ b/sdk/instrumentation/scope.go @@ -14,6 +14,6 @@ type Scope struct { Version string // SchemaURL of the telemetry emitted by the scope. SchemaURL string - // Attributes of the teelemtry emitted by the scope + // Attributes of the telemetry emitted by the scope Attributes attribute.Set } From b063b1c0b7155312659b8da970fe96a7a3a9263a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Paj=C4=85k?= Date: Wed, 11 Sep 2024 12:51:53 +0200 Subject: [PATCH 03/10] Add missing dot --- sdk/instrumentation/scope.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/instrumentation/scope.go b/sdk/instrumentation/scope.go index e5ed1fe7bc7..34852a47b21 100644 --- a/sdk/instrumentation/scope.go +++ b/sdk/instrumentation/scope.go @@ -14,6 +14,6 @@ type Scope struct { Version string // SchemaURL of the telemetry emitted by the scope. SchemaURL string - // Attributes of the telemetry emitted by the scope + // Attributes of the telemetry emitted by the scope. Attributes attribute.Set } From dba9c616eecf11b3a2847e8cd052c86621ed44ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Paj=C4=85k?= Date: Wed, 11 Sep 2024 13:15:02 +0200 Subject: [PATCH 04/10] OTLP exporters set InstrumentationScope.Attributes --- exporters/otlp/otlplog/otlploggrpc/internal/transform/log.go | 5 +++-- exporters/otlp/otlplog/otlploghttp/internal/transform/log.go | 5 +++-- .../otlpmetricgrpc/internal/transform/metricdata.go | 5 +++-- .../otlpmetrichttp/internal/transform/metricdata.go | 5 +++-- .../otlptrace/internal/tracetransform/instrumentation.go | 5 +++-- internal/shared/otlp/otlplog/transform/log.go.tmpl | 5 +++-- internal/shared/otlp/otlpmetric/transform/metricdata.go.tmpl | 5 +++-- 7 files changed, 21 insertions(+), 14 deletions(-) diff --git a/exporters/otlp/otlplog/otlploggrpc/internal/transform/log.go b/exporters/otlp/otlplog/otlploggrpc/internal/transform/log.go index 89758f0d073..5fd629f1dfa 100644 --- a/exporters/otlp/otlplog/otlploggrpc/internal/transform/log.go +++ b/exporters/otlp/otlplog/otlploggrpc/internal/transform/log.go @@ -97,8 +97,9 @@ func scopeLogsMap(dst *map[instrumentation.Scope]*lpb.ScopeLogs, records []log.R var emptyScope instrumentation.Scope if scope != emptyScope { sl.Scope = &cpb.InstrumentationScope{ - Name: scope.Name, - Version: scope.Version, + Name: scope.Name, + Version: scope.Version, + Attributes: AttrIter(scope.Attributes.Iter()), } sl.SchemaUrl = scope.SchemaURL } diff --git a/exporters/otlp/otlplog/otlploghttp/internal/transform/log.go b/exporters/otlp/otlplog/otlploghttp/internal/transform/log.go index 54c9c2b4d9e..4b4bc7199ee 100644 --- a/exporters/otlp/otlplog/otlploghttp/internal/transform/log.go +++ b/exporters/otlp/otlplog/otlploghttp/internal/transform/log.go @@ -97,8 +97,9 @@ func scopeLogsMap(dst *map[instrumentation.Scope]*lpb.ScopeLogs, records []log.R var emptyScope instrumentation.Scope if scope != emptyScope { sl.Scope = &cpb.InstrumentationScope{ - Name: scope.Name, - Version: scope.Version, + Name: scope.Name, + Version: scope.Version, + Attributes: AttrIter(scope.Attributes.Iter()), } sl.SchemaUrl = scope.SchemaURL } diff --git a/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/transform/metricdata.go b/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/transform/metricdata.go index 975e3b7aa1a..6226eccefe1 100644 --- a/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/transform/metricdata.go +++ b/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/transform/metricdata.go @@ -46,8 +46,9 @@ func ScopeMetrics(sms []metricdata.ScopeMetrics) ([]*mpb.ScopeMetrics, error) { out = append(out, &mpb.ScopeMetrics{ Scope: &cpb.InstrumentationScope{ - Name: sm.Scope.Name, - Version: sm.Scope.Version, + Name: sm.Scope.Name, + Version: sm.Scope.Version, + Attributes: AttrIter(sm.Scope.Attributes.Iter()), }, Metrics: ms, SchemaUrl: sm.Scope.SchemaURL, diff --git a/exporters/otlp/otlpmetric/otlpmetrichttp/internal/transform/metricdata.go b/exporters/otlp/otlpmetric/otlpmetrichttp/internal/transform/metricdata.go index 0a1a65c44d2..67d6d1695ab 100644 --- a/exporters/otlp/otlpmetric/otlpmetrichttp/internal/transform/metricdata.go +++ b/exporters/otlp/otlpmetric/otlpmetrichttp/internal/transform/metricdata.go @@ -46,8 +46,9 @@ func ScopeMetrics(sms []metricdata.ScopeMetrics) ([]*mpb.ScopeMetrics, error) { out = append(out, &mpb.ScopeMetrics{ Scope: &cpb.InstrumentationScope{ - Name: sm.Scope.Name, - Version: sm.Scope.Version, + Name: sm.Scope.Name, + Version: sm.Scope.Version, + Attributes: AttrIter(sm.Scope.Attributes.Iter()), }, Metrics: ms, SchemaUrl: sm.Scope.SchemaURL, diff --git a/exporters/otlp/otlptrace/internal/tracetransform/instrumentation.go b/exporters/otlp/otlptrace/internal/tracetransform/instrumentation.go index f6dd3decc90..2e7690e43a2 100644 --- a/exporters/otlp/otlptrace/internal/tracetransform/instrumentation.go +++ b/exporters/otlp/otlptrace/internal/tracetransform/instrumentation.go @@ -13,7 +13,8 @@ func InstrumentationScope(il instrumentation.Scope) *commonpb.InstrumentationSco return nil } return &commonpb.InstrumentationScope{ - Name: il.Name, - Version: il.Version, + Name: il.Name, + Version: il.Version, + Attributes: Iterator(il.Attributes.Iter()), } } diff --git a/internal/shared/otlp/otlplog/transform/log.go.tmpl b/internal/shared/otlp/otlplog/transform/log.go.tmpl index 54c9c2b4d9e..4b4bc7199ee 100644 --- a/internal/shared/otlp/otlplog/transform/log.go.tmpl +++ b/internal/shared/otlp/otlplog/transform/log.go.tmpl @@ -97,8 +97,9 @@ func scopeLogsMap(dst *map[instrumentation.Scope]*lpb.ScopeLogs, records []log.R var emptyScope instrumentation.Scope if scope != emptyScope { sl.Scope = &cpb.InstrumentationScope{ - Name: scope.Name, - Version: scope.Version, + Name: scope.Name, + Version: scope.Version, + Attributes: AttrIter(scope.Attributes.Iter()), } sl.SchemaUrl = scope.SchemaURL } diff --git a/internal/shared/otlp/otlpmetric/transform/metricdata.go.tmpl b/internal/shared/otlp/otlpmetric/transform/metricdata.go.tmpl index 1e1edc4f872..8d6bdd42e67 100644 --- a/internal/shared/otlp/otlpmetric/transform/metricdata.go.tmpl +++ b/internal/shared/otlp/otlpmetric/transform/metricdata.go.tmpl @@ -46,8 +46,9 @@ func ScopeMetrics(sms []metricdata.ScopeMetrics) ([]*mpb.ScopeMetrics, error) { out = append(out, &mpb.ScopeMetrics{ Scope: &cpb.InstrumentationScope{ - Name: sm.Scope.Name, - Version: sm.Scope.Version, + Name: sm.Scope.Name, + Version: sm.Scope.Version, + Attributes: AttrIter(sm.Scope.Attributes.Iter()), }, Metrics: ms, SchemaUrl: sm.Scope.SchemaURL, From 437cce146b3213d263bfe5f95607f906ff2aa9b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Paj=C4=85k?= Date: Wed, 11 Sep 2024 13:15:25 +0200 Subject: [PATCH 05/10] Update stdoutlog tests --- exporters/stdout/stdoutlog/exporter_test.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/exporters/stdout/stdoutlog/exporter_test.go b/exporters/stdout/stdoutlog/exporter_test.go index 368a663a687..99fd480727f 100644 --- a/exporters/stdout/stdoutlog/exporter_test.go +++ b/exporters/stdout/stdoutlog/exporter_test.go @@ -183,7 +183,7 @@ func getJSON(now *time.Time) string { timestamps = "\"Timestamp\":" + string(serializedNow) + ",\"ObservedTimestamp\":" + string(serializedNow) + "," } - return "{" + timestamps + "\"Severity\":9,\"SeverityText\":\"INFO\",\"Body\":{\"Type\":\"String\",\"Value\":\"test\"},\"Attributes\":[{\"Key\":\"key\",\"Value\":{\"Type\":\"String\",\"Value\":\"value\"}},{\"Key\":\"key2\",\"Value\":{\"Type\":\"String\",\"Value\":\"value\"}},{\"Key\":\"key3\",\"Value\":{\"Type\":\"String\",\"Value\":\"value\"}},{\"Key\":\"key4\",\"Value\":{\"Type\":\"String\",\"Value\":\"value\"}},{\"Key\":\"key5\",\"Value\":{\"Type\":\"String\",\"Value\":\"value\"}},{\"Key\":\"bool\",\"Value\":{\"Type\":\"Bool\",\"Value\":true}}],\"TraceID\":\"0102030405060708090a0b0c0d0e0f10\",\"SpanID\":\"0102030405060708\",\"TraceFlags\":\"01\",\"Resource\":[{\"Key\":\"foo\",\"Value\":{\"Type\":\"STRING\",\"Value\":\"bar\"}}],\"Scope\":{\"Name\":\"name\",\"Version\":\"version\",\"SchemaURL\":\"https://example.com/custom-schema\"},\"DroppedAttributes\":10}\n" + return "{" + timestamps + "\"Severity\":9,\"SeverityText\":\"INFO\",\"Body\":{\"Type\":\"String\",\"Value\":\"test\"},\"Attributes\":[{\"Key\":\"key\",\"Value\":{\"Type\":\"String\",\"Value\":\"value\"}},{\"Key\":\"key2\",\"Value\":{\"Type\":\"String\",\"Value\":\"value\"}},{\"Key\":\"key3\",\"Value\":{\"Type\":\"String\",\"Value\":\"value\"}},{\"Key\":\"key4\",\"Value\":{\"Type\":\"String\",\"Value\":\"value\"}},{\"Key\":\"key5\",\"Value\":{\"Type\":\"String\",\"Value\":\"value\"}},{\"Key\":\"bool\",\"Value\":{\"Type\":\"Bool\",\"Value\":true}}],\"TraceID\":\"0102030405060708090a0b0c0d0e0f10\",\"SpanID\":\"0102030405060708\",\"TraceFlags\":\"01\",\"Resource\":[{\"Key\":\"foo\",\"Value\":{\"Type\":\"STRING\",\"Value\":\"bar\"}}],\"Scope\":{\"Name\":\"name\",\"Version\":\"version\",\"SchemaURL\":\"https://example.com/custom-schema\",\"Attributes\":{}},\"DroppedAttributes\":10}\n" } func getJSONs(now *time.Time) string { @@ -263,7 +263,8 @@ func getPrettyJSON(now *time.Time) string { "Scope": { "Name": "name", "Version": "version", - "SchemaURL": "https://example.com/custom-schema" + "SchemaURL": "https://example.com/custom-schema", + "Attributes": {} }, "DroppedAttributes": 10 } From 54f80920e0eb28dae7570d3333f170074177f3d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Paj=C4=85k?= Date: Wed, 11 Sep 2024 13:17:56 +0200 Subject: [PATCH 06/10] Update stdoutmetric test --- exporters/stdout/stdoutmetric/example_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/exporters/stdout/stdoutmetric/example_test.go b/exporters/stdout/stdoutmetric/example_test.go index b2a4ebbd74d..1df2df38ef4 100644 --- a/exporters/stdout/stdoutmetric/example_test.go +++ b/exporters/stdout/stdoutmetric/example_test.go @@ -184,7 +184,8 @@ func Example() { // "Scope": { // "Name": "example", // "Version": "0.0.1", - // "SchemaURL": "" + // "SchemaURL": "", + // "Attributes": null // }, // "Metrics": [ // { From 182ea85b1303dd75a6495bea95709edd364b42d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Paj=C4=85k?= Date: Wed, 11 Sep 2024 13:20:14 +0200 Subject: [PATCH 07/10] Update stdouttrace test --- exporters/stdout/stdouttrace/trace_test.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/exporters/stdout/stdouttrace/trace_test.go b/exporters/stdout/stdouttrace/trace_test.go index d598ca4cd85..6b1fd0cecbe 100644 --- a/exporters/stdout/stdouttrace/trace_test.go +++ b/exporters/stdout/stdouttrace/trace_test.go @@ -189,12 +189,14 @@ func expectedJSON(now time.Time) string { "InstrumentationScope": { "Name": "", "Version": "", - "SchemaURL": "" + "SchemaURL": "", + "Attributes": null }, "InstrumentationLibrary": { "Name": "", "Version": "", - "SchemaURL": "" + "SchemaURL": "", + "Attributes": null } } ` From 7b2bb8c0f6e4ac76042e9e353d7afe7a67ec1768 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Paj=C4=85k?= Date: Wed, 11 Sep 2024 13:32:17 +0200 Subject: [PATCH 08/10] Fix sdk/trace tests --- sdk/trace/trace_test.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/sdk/trace/trace_test.go b/sdk/trace/trace_test.go index 87247d1f167..3de95d53e38 100644 --- a/sdk/trace/trace_test.go +++ b/sdk/trace/trace_test.go @@ -900,7 +900,11 @@ func cmpDiff(x, y interface{}) string { cmp.AllowUnexported(snapshot{}), cmp.AllowUnexported(attribute.Value{}), cmp.AllowUnexported(Event{}), - cmp.AllowUnexported(trace.TraceState{})) + cmp.AllowUnexported(trace.TraceState{}), + cmp.Comparer(func(x, y attribute.Set) bool { + return x.Equals(&y) + }), + ) } // checkChild is test utility function that tests that c has fields set appropriately, From 07bfb33cf69a10e3a3e174a98c6073f7369f9543 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Paj=C4=85k?= Date: Wed, 11 Sep 2024 14:15:03 +0200 Subject: [PATCH 09/10] Update SameLoggers test --- sdk/log/provider_test.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sdk/log/provider_test.go b/sdk/log/provider_test.go index cb4d0155507..8e80ef090f2 100644 --- a/sdk/log/provider_test.go +++ b/sdk/log/provider_test.go @@ -302,10 +302,12 @@ func TestLoggerProviderLogger(t *testing.T) { l0, l1 := p.Logger("l0"), p.Logger("l1") l2, l3 := p.Logger("l0"), p.Logger("l1") - l4 := p.Logger("l0", log.WithInstrumentationAttributes(attribute.String("foo", "bar"))) + l4, l5 := p.Logger("l0", log.WithInstrumentationAttributes(attribute.String("foo", "bar"))), p.Logger("l0", log.WithInstrumentationAttributes(attribute.String("foo", "bar"))) assert.Same(t, l0, l2) assert.Same(t, l1, l3) + assert.Same(t, l4, l5) + assert.NotSame(t, l0, l1) assert.NotSame(t, l0, l4) }) } From 7710a1f27ad205860fc1234b3ddb0b036d6ebd73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Paj=C4=85k?= Date: Wed, 11 Sep 2024 14:18:21 +0200 Subject: [PATCH 10/10] Update same loggers --- sdk/log/provider_test.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/sdk/log/provider_test.go b/sdk/log/provider_test.go index 8e80ef090f2..0b2c7f786c8 100644 --- a/sdk/log/provider_test.go +++ b/sdk/log/provider_test.go @@ -300,15 +300,15 @@ func TestLoggerProviderLogger(t *testing.T) { t.Run("SameLoggers", func(t *testing.T) { p := NewLoggerProvider() - l0, l1 := p.Logger("l0"), p.Logger("l1") - l2, l3 := p.Logger("l0"), p.Logger("l1") - l4, l5 := p.Logger("l0", log.WithInstrumentationAttributes(attribute.String("foo", "bar"))), p.Logger("l0", log.WithInstrumentationAttributes(attribute.String("foo", "bar"))) - - assert.Same(t, l0, l2) - assert.Same(t, l1, l3) - assert.Same(t, l4, l5) + 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, l4) + assert.NotSame(t, l0, l2) + assert.NotSame(t, l1, l2) + + l3, l4, l5 := p.Logger("l0"), p.Logger("l1"), p.Logger("l0", log.WithInstrumentationAttributes(attribute.String("foo", "bar"))) + assert.Same(t, l0, l3) + assert.Same(t, l1, l4) + assert.Same(t, l2, l5) }) }