From 690c2cb5ebad1bbd4ce780b70211fd80bbad46f9 Mon Sep 17 00:00:00 2001 From: Craig Pastro Date: Fri, 24 Jun 2022 16:33:11 -0700 Subject: [PATCH 1/9] Deprecate Library and move all uses to Scope --- CHANGELOG.md | 6 ++++ bridge/opencensus/exporter.go | 4 +-- bridge/opencensus/exporter_test.go | 2 +- exporters/jaeger/jaeger_benchmark_test.go | 2 +- exporters/jaeger/jaeger_test.go | 8 +++--- exporters/otlp/otlpmetric/exporter_test.go | 6 ++-- .../internal/metrictransform/metric.go | 2 +- .../internal/otlpmetrictest/data.go | 4 +-- .../otlptrace/internal/otlptracetest/data.go | 2 +- .../tracetransform/instrumentation.go | 4 +-- .../otlptrace/internal/tracetransform/span.go | 2 +- .../internal/tracetransform/span_test.go | 2 +- exporters/prometheus/prometheus.go | 4 +-- exporters/stdout/stdoutmetric/metric.go | 2 +- exporters/zipkin/model_test.go | 6 ++-- sdk/instrumentation/library.go | 1 + sdk/metric/controller/basic/controller.go | 6 ++-- .../controller/basic/controller_test.go | 2 +- sdk/metric/controller/controllertest/test.go | 4 +-- sdk/metric/export/metric.go | 2 +- sdk/metric/metrictest/exporter.go | 13 +++++---- sdk/metric/processor/basic/basic_test.go | 2 +- sdk/metric/processor/processortest/test.go | 16 +++++------ .../processor/processortest/test_test.go | 2 +- sdk/metric/processor/reducer/reducer_test.go | 2 +- sdk/trace/provider.go | 6 ++-- sdk/trace/snapshot.go | 4 +-- sdk/trace/span.go | 6 ++-- sdk/trace/trace_test.go | 28 +++++++++---------- sdk/trace/tracer.go | 2 +- sdk/trace/tracetest/span.go | 6 ++-- 31 files changed, 84 insertions(+), 74 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b502a1fb6b4..4792ddfc22d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,12 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm - Support for go1.16. Support is now only for go1.17 and go1.18 (#2917) +### Deprecated + +- The `Library` struct in the `go.opentelemetry.io/otel/sdk/instrumentation` package is deprecated. + Use the equivalent `Scope` struct instead. + + ## [1.7.0/0.30.0] - 2022-04-28 ### Added diff --git a/bridge/opencensus/exporter.go b/bridge/opencensus/exporter.go index 7e7e7960007..84aa499a60f 100644 --- a/bridge/opencensus/exporter.go +++ b/bridge/opencensus/exporter.go @@ -64,8 +64,8 @@ type censusLibraryReader struct { metrics []*metricdata.Metric } -func (r censusLibraryReader) ForEach(readerFunc func(instrumentation.Library, export.Reader) error) error { - return readerFunc(instrumentation.Library{ +func (r censusLibraryReader) ForEach(readerFunc func(instrumentation.Scope, export.Reader) error) error { + return readerFunc(instrumentation.Scope{ Name: "OpenCensus Bridge", }, &metricReader{metrics: r.metrics}) } diff --git a/bridge/opencensus/exporter_test.go b/bridge/opencensus/exporter_test.go index 2634f5334d5..c1ea8c95400 100644 --- a/bridge/opencensus/exporter_test.go +++ b/bridge/opencensus/exporter_test.go @@ -47,7 +47,7 @@ type fakeExporter struct { func (f *fakeExporter) Export(ctx context.Context, res *resource.Resource, ilr export.InstrumentationLibraryReader) error { return controllertest.ReadAll(ilr, aggregation.StatelessTemporalitySelector(), - func(_ instrumentation.Library, record export.Record) error { + func(_ instrumentation.Scope, record export.Record) error { f.resource = res f.records = append(f.records, record) return f.err diff --git a/exporters/jaeger/jaeger_benchmark_test.go b/exporters/jaeger/jaeger_benchmark_test.go index ab96ac8c9ed..2b0e54c90d6 100644 --- a/exporters/jaeger/jaeger_benchmark_test.go +++ b/exporters/jaeger/jaeger_benchmark_test.go @@ -61,7 +61,7 @@ func spans(n int) []tracesdk.ReadOnlySpan { StartTime: now, EndTime: now, SpanKind: trace.SpanKindClient, - InstrumentationLibrary: instrumentation.Library{ + InstrumentationLibrary: instrumentation.Scope{ Name: instrLibName, }, } diff --git a/exporters/jaeger/jaeger_test.go b/exporters/jaeger/jaeger_test.go index 67133ab2c9d..c748293ee9b 100644 --- a/exporters/jaeger/jaeger_test.go +++ b/exporters/jaeger/jaeger_test.go @@ -187,7 +187,7 @@ func TestSpanSnapshotToThrift(t *testing.T) { EndTime: now, Status: sdktrace.Status{Code: codes.Error}, SpanKind: trace.SpanKindClient, - InstrumentationLibrary: instrumentation.Library{ + InstrumentationLibrary: instrumentation.Scope{ Name: instrLibName, Version: instrLibVersion, }, @@ -245,7 +245,7 @@ func TestSpanSnapshotToThrift(t *testing.T) { Description: statusMessage, }, SpanKind: trace.SpanKindClient, - InstrumentationLibrary: instrumentation.Library{ + InstrumentationLibrary: instrumentation.Scope{ Name: instrLibName, Version: instrLibVersion, }, @@ -330,7 +330,7 @@ func TestSpanSnapshotToThrift(t *testing.T) { Description: statusMessage, }, SpanKind: trace.SpanKindInternal, - InstrumentationLibrary: instrumentation.Library{ + InstrumentationLibrary: instrumentation.Scope{ Name: instrLibName, Version: instrLibVersion, }, @@ -383,7 +383,7 @@ func TestSpanSnapshotToThrift(t *testing.T) { Description: statusMessage, }, SpanKind: trace.SpanKindInternal, - InstrumentationLibrary: instrumentation.Library{ + InstrumentationLibrary: instrumentation.Scope{ Name: instrLibName, Version: instrLibVersion, }, diff --git a/exporters/otlp/otlpmetric/exporter_test.go b/exporters/otlp/otlpmetric/exporter_test.go index d5208fc26d6..f4fe7774e9a 100644 --- a/exporters/otlp/otlpmetric/exporter_test.go +++ b/exporters/otlp/otlpmetric/exporter_test.go @@ -728,7 +728,7 @@ func TestStatelessAggregationTemporality(t *testing.T) { func runMetricExportTests(t *testing.T, opts []otlpmetric.Option, res *resource.Resource, records []testRecord, expected []*metricpb.ResourceMetrics) { exp, driver := newExporter(t, opts...) - libraryRecs := map[instrumentation.Library][]export.Record{} + libraryRecs := map[instrumentation.Scope][]export.Record{} for _, r := range records { lcopy := make([]attribute.KeyValue, len(r.attrs)) copy(lcopy, r.attrs) @@ -771,7 +771,7 @@ func runMetricExportTests(t *testing.T, opts []otlpmetric.Option, res *resource. require.NoError(t, agg.SynchronizedMove(ckpt, &desc)) meterCfg := metric.NewMeterConfig(r.meterOpts...) - lib := instrumentation.Library{ + lib := instrumentation.Scope{ Name: r.meterName, Version: meterCfg.InstrumentationVersion(), SchemaURL: meterCfg.SchemaURL(), @@ -838,7 +838,7 @@ func TestEmptyMetricExport(t *testing.T) { }, } { driver.Reset() - require.NoError(t, exp.Export(context.Background(), resource.Empty(), processortest.MultiInstrumentationLibraryReader(map[instrumentation.Library][]export.Record{ + require.NoError(t, exp.Export(context.Background(), resource.Empty(), processortest.MultiInstrumentationLibraryReader(map[instrumentation.Scope][]export.Record{ { Name: testLibName, }: test.records, diff --git a/exporters/otlp/otlpmetric/internal/metrictransform/metric.go b/exporters/otlp/otlpmetric/internal/metrictransform/metric.go index 2d7c9049905..a189b85bdad 100644 --- a/exporters/otlp/otlpmetric/internal/metrictransform/metric.go +++ b/exporters/otlp/otlpmetric/internal/metrictransform/metric.go @@ -74,7 +74,7 @@ func toNanos(t time.Time) uint64 { func InstrumentationLibraryReader(ctx context.Context, temporalitySelector aggregation.TemporalitySelector, res *resource.Resource, ilmr export.InstrumentationLibraryReader, numWorkers uint) (*metricpb.ResourceMetrics, error) { var sms []*metricpb.ScopeMetrics - err := ilmr.ForEach(func(lib instrumentation.Library, mr export.Reader) error { + err := ilmr.ForEach(func(lib instrumentation.Scope, mr export.Reader) error { records, errc := source(ctx, temporalitySelector, mr) // Start a fixed number of goroutines to transform records. diff --git a/exporters/otlp/otlpmetric/internal/otlpmetrictest/data.go b/exporters/otlp/otlpmetric/internal/otlpmetrictest/data.go index d8d9c03a31e..825a31d9189 100644 --- a/exporters/otlp/otlpmetric/internal/otlpmetrictest/data.go +++ b/exporters/otlp/otlpmetric/internal/otlpmetrictest/data.go @@ -48,7 +48,7 @@ func OneRecordReader() export.InstrumentationLibraryReader { rec := export.NewRecord(&desc, &attrs, agg[0].Aggregation(), start, end) return processortest.MultiInstrumentationLibraryReader( - map[instrumentation.Library][]export.Record{ + map[instrumentation.Scope][]export.Record{ { Name: "onelib", }: {rec}, @@ -66,6 +66,6 @@ type FailReader struct{} var _ export.InstrumentationLibraryReader = FailReader{} // ForEach implements export.Reader. It always fails. -func (FailReader) ForEach(readerFunc func(instrumentation.Library, export.Reader) error) error { +func (FailReader) ForEach(readerFunc func(instrumentation.Scope, export.Reader) error) error { return fmt.Errorf("fail") } diff --git a/exporters/otlp/otlptrace/internal/otlptracetest/data.go b/exporters/otlp/otlptrace/internal/otlptracetest/data.go index d039105cb29..4e51f317c84 100644 --- a/exporters/otlp/otlptrace/internal/otlptracetest/data.go +++ b/exporters/otlp/otlptrace/internal/otlptracetest/data.go @@ -54,7 +54,7 @@ func SingleReadOnlySpan() []tracesdk.ReadOnlySpan { DroppedLinks: 0, ChildSpanCount: 0, Resource: resource.NewSchemaless(attribute.String("a", "b")), - InstrumentationLibrary: instrumentation.Library{ + InstrumentationLibrary: instrumentation.Scope{ Name: "bar", Version: "0.0.0", }, diff --git a/exporters/otlp/otlptrace/internal/tracetransform/instrumentation.go b/exporters/otlp/otlptrace/internal/tracetransform/instrumentation.go index 213f9f92a4e..7aaec38d22a 100644 --- a/exporters/otlp/otlptrace/internal/tracetransform/instrumentation.go +++ b/exporters/otlp/otlptrace/internal/tracetransform/instrumentation.go @@ -19,8 +19,8 @@ import ( commonpb "go.opentelemetry.io/proto/otlp/common/v1" ) -func InstrumentationScope(il instrumentation.Library) *commonpb.InstrumentationScope { - if il == (instrumentation.Library{}) { +func InstrumentationScope(il instrumentation.Scope) *commonpb.InstrumentationScope { + if il == (instrumentation.Scope{}) { return nil } return &commonpb.InstrumentationScope{ diff --git a/exporters/otlp/otlptrace/internal/tracetransform/span.go b/exporters/otlp/otlptrace/internal/tracetransform/span.go index 0e8d00a0494..da6eac95f2c 100644 --- a/exporters/otlp/otlptrace/internal/tracetransform/span.go +++ b/exporters/otlp/otlptrace/internal/tracetransform/span.go @@ -34,7 +34,7 @@ func Spans(sdl []tracesdk.ReadOnlySpan) []*tracepb.ResourceSpans { type key struct { r attribute.Distinct - il instrumentation.Library + il instrumentation.Scope } ssm := make(map[key]*tracepb.ScopeSpans) diff --git a/exporters/otlp/otlptrace/internal/tracetransform/span_test.go b/exporters/otlp/otlptrace/internal/tracetransform/span_test.go index 3bb203eae80..20c23d49458 100644 --- a/exporters/otlp/otlptrace/internal/tracetransform/span_test.go +++ b/exporters/otlp/otlptrace/internal/tracetransform/span_test.go @@ -264,7 +264,7 @@ func TestSpanData(t *testing.T) { attribute.Int64("rk2", 5), attribute.StringSlice("rk3", []string{"sv1", "sv2"}), ), - InstrumentationLibrary: instrumentation.Library{ + InstrumentationLibrary: instrumentation.Scope{ Name: "go.opentelemetry.io/test/otel", Version: "v0.0.1", SchemaURL: semconv.SchemaURL, diff --git a/exporters/prometheus/prometheus.go b/exporters/prometheus/prometheus.go index fb544d004fb..c7aa16d1257 100644 --- a/exporters/prometheus/prometheus.go +++ b/exporters/prometheus/prometheus.go @@ -151,7 +151,7 @@ func (c *collector) Describe(ch chan<- *prometheus.Desc) { c.exp.lock.RLock() defer c.exp.lock.RUnlock() - _ = c.exp.Controller().ForEach(func(_ instrumentation.Library, reader export.Reader) error { + _ = c.exp.Controller().ForEach(func(_ instrumentation.Scope, reader export.Reader) error { return reader.ForEach(c.exp, func(record export.Record) error { var attrKeys []string mergeAttrs(record, c.exp.controller.Resource(), &attrKeys, nil) @@ -174,7 +174,7 @@ func (c *collector) Collect(ch chan<- prometheus.Metric) { otel.Handle(err) } - err := ctrl.ForEach(func(_ instrumentation.Library, reader export.Reader) error { + err := ctrl.ForEach(func(_ instrumentation.Scope, reader export.Reader) error { return reader.ForEach(c.exp, func(record export.Record) error { agg := record.Aggregation() numberKind := record.Descriptor().NumberKind() diff --git a/exporters/stdout/stdoutmetric/metric.go b/exporters/stdout/stdoutmetric/metric.go index 38289d281a7..0bdee8e9093 100644 --- a/exporters/stdout/stdoutmetric/metric.go +++ b/exporters/stdout/stdoutmetric/metric.go @@ -52,7 +52,7 @@ func (e *metricExporter) TemporalityFor(desc *sdkapi.Descriptor, kind aggregatio func (e *metricExporter) Export(_ context.Context, res *resource.Resource, reader export.InstrumentationLibraryReader) error { var aggError error var batch []line - aggError = reader.ForEach(func(lib instrumentation.Library, mr export.Reader) error { + aggError = reader.ForEach(func(lib instrumentation.Scope, mr export.Reader) error { var instAttrs []attribute.KeyValue if name := lib.Name; name != "" { instAttrs = append(instAttrs, attribute.String("instrumentation.name", name)) diff --git a/exporters/zipkin/model_test.go b/exporters/zipkin/model_test.go index f8869988e7a..9ada99ca3f1 100644 --- a/exporters/zipkin/model_test.go +++ b/exporters/zipkin/model_test.go @@ -829,7 +829,7 @@ func TestTagsTransformation(t *testing.T) { { name: "instrLib-empty", data: tracetest.SpanStub{ - InstrumentationLibrary: instrumentation.Library{}, + InstrumentationLibrary: instrumentation.Scope{}, }, want: nil, }, @@ -837,7 +837,7 @@ func TestTagsTransformation(t *testing.T) { name: "instrLib-noversion", data: tracetest.SpanStub{ Attributes: []attribute.KeyValue{}, - InstrumentationLibrary: instrumentation.Library{ + InstrumentationLibrary: instrumentation.Scope{ Name: instrLibName, }, }, @@ -849,7 +849,7 @@ func TestTagsTransformation(t *testing.T) { name: "instrLib-with-version", data: tracetest.SpanStub{ Attributes: []attribute.KeyValue{}, - InstrumentationLibrary: instrumentation.Library{ + InstrumentationLibrary: instrumentation.Scope{ Name: instrLibName, Version: instrLibVersion, }, diff --git a/sdk/instrumentation/library.go b/sdk/instrumentation/library.go index ec6451849bf..246873345de 100644 --- a/sdk/instrumentation/library.go +++ b/sdk/instrumentation/library.go @@ -22,4 +22,5 @@ For more information see package instrumentation // import "go.opentelemetry.io/otel/sdk/instrumentation" // Library represents the instrumentation library. +// Deprecated: please use Scope instead. type Library = Scope diff --git a/sdk/metric/controller/basic/controller.go b/sdk/metric/controller/basic/controller.go index a46e3835e3b..51c0da6e481 100644 --- a/sdk/metric/controller/basic/controller.go +++ b/sdk/metric/controller/basic/controller.go @@ -85,7 +85,7 @@ var _ metric.MeterProvider = &Controller{} // with opts. func (c *Controller) Meter(instrumentationName string, opts ...metric.MeterOption) metric.Meter { cfg := metric.NewMeterConfig(opts...) - library := instrumentation.Library{ + library := instrumentation.Scope{ Name: instrumentationName, Version: cfg.InstrumentationVersion(), SchemaURL: cfg.SchemaURL(), @@ -108,7 +108,7 @@ func (c *Controller) Meter(instrumentationName string, opts ...metric.MeterOptio type accumulatorCheckpointer struct { *sdk.Accumulator checkpointer export.Checkpointer - library instrumentation.Library + library instrumentation.Scope } var _ sdkapi.MeterImpl = &accumulatorCheckpointer{} @@ -323,7 +323,7 @@ func (c *Controller) export(ctx context.Context) error { // nolint:revive // me } // ForEach implements export.InstrumentationLibraryReader. -func (c *Controller) ForEach(readerFunc func(l instrumentation.Library, r export.Reader) error) error { +func (c *Controller) ForEach(readerFunc func(l instrumentation.Scope, r export.Reader) error) error { for _, acPair := range c.accumulatorList() { reader := acPair.checkpointer.Reader() // TODO: We should not fail fast; instead accumulate errors. diff --git a/sdk/metric/controller/basic/controller_test.go b/sdk/metric/controller/basic/controller_test.go index 26dcf4bb286..74904d68c49 100644 --- a/sdk/metric/controller/basic/controller_test.go +++ b/sdk/metric/controller/basic/controller_test.go @@ -43,7 +43,7 @@ func getMap(t *testing.T, cont *controller.Controller) map[string]float64 { out := processortest.NewOutput(attribute.DefaultEncoder()) require.NoError(t, cont.ForEach( - func(_ instrumentation.Library, reader export.Reader) error { + func(_ instrumentation.Scope, reader export.Reader) error { return reader.ForEach( aggregation.CumulativeTemporalitySelector(), func(record export.Record) error { diff --git a/sdk/metric/controller/controllertest/test.go b/sdk/metric/controller/controllertest/test.go index 9c1a3421972..045159f39c2 100644 --- a/sdk/metric/controller/controllertest/test.go +++ b/sdk/metric/controller/controllertest/test.go @@ -75,9 +75,9 @@ func (t MockTicker) C() <-chan time.Time { func ReadAll( reader export.InstrumentationLibraryReader, kind aggregation.TemporalitySelector, - apply func(instrumentation.Library, export.Record) error, + apply func(instrumentation.Scope, export.Record) error, ) error { - return reader.ForEach(func(library instrumentation.Library, reader export.Reader) error { + return reader.ForEach(func(library instrumentation.Scope, reader export.Reader) error { return reader.ForEach(kind, func(record export.Record) error { return apply(library, record) }) diff --git a/sdk/metric/export/metric.go b/sdk/metric/export/metric.go index 6168ca445ba..e2cf1bf57af 100644 --- a/sdk/metric/export/metric.go +++ b/sdk/metric/export/metric.go @@ -155,7 +155,7 @@ type InstrumentationLibraryReader interface { // ForEach calls the passed function once per instrumentation library, // allowing the caller to emit metrics grouped by the library that // produced them. - ForEach(readerFunc func(instrumentation.Library, Reader) error) error + ForEach(readerFunc func(instrumentation.Scope, Reader) error) error } // Reader allows a controller to access a complete checkpoint of diff --git a/sdk/metric/metrictest/exporter.go b/sdk/metric/metrictest/exporter.go index e767702019a..79d862eff80 100644 --- a/sdk/metric/metrictest/exporter.go +++ b/sdk/metric/metrictest/exporter.go @@ -64,9 +64,12 @@ func NewTestMeterProvider(opts ...Option) (metric.MeterProvider, *Exporter) { return c, exp } -// Library is the same as "sdk/instrumentation".Library but there is +// Deprecated: please use Scope instead. +type Library = Scope + +// Scope is the same as "sdk/instrumentation".Scope but there is // a package cycle to use it so it is redeclared here. -type Library struct { +type Scope struct { InstrumentationName string InstrumentationVersion string SchemaURL string @@ -75,7 +78,7 @@ type Library struct { // ExportRecord represents one collected datapoint from the Exporter. type ExportRecord struct { InstrumentName string - InstrumentationLibrary Library + InstrumentationLibrary Scope Attributes []attribute.KeyValue AggregationKind aggregation.Kind NumberKind number.Kind @@ -95,8 +98,8 @@ func (e *Exporter) Collect(ctx context.Context) error { return err } - return e.controller.ForEach(func(l instrumentation.Library, r export.Reader) error { - lib := Library{ + return e.controller.ForEach(func(l instrumentation.Scope, r export.Reader) error { + lib := Scope{ InstrumentationName: l.Name, InstrumentationVersion: l.Version, SchemaURL: l.SchemaURL, diff --git a/sdk/metric/processor/basic/basic_test.go b/sdk/metric/processor/basic/basic_test.go index 21d816b44a0..43d06109c25 100644 --- a/sdk/metric/processor/basic/basic_test.go +++ b/sdk/metric/processor/basic/basic_test.go @@ -471,7 +471,7 @@ func TestCounterObserverEndToEnd(t *testing.T) { exporter := processortest.New(eselector, attribute.DefaultEncoder()) require.NoError(t, exporter.Export(ctx, resource.Empty(), processortest.OneInstrumentationLibraryReader( - instrumentation.Library{ + instrumentation.Scope{ Name: "test", }, reader))) diff --git a/sdk/metric/processor/processortest/test.go b/sdk/metric/processor/processortest/test.go index fa0e902d255..521904cd7cc 100644 --- a/sdk/metric/processor/processortest/test.go +++ b/sdk/metric/processor/processortest/test.go @@ -243,7 +243,7 @@ func (o *Output) AddRecord(rec export.Record) error { } // AddRecordWithResource merges rec into this Output. -func (o *Output) AddInstrumentationLibraryRecord(_ instrumentation.Library, rec export.Record) error { +func (o *Output) AddInstrumentationLibraryRecord(_ instrumentation.Scope, rec export.Record) error { return o.AddRecordWithResource(rec, resource.Empty()) } @@ -340,7 +340,7 @@ func (e *Exporter) Export(_ context.Context, res *resource.Resource, ckpt export e.output.Lock() defer e.output.Unlock() e.exportCount++ - return ckpt.ForEach(func(library instrumentation.Library, mr export.Reader) error { + return ckpt.ForEach(func(library instrumentation.Scope, mr export.Reader) error { return mr.ForEach(e.TemporalitySelector, func(r export.Record) error { if e.InjectErr != nil { if err := e.InjectErr(r); err != nil { @@ -381,32 +381,32 @@ func (e *Exporter) Reset() { // OneInstrumentationLibraryReader returns an InstrumentationLibraryReader for // a single instrumentation library. -func OneInstrumentationLibraryReader(l instrumentation.Library, r export.Reader) export.InstrumentationLibraryReader { +func OneInstrumentationLibraryReader(l instrumentation.Scope, r export.Reader) export.InstrumentationLibraryReader { return oneLibraryReader{l, r} } type oneLibraryReader struct { - library instrumentation.Library + library instrumentation.Scope reader export.Reader } -func (o oneLibraryReader) ForEach(readerFunc func(instrumentation.Library, export.Reader) error) error { +func (o oneLibraryReader) ForEach(readerFunc func(instrumentation.Scope, export.Reader) error) error { return readerFunc(o.library, o.reader) } // MultiInstrumentationLibraryReader returns an InstrumentationLibraryReader // for a group of records that came from multiple instrumentation libraries. -func MultiInstrumentationLibraryReader(records map[instrumentation.Library][]export.Record) export.InstrumentationLibraryReader { +func MultiInstrumentationLibraryReader(records map[instrumentation.Scope][]export.Record) export.InstrumentationLibraryReader { return instrumentationLibraryReader{records: records} } type instrumentationLibraryReader struct { - records map[instrumentation.Library][]export.Record + records map[instrumentation.Scope][]export.Record } var _ export.InstrumentationLibraryReader = instrumentationLibraryReader{} -func (m instrumentationLibraryReader) ForEach(fn func(instrumentation.Library, export.Reader) error) error { +func (m instrumentationLibraryReader) ForEach(fn func(instrumentation.Scope, export.Reader) error) error { for library, records := range m.records { if err := fn(library, &metricReader{records: records}); err != nil { return err diff --git a/sdk/metric/processor/processortest/test_test.go b/sdk/metric/processor/processortest/test_test.go index 98c15f2f763..2ca854edb7a 100644 --- a/sdk/metric/processor/processortest/test_test.go +++ b/sdk/metric/processor/processortest/test_test.go @@ -80,7 +80,7 @@ func TestProcessorTesting(t *testing.T) { ) err := exporter.Export(context.Background(), res, processortest.OneInstrumentationLibraryReader( - instrumentation.Library{ + instrumentation.Scope{ Name: "test", }, checkpointer.Reader(), diff --git a/sdk/metric/processor/reducer/reducer_test.go b/sdk/metric/processor/reducer/reducer_test.go index 12fbb7f86e0..197cafe516f 100644 --- a/sdk/metric/processor/reducer/reducer_test.go +++ b/sdk/metric/processor/reducer/reducer_test.go @@ -106,7 +106,7 @@ func TestFilterBasicProcessor(t *testing.T) { } res := resource.NewSchemaless(attribute.String("R", "V")) - require.NoError(t, exporter.Export(context.Background(), res, processortest.OneInstrumentationLibraryReader(instrumentation.Library{ + require.NoError(t, exporter.Export(context.Background(), res, processortest.OneInstrumentationLibraryReader(instrumentation.Scope{ Name: "test", }, basicProc.Reader()))) diff --git a/sdk/trace/provider.go b/sdk/trace/provider.go index 3f526c1d3cf..ff53a76d203 100644 --- a/sdk/trace/provider.go +++ b/sdk/trace/provider.go @@ -74,7 +74,7 @@ func (cfg tracerProviderConfig) MarshalLog() interface{} { // instrumentation so it can trace operational flow through a system. type TracerProvider struct { mu sync.Mutex - namedTracer map[instrumentation.Library]*tracer + namedTracer map[instrumentation.Scope]*tracer spanProcessors atomic.Value // These fields are not protected by the lock mu. They are assumed to be @@ -110,7 +110,7 @@ func NewTracerProvider(opts ...TracerProviderOption) *TracerProvider { o = ensureValidTracerProviderConfig(o) tp := &TracerProvider{ - namedTracer: make(map[instrumentation.Library]*tracer), + namedTracer: make(map[instrumentation.Scope]*tracer), sampler: o.sampler, idGenerator: o.idGenerator, spanLimits: o.spanLimits, @@ -141,7 +141,7 @@ func (p *TracerProvider) Tracer(name string, opts ...trace.TracerOption) trace.T if name == "" { name = defaultTracerName } - il := instrumentation.Library{ + il := instrumentation.Scope{ Name: name, Version: c.InstrumentationVersion(), SchemaURL: c.SchemaURL(), diff --git a/sdk/trace/snapshot.go b/sdk/trace/snapshot.go index 53aac61f5fe..f447179bbbe 100644 --- a/sdk/trace/snapshot.go +++ b/sdk/trace/snapshot.go @@ -41,7 +41,7 @@ type snapshot struct { droppedEventCount int droppedLinkCount int resource *resource.Resource - instrumentationLibrary instrumentation.Library + instrumentationLibrary instrumentation.Scope } var _ ReadOnlySpan = snapshot{} @@ -104,7 +104,7 @@ func (s snapshot) Status() Status { // InstrumentationLibrary returns information about the instrumentation // library that created the span. -func (s snapshot) InstrumentationLibrary() instrumentation.Library { +func (s snapshot) InstrumentationLibrary() instrumentation.Scope { return s.instrumentationLibrary } diff --git a/sdk/trace/span.go b/sdk/trace/span.go index edf456d93a7..c5a752c8d6a 100644 --- a/sdk/trace/span.go +++ b/sdk/trace/span.go @@ -65,7 +65,7 @@ type ReadOnlySpan interface { Status() Status // InstrumentationLibrary returns information about the instrumentation // library that created the span. - InstrumentationLibrary() instrumentation.Library + InstrumentationLibrary() instrumentation.Scope // Resource returns information about the entity that produced the span. Resource() *resource.Resource // DroppedAttributes returns the number of attributes dropped by the span @@ -584,9 +584,9 @@ func (s *recordingSpan) Status() Status { return s.status } -// InstrumentationLibrary returns the instrumentation.Library associated with +// InstrumentationLibrary returns the instrumentation.Scope associated with // the Tracer that created this span. -func (s *recordingSpan) InstrumentationLibrary() instrumentation.Library { +func (s *recordingSpan) InstrumentationLibrary() instrumentation.Scope { s.mu.Lock() defer s.mu.Unlock() return s.tracer.instrumentationLibrary diff --git a/sdk/trace/trace_test.go b/sdk/trace/trace_test.go index 7ea04a86f05..d0fd4d0e025 100644 --- a/sdk/trace/trace_test.go +++ b/sdk/trace/trace_test.go @@ -412,7 +412,7 @@ func TestSetSpanAttributesOnStart(t *testing.T) { attribute.String("key2", "value2"), }, spanKind: trace.SpanKindInternal, - instrumentationLibrary: instrumentation.Library{Name: "StartSpanAttribute"}, + instrumentationLibrary: instrumentation.Scope{Name: "StartSpanAttribute"}, } if diff := cmpDiff(got, want); diff != "" { t.Errorf("SetSpanAttributesOnStart: -got +want %s", diff) @@ -667,7 +667,7 @@ func TestEvents(t *testing.T) { {Name: "bar", Attributes: []attribute.KeyValue{k2v2, k3v3}}, }, spanKind: trace.SpanKindInternal, - instrumentationLibrary: instrumentation.Library{Name: "Events"}, + instrumentationLibrary: instrumentation.Scope{Name: "Events"}, } if diff := cmpDiff(got, want); diff != "" { t.Errorf("Message Events: -got +want %s", diff) @@ -719,7 +719,7 @@ func TestEventsOverLimit(t *testing.T) { }, droppedEventCount: 2, spanKind: trace.SpanKindInternal, - instrumentationLibrary: instrumentation.Library{Name: "EventsOverLimit"}, + instrumentationLibrary: instrumentation.Scope{Name: "EventsOverLimit"}, } if diff := cmpDiff(got, want); diff != "" { t.Errorf("Message Event over limit: -got +want %s", diff) @@ -757,7 +757,7 @@ func TestLinks(t *testing.T) { name: "span0", links: []Link{{l1.SpanContext, l1.Attributes, 0}, {l2.SpanContext, l2.Attributes, 0}}, spanKind: trace.SpanKindInternal, - instrumentationLibrary: instrumentation.Library{Name: "Links"}, + instrumentationLibrary: instrumentation.Scope{Name: "Links"}, } if diff := cmpDiff(got, want); diff != "" { t.Errorf("Link: -got +want %s", diff) @@ -813,7 +813,7 @@ func TestLinksOverLimit(t *testing.T) { }, droppedLinkCount: 1, spanKind: trace.SpanKindInternal, - instrumentationLibrary: instrumentation.Library{Name: "LinksOverLimit"}, + instrumentationLibrary: instrumentation.Scope{Name: "LinksOverLimit"}, } if diff := cmpDiff(got, want); diff != "" { t.Errorf("Link over limit: -got +want %s", diff) @@ -861,7 +861,7 @@ func TestSetSpanStatus(t *testing.T) { Code: codes.Error, Description: "Error", }, - instrumentationLibrary: instrumentation.Library{Name: "SpanStatus"}, + instrumentationLibrary: instrumentation.Scope{Name: "SpanStatus"}, } if diff := cmpDiff(got, want); diff != "" { t.Errorf("SetSpanStatus: -got +want %s", diff) @@ -891,7 +891,7 @@ func TestSetSpanStatusWithoutMessageWhenStatusIsNotError(t *testing.T) { Code: codes.Ok, Description: "", }, - instrumentationLibrary: instrumentation.Library{Name: "SpanStatus"}, + instrumentationLibrary: instrumentation.Scope{Name: "SpanStatus"}, } if diff := cmpDiff(got, want); diff != "" { t.Errorf("SetSpanStatus: -got +want %s", diff) @@ -1230,7 +1230,7 @@ func TestRecordError(t *testing.T) { }, }, }, - instrumentationLibrary: instrumentation.Library{Name: "RecordError"}, + instrumentationLibrary: instrumentation.Scope{Name: "RecordError"}, } if diff := cmpDiff(got, want); diff != "" { t.Errorf("SpanErrorOptions: -got +want %s", diff) @@ -1274,7 +1274,7 @@ func TestRecordErrorWithStackTrace(t *testing.T) { }, }, }, - instrumentationLibrary: instrumentation.Library{Name: "RecordError"}, + instrumentationLibrary: instrumentation.Scope{Name: "RecordError"}, } assert.Equal(t, got.spanContext, want.spanContext) @@ -1314,7 +1314,7 @@ func TestRecordErrorNil(t *testing.T) { Code: codes.Unset, Description: "", }, - instrumentationLibrary: instrumentation.Library{Name: "RecordErrorNil"}, + instrumentationLibrary: instrumentation.Scope{Name: "RecordErrorNil"}, } if diff := cmpDiff(got, want); diff != "" { t.Errorf("SpanErrorOptions: -got +want %s", diff) @@ -1430,7 +1430,7 @@ func TestWithResource(t *testing.T) { }, spanKind: trace.SpanKindInternal, resource: tc.want, - instrumentationLibrary: instrumentation.Library{Name: "WithResource"}, + instrumentationLibrary: instrumentation.Scope{Name: "WithResource"}, } if diff := cmpDiff(got, want); diff != "" { t.Errorf("WithResource:\n -got +want %s", diff) @@ -1463,7 +1463,7 @@ func TestWithInstrumentationVersionAndSchema(t *testing.T) { parent: sc.WithRemote(true), name: "span0", spanKind: trace.SpanKindInternal, - instrumentationLibrary: instrumentation.Library{ + instrumentationLibrary: instrumentation.Scope{ Name: "WithInstrumentationVersion", Version: "v0.1.0", SchemaURL: "https://opentelemetry.io/schemas/1.2.0", @@ -1696,7 +1696,7 @@ func TestAddEventsWithMoreAttributesThanLimit(t *testing.T) { }, }, spanKind: trace.SpanKindInternal, - instrumentationLibrary: instrumentation.Library{Name: "AddSpanEventWithOverLimitedAttributes"}, + instrumentationLibrary: instrumentation.Scope{Name: "AddSpanEventWithOverLimitedAttributes"}, } if diff := cmpDiff(got, want); diff != "" { t.Errorf("SetSpanAttributesOverLimit: -got +want %s", diff) @@ -1751,7 +1751,7 @@ func TestAddLinksWithMoreAttributesThanLimit(t *testing.T) { }, }, spanKind: trace.SpanKindInternal, - instrumentationLibrary: instrumentation.Library{Name: "Links"}, + instrumentationLibrary: instrumentation.Scope{Name: "Links"}, } if diff := cmpDiff(got, want); diff != "" { t.Errorf("Link: -got +want %s", diff) diff --git a/sdk/trace/tracer.go b/sdk/trace/tracer.go index 5b8ab43be3d..49baeb65387 100644 --- a/sdk/trace/tracer.go +++ b/sdk/trace/tracer.go @@ -24,7 +24,7 @@ import ( type tracer struct { provider *TracerProvider - instrumentationLibrary instrumentation.Library + instrumentationLibrary instrumentation.Scope } var _ trace.Tracer = &tracer{} diff --git a/sdk/trace/tracetest/span.go b/sdk/trace/tracetest/span.go index b5f47735c1f..c6f55100524 100644 --- a/sdk/trace/tracetest/span.go +++ b/sdk/trace/tracetest/span.go @@ -71,7 +71,7 @@ type SpanStub struct { DroppedLinks int ChildSpanCount int Resource *resource.Resource - InstrumentationLibrary instrumentation.Library + InstrumentationLibrary instrumentation.Scope } // SpanStubFromReadOnlySpan returns a SpanStub populated from ro. @@ -141,7 +141,7 @@ type spanSnapshot struct { droppedLinks int childSpanCount int resource *resource.Resource - instrumentationLibrary instrumentation.Library + instrumentationLibrary instrumentation.Scope } func (s spanSnapshot) Name() string { return s.name } @@ -159,6 +159,6 @@ func (s spanSnapshot) DroppedLinks() int { return s.droppedLinks func (s spanSnapshot) DroppedEvents() int { return s.droppedEvents } func (s spanSnapshot) ChildSpanCount() int { return s.childSpanCount } func (s spanSnapshot) Resource() *resource.Resource { return s.resource } -func (s spanSnapshot) InstrumentationLibrary() instrumentation.Library { +func (s spanSnapshot) InstrumentationLibrary() instrumentation.Scope { return s.instrumentationLibrary } From d66f25da6dfbcce91bcd334aeb2af4dae4561a11 Mon Sep 17 00:00:00 2001 From: Craig Pastro Date: Fri, 24 Jun 2022 16:34:29 -0700 Subject: [PATCH 2/9] Add PR number to changelog --- CHANGELOG.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4792ddfc22d..6f140772496 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,8 +20,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm ### Deprecated - The `Library` struct in the `go.opentelemetry.io/otel/sdk/instrumentation` package is deprecated. - Use the equivalent `Scope` struct instead. - + Use the equivalent `Scope` struct instead. (#2977) ## [1.7.0/0.30.0] - 2022-04-28 From 047d6075da26912f71002f04343686b7e6f4fe04 Mon Sep 17 00:00:00 2001 From: Craig Pastro Date: Mon, 27 Jun 2022 14:46:35 -0700 Subject: [PATCH 3/9] Don't change signatures in stable modules --- exporters/jaeger/jaeger.go | 2 +- .../otlptrace/internal/tracetransform/span.go | 8 ++++---- exporters/zipkin/model.go | 2 +- sdk/metric/controller/basic/controller.go | 2 +- sdk/metric/export/metric.go | 2 +- sdk/metric/processor/processortest/test.go | 16 ++++++++-------- sdk/trace/snapshot.go | 8 +++++++- sdk/trace/span.go | 18 +++++++++++++++--- sdk/trace/trace_test.go | 4 ++-- sdk/trace/tracetest/span.go | 9 ++++++--- 10 files changed, 46 insertions(+), 25 deletions(-) diff --git a/exporters/jaeger/jaeger.go b/exporters/jaeger/jaeger.go index d9b58ec4f82..899874e83f2 100644 --- a/exporters/jaeger/jaeger.go +++ b/exporters/jaeger/jaeger.go @@ -142,7 +142,7 @@ func spanToThrift(ss sdktrace.ReadOnlySpan) *gen.Span { } } - if il := ss.InstrumentationLibrary(); il.Name != "" { + if il := ss.InstrumentationScope(); il.Name != "" { tags = append(tags, getStringTag(keyInstrumentationLibraryName, il.Name)) if il.Version != "" { tags = append(tags, getStringTag(keyInstrumentationLibraryVersion, il.Version)) diff --git a/exporters/otlp/otlptrace/internal/tracetransform/span.go b/exporters/otlp/otlptrace/internal/tracetransform/span.go index da6eac95f2c..cb421bf14e0 100644 --- a/exporters/otlp/otlptrace/internal/tracetransform/span.go +++ b/exporters/otlp/otlptrace/internal/tracetransform/span.go @@ -47,15 +47,15 @@ func Spans(sdl []tracesdk.ReadOnlySpan) []*tracepb.ResourceSpans { rKey := sd.Resource().Equivalent() k := key{ r: rKey, - il: sd.InstrumentationLibrary(), + il: sd.InstrumentationScope(), } scopeSpan, iOk := ssm[k] if !iOk { - // Either the resource or instrumentation library were unknown. + // Either the resource or instrumentation scope were unknown. scopeSpan = &tracepb.ScopeSpans{ - Scope: InstrumentationScope(sd.InstrumentationLibrary()), + Scope: InstrumentationScope(sd.InstrumentationScope()), Spans: []*tracepb.Span{}, - SchemaUrl: sd.InstrumentationLibrary().SchemaURL, + SchemaUrl: sd.InstrumentationScope().SchemaURL, } } scopeSpan.Spans = append(scopeSpan.Spans, span(sd)) diff --git a/exporters/zipkin/model.go b/exporters/zipkin/model.go index f733651dac6..ae14c490a4c 100644 --- a/exporters/zipkin/model.go +++ b/exporters/zipkin/model.go @@ -218,7 +218,7 @@ func toZipkinTags(data tracesdk.ReadOnlySpan) map[string]string { delete(m, "error") } - if il := data.InstrumentationLibrary(); il.Name != "" { + if il := data.InstrumentationScope(); il.Name != "" { m[keyInstrumentationLibraryName] = il.Name if il.Version != "" { m[keyInstrumentationLibraryVersion] = il.Version diff --git a/sdk/metric/controller/basic/controller.go b/sdk/metric/controller/basic/controller.go index 51c0da6e481..ebf4cca7d7b 100644 --- a/sdk/metric/controller/basic/controller.go +++ b/sdk/metric/controller/basic/controller.go @@ -323,7 +323,7 @@ func (c *Controller) export(ctx context.Context) error { // nolint:revive // me } // ForEach implements export.InstrumentationLibraryReader. -func (c *Controller) ForEach(readerFunc func(l instrumentation.Scope, r export.Reader) error) error { +func (c *Controller) ForEach(readerFunc func(l instrumentation.Library, r export.Reader) error) error { for _, acPair := range c.accumulatorList() { reader := acPair.checkpointer.Reader() // TODO: We should not fail fast; instead accumulate errors. diff --git a/sdk/metric/export/metric.go b/sdk/metric/export/metric.go index e2cf1bf57af..6168ca445ba 100644 --- a/sdk/metric/export/metric.go +++ b/sdk/metric/export/metric.go @@ -155,7 +155,7 @@ type InstrumentationLibraryReader interface { // ForEach calls the passed function once per instrumentation library, // allowing the caller to emit metrics grouped by the library that // produced them. - ForEach(readerFunc func(instrumentation.Scope, Reader) error) error + ForEach(readerFunc func(instrumentation.Library, Reader) error) error } // Reader allows a controller to access a complete checkpoint of diff --git a/sdk/metric/processor/processortest/test.go b/sdk/metric/processor/processortest/test.go index 521904cd7cc..fa0e902d255 100644 --- a/sdk/metric/processor/processortest/test.go +++ b/sdk/metric/processor/processortest/test.go @@ -243,7 +243,7 @@ func (o *Output) AddRecord(rec export.Record) error { } // AddRecordWithResource merges rec into this Output. -func (o *Output) AddInstrumentationLibraryRecord(_ instrumentation.Scope, rec export.Record) error { +func (o *Output) AddInstrumentationLibraryRecord(_ instrumentation.Library, rec export.Record) error { return o.AddRecordWithResource(rec, resource.Empty()) } @@ -340,7 +340,7 @@ func (e *Exporter) Export(_ context.Context, res *resource.Resource, ckpt export e.output.Lock() defer e.output.Unlock() e.exportCount++ - return ckpt.ForEach(func(library instrumentation.Scope, mr export.Reader) error { + return ckpt.ForEach(func(library instrumentation.Library, mr export.Reader) error { return mr.ForEach(e.TemporalitySelector, func(r export.Record) error { if e.InjectErr != nil { if err := e.InjectErr(r); err != nil { @@ -381,32 +381,32 @@ func (e *Exporter) Reset() { // OneInstrumentationLibraryReader returns an InstrumentationLibraryReader for // a single instrumentation library. -func OneInstrumentationLibraryReader(l instrumentation.Scope, r export.Reader) export.InstrumentationLibraryReader { +func OneInstrumentationLibraryReader(l instrumentation.Library, r export.Reader) export.InstrumentationLibraryReader { return oneLibraryReader{l, r} } type oneLibraryReader struct { - library instrumentation.Scope + library instrumentation.Library reader export.Reader } -func (o oneLibraryReader) ForEach(readerFunc func(instrumentation.Scope, export.Reader) error) error { +func (o oneLibraryReader) ForEach(readerFunc func(instrumentation.Library, export.Reader) error) error { return readerFunc(o.library, o.reader) } // MultiInstrumentationLibraryReader returns an InstrumentationLibraryReader // for a group of records that came from multiple instrumentation libraries. -func MultiInstrumentationLibraryReader(records map[instrumentation.Scope][]export.Record) export.InstrumentationLibraryReader { +func MultiInstrumentationLibraryReader(records map[instrumentation.Library][]export.Record) export.InstrumentationLibraryReader { return instrumentationLibraryReader{records: records} } type instrumentationLibraryReader struct { - records map[instrumentation.Scope][]export.Record + records map[instrumentation.Library][]export.Record } var _ export.InstrumentationLibraryReader = instrumentationLibraryReader{} -func (m instrumentationLibraryReader) ForEach(fn func(instrumentation.Scope, export.Reader) error) error { +func (m instrumentationLibraryReader) ForEach(fn func(instrumentation.Library, export.Reader) error) error { for library, records := range m.records { if err := fn(library, &metricReader{records: records}); err != nil { return err diff --git a/sdk/trace/snapshot.go b/sdk/trace/snapshot.go index f447179bbbe..5cd93779ff0 100644 --- a/sdk/trace/snapshot.go +++ b/sdk/trace/snapshot.go @@ -102,9 +102,15 @@ func (s snapshot) Status() Status { return s.status } +// InstrumentationScope returns information about the instrumentation +// scope that created the span. +func (s snapshot) InstrumentationScope() instrumentation.Scope { + return s.instrumentationLibrary +} + // InstrumentationLibrary returns information about the instrumentation // library that created the span. -func (s snapshot) InstrumentationLibrary() instrumentation.Scope { +func (s snapshot) InstrumentationLibrary() instrumentation.Library { return s.instrumentationLibrary } diff --git a/sdk/trace/span.go b/sdk/trace/span.go index c5a752c8d6a..d7c20f1f9b3 100644 --- a/sdk/trace/span.go +++ b/sdk/trace/span.go @@ -63,9 +63,13 @@ type ReadOnlySpan interface { Events() []Event // Status returns the spans status. Status() Status + // InstrumentationScope returns information about the instrumentation + // scope that created the span. + InstrumentationScope() instrumentation.Scope // InstrumentationLibrary returns information about the instrumentation // library that created the span. - InstrumentationLibrary() instrumentation.Scope + // Deprecated: please use InstrumentationScope instead + InstrumentationLibrary() instrumentation.Library // Resource returns information about the entity that produced the span. Resource() *resource.Resource // DroppedAttributes returns the number of attributes dropped by the span @@ -584,9 +588,17 @@ func (s *recordingSpan) Status() Status { return s.status } -// InstrumentationLibrary returns the instrumentation.Scope associated with +// InstrumentationScope returns the instrumentation.Scope associated with // the Tracer that created this span. -func (s *recordingSpan) InstrumentationLibrary() instrumentation.Scope { +func (s *recordingSpan) InstrumentationScope() instrumentation.Scope { + s.mu.Lock() + defer s.mu.Unlock() + return s.tracer.instrumentationLibrary +} + +// InstrumentationLibrary returns the instrumentation.Library associated with +// the Tracer that created this span. +func (s *recordingSpan) InstrumentationLibrary() instrumentation.Library { s.mu.Lock() defer s.mu.Unlock() return s.tracer.instrumentationLibrary diff --git a/sdk/trace/trace_test.go b/sdk/trace/trace_test.go index d0fd4d0e025..cb3852acbdf 100644 --- a/sdk/trace/trace_test.go +++ b/sdk/trace/trace_test.go @@ -1570,8 +1570,8 @@ func TestReadOnlySpan(t *testing.T) { assert.Equal(t, kv.Value, ro.Events()[0].Attributes[0].Value) assert.Equal(t, codes.Ok, ro.Status().Code) assert.Equal(t, "", ro.Status().Description) - assert.Equal(t, "ReadOnlySpan", ro.InstrumentationLibrary().Name) - assert.Equal(t, "3", ro.InstrumentationLibrary().Version) + assert.Equal(t, "ReadOnlySpan", ro.InstrumentationScope().Name) + assert.Equal(t, "3", ro.InstrumentationScope().Version) assert.Equal(t, kv.Key, ro.Resource().Attributes()[0].Key) assert.Equal(t, kv.Value, ro.Resource().Attributes()[0].Value) diff --git a/sdk/trace/tracetest/span.go b/sdk/trace/tracetest/span.go index c6f55100524..e8108a05a55 100644 --- a/sdk/trace/tracetest/span.go +++ b/sdk/trace/tracetest/span.go @@ -71,7 +71,7 @@ type SpanStub struct { DroppedLinks int ChildSpanCount int Resource *resource.Resource - InstrumentationLibrary instrumentation.Scope + InstrumentationLibrary instrumentation.Library } // SpanStubFromReadOnlySpan returns a SpanStub populated from ro. @@ -141,7 +141,7 @@ type spanSnapshot struct { droppedLinks int childSpanCount int resource *resource.Resource - instrumentationLibrary instrumentation.Scope + instrumentationLibrary instrumentation.Library } func (s spanSnapshot) Name() string { return s.name } @@ -159,6 +159,9 @@ func (s spanSnapshot) DroppedLinks() int { return s.droppedLinks func (s spanSnapshot) DroppedEvents() int { return s.droppedEvents } func (s spanSnapshot) ChildSpanCount() int { return s.childSpanCount } func (s spanSnapshot) Resource() *resource.Resource { return s.resource } -func (s spanSnapshot) InstrumentationLibrary() instrumentation.Scope { +func (s spanSnapshot) InstrumentationScope() instrumentation.Scope { + return s.instrumentationLibrary +} +func (s spanSnapshot) InstrumentationLibrary() instrumentation.Library { return s.instrumentationLibrary } From 3af818c10a7c46fe09881c6fe8bb485c4206e439 Mon Sep 17 00:00:00 2001 From: Craig Pastro Date: Mon, 27 Jun 2022 15:08:23 -0700 Subject: [PATCH 4/9] Revert some changes --- bridge/opencensus/exporter.go | 4 ++-- bridge/opencensus/exporter_test.go | 2 +- exporters/jaeger/jaeger.go | 8 ++++---- exporters/jaeger/jaeger_benchmark_test.go | 2 +- exporters/jaeger/jaeger_test.go | 8 ++++---- exporters/otlp/otlpmetric/exporter_test.go | 6 +++--- .../otlp/otlpmetric/internal/metrictransform/metric.go | 2 +- exporters/otlp/otlpmetric/internal/otlpmetrictest/data.go | 4 ++-- exporters/otlp/otlptrace/internal/tracetransform/span.go | 4 ++-- exporters/prometheus/prometheus.go | 4 ++-- exporters/stdout/stdoutmetric/metric.go | 2 +- exporters/zipkin/model.go | 8 ++++---- exporters/zipkin/model_test.go | 6 +++--- 13 files changed, 30 insertions(+), 30 deletions(-) diff --git a/bridge/opencensus/exporter.go b/bridge/opencensus/exporter.go index 84aa499a60f..7e7e7960007 100644 --- a/bridge/opencensus/exporter.go +++ b/bridge/opencensus/exporter.go @@ -64,8 +64,8 @@ type censusLibraryReader struct { metrics []*metricdata.Metric } -func (r censusLibraryReader) ForEach(readerFunc func(instrumentation.Scope, export.Reader) error) error { - return readerFunc(instrumentation.Scope{ +func (r censusLibraryReader) ForEach(readerFunc func(instrumentation.Library, export.Reader) error) error { + return readerFunc(instrumentation.Library{ Name: "OpenCensus Bridge", }, &metricReader{metrics: r.metrics}) } diff --git a/bridge/opencensus/exporter_test.go b/bridge/opencensus/exporter_test.go index c1ea8c95400..2634f5334d5 100644 --- a/bridge/opencensus/exporter_test.go +++ b/bridge/opencensus/exporter_test.go @@ -47,7 +47,7 @@ type fakeExporter struct { func (f *fakeExporter) Export(ctx context.Context, res *resource.Resource, ilr export.InstrumentationLibraryReader) error { return controllertest.ReadAll(ilr, aggregation.StatelessTemporalitySelector(), - func(_ instrumentation.Scope, record export.Record) error { + func(_ instrumentation.Library, record export.Record) error { f.resource = res f.records = append(f.records, record) return f.err diff --git a/exporters/jaeger/jaeger.go b/exporters/jaeger/jaeger.go index 899874e83f2..d6d2fcfbbee 100644 --- a/exporters/jaeger/jaeger.go +++ b/exporters/jaeger/jaeger.go @@ -142,10 +142,10 @@ func spanToThrift(ss sdktrace.ReadOnlySpan) *gen.Span { } } - if il := ss.InstrumentationScope(); il.Name != "" { - tags = append(tags, getStringTag(keyInstrumentationLibraryName, il.Name)) - if il.Version != "" { - tags = append(tags, getStringTag(keyInstrumentationLibraryVersion, il.Version)) + if is := ss.InstrumentationScope(); is.Name != "" { + tags = append(tags, getStringTag(keyInstrumentationLibraryName, is.Name)) + if is.Version != "" { + tags = append(tags, getStringTag(keyInstrumentationLibraryVersion, is.Version)) } } diff --git a/exporters/jaeger/jaeger_benchmark_test.go b/exporters/jaeger/jaeger_benchmark_test.go index 2b0e54c90d6..ab96ac8c9ed 100644 --- a/exporters/jaeger/jaeger_benchmark_test.go +++ b/exporters/jaeger/jaeger_benchmark_test.go @@ -61,7 +61,7 @@ func spans(n int) []tracesdk.ReadOnlySpan { StartTime: now, EndTime: now, SpanKind: trace.SpanKindClient, - InstrumentationLibrary: instrumentation.Scope{ + InstrumentationLibrary: instrumentation.Library{ Name: instrLibName, }, } diff --git a/exporters/jaeger/jaeger_test.go b/exporters/jaeger/jaeger_test.go index c748293ee9b..67133ab2c9d 100644 --- a/exporters/jaeger/jaeger_test.go +++ b/exporters/jaeger/jaeger_test.go @@ -187,7 +187,7 @@ func TestSpanSnapshotToThrift(t *testing.T) { EndTime: now, Status: sdktrace.Status{Code: codes.Error}, SpanKind: trace.SpanKindClient, - InstrumentationLibrary: instrumentation.Scope{ + InstrumentationLibrary: instrumentation.Library{ Name: instrLibName, Version: instrLibVersion, }, @@ -245,7 +245,7 @@ func TestSpanSnapshotToThrift(t *testing.T) { Description: statusMessage, }, SpanKind: trace.SpanKindClient, - InstrumentationLibrary: instrumentation.Scope{ + InstrumentationLibrary: instrumentation.Library{ Name: instrLibName, Version: instrLibVersion, }, @@ -330,7 +330,7 @@ func TestSpanSnapshotToThrift(t *testing.T) { Description: statusMessage, }, SpanKind: trace.SpanKindInternal, - InstrumentationLibrary: instrumentation.Scope{ + InstrumentationLibrary: instrumentation.Library{ Name: instrLibName, Version: instrLibVersion, }, @@ -383,7 +383,7 @@ func TestSpanSnapshotToThrift(t *testing.T) { Description: statusMessage, }, SpanKind: trace.SpanKindInternal, - InstrumentationLibrary: instrumentation.Scope{ + InstrumentationLibrary: instrumentation.Library{ Name: instrLibName, Version: instrLibVersion, }, diff --git a/exporters/otlp/otlpmetric/exporter_test.go b/exporters/otlp/otlpmetric/exporter_test.go index f4fe7774e9a..d5208fc26d6 100644 --- a/exporters/otlp/otlpmetric/exporter_test.go +++ b/exporters/otlp/otlpmetric/exporter_test.go @@ -728,7 +728,7 @@ func TestStatelessAggregationTemporality(t *testing.T) { func runMetricExportTests(t *testing.T, opts []otlpmetric.Option, res *resource.Resource, records []testRecord, expected []*metricpb.ResourceMetrics) { exp, driver := newExporter(t, opts...) - libraryRecs := map[instrumentation.Scope][]export.Record{} + libraryRecs := map[instrumentation.Library][]export.Record{} for _, r := range records { lcopy := make([]attribute.KeyValue, len(r.attrs)) copy(lcopy, r.attrs) @@ -771,7 +771,7 @@ func runMetricExportTests(t *testing.T, opts []otlpmetric.Option, res *resource. require.NoError(t, agg.SynchronizedMove(ckpt, &desc)) meterCfg := metric.NewMeterConfig(r.meterOpts...) - lib := instrumentation.Scope{ + lib := instrumentation.Library{ Name: r.meterName, Version: meterCfg.InstrumentationVersion(), SchemaURL: meterCfg.SchemaURL(), @@ -838,7 +838,7 @@ func TestEmptyMetricExport(t *testing.T) { }, } { driver.Reset() - require.NoError(t, exp.Export(context.Background(), resource.Empty(), processortest.MultiInstrumentationLibraryReader(map[instrumentation.Scope][]export.Record{ + require.NoError(t, exp.Export(context.Background(), resource.Empty(), processortest.MultiInstrumentationLibraryReader(map[instrumentation.Library][]export.Record{ { Name: testLibName, }: test.records, diff --git a/exporters/otlp/otlpmetric/internal/metrictransform/metric.go b/exporters/otlp/otlpmetric/internal/metrictransform/metric.go index a189b85bdad..2d7c9049905 100644 --- a/exporters/otlp/otlpmetric/internal/metrictransform/metric.go +++ b/exporters/otlp/otlpmetric/internal/metrictransform/metric.go @@ -74,7 +74,7 @@ func toNanos(t time.Time) uint64 { func InstrumentationLibraryReader(ctx context.Context, temporalitySelector aggregation.TemporalitySelector, res *resource.Resource, ilmr export.InstrumentationLibraryReader, numWorkers uint) (*metricpb.ResourceMetrics, error) { var sms []*metricpb.ScopeMetrics - err := ilmr.ForEach(func(lib instrumentation.Scope, mr export.Reader) error { + err := ilmr.ForEach(func(lib instrumentation.Library, mr export.Reader) error { records, errc := source(ctx, temporalitySelector, mr) // Start a fixed number of goroutines to transform records. diff --git a/exporters/otlp/otlpmetric/internal/otlpmetrictest/data.go b/exporters/otlp/otlpmetric/internal/otlpmetrictest/data.go index 825a31d9189..d8d9c03a31e 100644 --- a/exporters/otlp/otlpmetric/internal/otlpmetrictest/data.go +++ b/exporters/otlp/otlpmetric/internal/otlpmetrictest/data.go @@ -48,7 +48,7 @@ func OneRecordReader() export.InstrumentationLibraryReader { rec := export.NewRecord(&desc, &attrs, agg[0].Aggregation(), start, end) return processortest.MultiInstrumentationLibraryReader( - map[instrumentation.Scope][]export.Record{ + map[instrumentation.Library][]export.Record{ { Name: "onelib", }: {rec}, @@ -66,6 +66,6 @@ type FailReader struct{} var _ export.InstrumentationLibraryReader = FailReader{} // ForEach implements export.Reader. It always fails. -func (FailReader) ForEach(readerFunc func(instrumentation.Scope, export.Reader) error) error { +func (FailReader) ForEach(readerFunc func(instrumentation.Library, export.Reader) error) error { return fmt.Errorf("fail") } diff --git a/exporters/otlp/otlptrace/internal/tracetransform/span.go b/exporters/otlp/otlptrace/internal/tracetransform/span.go index cb421bf14e0..b83cbd72478 100644 --- a/exporters/otlp/otlptrace/internal/tracetransform/span.go +++ b/exporters/otlp/otlptrace/internal/tracetransform/span.go @@ -34,7 +34,7 @@ func Spans(sdl []tracesdk.ReadOnlySpan) []*tracepb.ResourceSpans { type key struct { r attribute.Distinct - il instrumentation.Scope + is instrumentation.Scope } ssm := make(map[key]*tracepb.ScopeSpans) @@ -47,7 +47,7 @@ func Spans(sdl []tracesdk.ReadOnlySpan) []*tracepb.ResourceSpans { rKey := sd.Resource().Equivalent() k := key{ r: rKey, - il: sd.InstrumentationScope(), + is: sd.InstrumentationScope(), } scopeSpan, iOk := ssm[k] if !iOk { diff --git a/exporters/prometheus/prometheus.go b/exporters/prometheus/prometheus.go index c7aa16d1257..fb544d004fb 100644 --- a/exporters/prometheus/prometheus.go +++ b/exporters/prometheus/prometheus.go @@ -151,7 +151,7 @@ func (c *collector) Describe(ch chan<- *prometheus.Desc) { c.exp.lock.RLock() defer c.exp.lock.RUnlock() - _ = c.exp.Controller().ForEach(func(_ instrumentation.Scope, reader export.Reader) error { + _ = c.exp.Controller().ForEach(func(_ instrumentation.Library, reader export.Reader) error { return reader.ForEach(c.exp, func(record export.Record) error { var attrKeys []string mergeAttrs(record, c.exp.controller.Resource(), &attrKeys, nil) @@ -174,7 +174,7 @@ func (c *collector) Collect(ch chan<- prometheus.Metric) { otel.Handle(err) } - err := ctrl.ForEach(func(_ instrumentation.Scope, reader export.Reader) error { + err := ctrl.ForEach(func(_ instrumentation.Library, reader export.Reader) error { return reader.ForEach(c.exp, func(record export.Record) error { agg := record.Aggregation() numberKind := record.Descriptor().NumberKind() diff --git a/exporters/stdout/stdoutmetric/metric.go b/exporters/stdout/stdoutmetric/metric.go index 0bdee8e9093..38289d281a7 100644 --- a/exporters/stdout/stdoutmetric/metric.go +++ b/exporters/stdout/stdoutmetric/metric.go @@ -52,7 +52,7 @@ func (e *metricExporter) TemporalityFor(desc *sdkapi.Descriptor, kind aggregatio func (e *metricExporter) Export(_ context.Context, res *resource.Resource, reader export.InstrumentationLibraryReader) error { var aggError error var batch []line - aggError = reader.ForEach(func(lib instrumentation.Scope, mr export.Reader) error { + aggError = reader.ForEach(func(lib instrumentation.Library, mr export.Reader) error { var instAttrs []attribute.KeyValue if name := lib.Name; name != "" { instAttrs = append(instAttrs, attribute.String("instrumentation.name", name)) diff --git a/exporters/zipkin/model.go b/exporters/zipkin/model.go index ae14c490a4c..81d0fc1a706 100644 --- a/exporters/zipkin/model.go +++ b/exporters/zipkin/model.go @@ -218,10 +218,10 @@ func toZipkinTags(data tracesdk.ReadOnlySpan) map[string]string { delete(m, "error") } - if il := data.InstrumentationScope(); il.Name != "" { - m[keyInstrumentationLibraryName] = il.Name - if il.Version != "" { - m[keyInstrumentationLibraryVersion] = il.Version + if is := data.InstrumentationScope(); is.Name != "" { + m[keyInstrumentationLibraryName] = is.Name + if is.Version != "" { + m[keyInstrumentationLibraryVersion] = is.Version } } diff --git a/exporters/zipkin/model_test.go b/exporters/zipkin/model_test.go index 9ada99ca3f1..f8869988e7a 100644 --- a/exporters/zipkin/model_test.go +++ b/exporters/zipkin/model_test.go @@ -829,7 +829,7 @@ func TestTagsTransformation(t *testing.T) { { name: "instrLib-empty", data: tracetest.SpanStub{ - InstrumentationLibrary: instrumentation.Scope{}, + InstrumentationLibrary: instrumentation.Library{}, }, want: nil, }, @@ -837,7 +837,7 @@ func TestTagsTransformation(t *testing.T) { name: "instrLib-noversion", data: tracetest.SpanStub{ Attributes: []attribute.KeyValue{}, - InstrumentationLibrary: instrumentation.Scope{ + InstrumentationLibrary: instrumentation.Library{ Name: instrLibName, }, }, @@ -849,7 +849,7 @@ func TestTagsTransformation(t *testing.T) { name: "instrLib-with-version", data: tracetest.SpanStub{ Attributes: []attribute.KeyValue{}, - InstrumentationLibrary: instrumentation.Scope{ + InstrumentationLibrary: instrumentation.Library{ Name: instrLibName, Version: instrLibVersion, }, From 2534d4beb30c19a8c4e7ebe3add548c3f089d7cd Mon Sep 17 00:00:00 2001 From: Craig Pastro Date: Mon, 27 Jun 2022 15:20:14 -0700 Subject: [PATCH 5/9] Rename internal struct names --- sdk/metric/controller/basic/controller.go | 20 +++---- sdk/metric/controller/controllertest/test.go | 4 +- sdk/metric/metrictest/exporter.go | 6 +- sdk/metric/processor/basic/basic_test.go | 2 +- .../processor/processortest/test_test.go | 2 +- sdk/metric/processor/reducer/reducer_test.go | 2 +- sdk/trace/provider.go | 10 ++-- sdk/trace/provider_test.go | 2 +- sdk/trace/snapshot.go | 36 ++++++------ sdk/trace/span.go | 6 +- sdk/trace/trace_test.go | 56 +++++++++---------- sdk/trace/tracer.go | 4 +- 12 files changed, 75 insertions(+), 75 deletions(-) diff --git a/sdk/metric/controller/basic/controller.go b/sdk/metric/controller/basic/controller.go index ebf4cca7d7b..2107b16cb3c 100644 --- a/sdk/metric/controller/basic/controller.go +++ b/sdk/metric/controller/basic/controller.go @@ -59,7 +59,7 @@ var ErrControllerStarted = fmt.Errorf("controller already started") type Controller struct { // lock synchronizes Start() and Stop(). lock sync.Mutex - libraries sync.Map + scopes sync.Map checkpointerFactory export.CheckpointerFactory resource *resource.Resource @@ -85,21 +85,21 @@ var _ metric.MeterProvider = &Controller{} // with opts. func (c *Controller) Meter(instrumentationName string, opts ...metric.MeterOption) metric.Meter { cfg := metric.NewMeterConfig(opts...) - library := instrumentation.Scope{ + scope := instrumentation.Scope{ Name: instrumentationName, Version: cfg.InstrumentationVersion(), SchemaURL: cfg.SchemaURL(), } - m, ok := c.libraries.Load(library) + m, ok := c.scopes.Load(scope) if !ok { checkpointer := c.checkpointerFactory.NewCheckpointer() - m, _ = c.libraries.LoadOrStore( - library, + m, _ = c.scopes.LoadOrStore( + scope, registry.NewUniqueInstrumentMeterImpl(&accumulatorCheckpointer{ Accumulator: sdk.NewAccumulator(checkpointer), checkpointer: checkpointer, - library: library, + scope: scope, })) } return sdkapi.WrapMeterImpl(m.(*registry.UniqueInstrumentMeterImpl)) @@ -108,7 +108,7 @@ func (c *Controller) Meter(instrumentationName string, opts ...metric.MeterOptio type accumulatorCheckpointer struct { *sdk.Accumulator checkpointer export.Checkpointer - library instrumentation.Scope + scope instrumentation.Scope } var _ sdkapi.MeterImpl = &accumulatorCheckpointer{} @@ -248,7 +248,7 @@ func (c *Controller) collect(ctx context.Context) error { // registered to this controller. This briefly locks the controller. func (c *Controller) accumulatorList() []*accumulatorCheckpointer { var r []*accumulatorCheckpointer - c.libraries.Range(func(key, value interface{}) bool { + c.scopes.Range(func(key, value interface{}) bool { acc, ok := value.(*registry.UniqueInstrumentMeterImpl).MeterImpl().(*accumulatorCheckpointer) if ok { r = append(r, acc) @@ -272,7 +272,7 @@ func (c *Controller) checkpoint(ctx context.Context) error { } // checkpointSingleAccumulator checkpoints a single instrumentation -// library's accumulator, which involves calling +// scope's accumulator, which involves calling // checkpointer.StartCollection, accumulator.Collect, and // checkpointer.FinishCollection in sequence. func (c *Controller) checkpointSingleAccumulator(ctx context.Context, ac *accumulatorCheckpointer) error { @@ -330,7 +330,7 @@ func (c *Controller) ForEach(readerFunc func(l instrumentation.Library, r export if err := func() error { reader.RLock() defer reader.RUnlock() - return readerFunc(acPair.library, reader) + return readerFunc(acPair.scope, reader) }(); err != nil { return err } diff --git a/sdk/metric/controller/controllertest/test.go b/sdk/metric/controller/controllertest/test.go index 045159f39c2..9c1a3421972 100644 --- a/sdk/metric/controller/controllertest/test.go +++ b/sdk/metric/controller/controllertest/test.go @@ -75,9 +75,9 @@ func (t MockTicker) C() <-chan time.Time { func ReadAll( reader export.InstrumentationLibraryReader, kind aggregation.TemporalitySelector, - apply func(instrumentation.Scope, export.Record) error, + apply func(instrumentation.Library, export.Record) error, ) error { - return reader.ForEach(func(library instrumentation.Scope, reader export.Reader) error { + return reader.ForEach(func(library instrumentation.Library, reader export.Reader) error { return reader.ForEach(kind, func(record export.Record) error { return apply(library, record) }) diff --git a/sdk/metric/metrictest/exporter.go b/sdk/metric/metrictest/exporter.go index 79d862eff80..c0926dd7cf6 100644 --- a/sdk/metric/metrictest/exporter.go +++ b/sdk/metric/metrictest/exporter.go @@ -78,7 +78,7 @@ type Scope struct { // ExportRecord represents one collected datapoint from the Exporter. type ExportRecord struct { InstrumentName string - InstrumentationLibrary Scope + InstrumentationLibrary Library Attributes []attribute.KeyValue AggregationKind aggregation.Kind NumberKind number.Kind @@ -98,8 +98,8 @@ func (e *Exporter) Collect(ctx context.Context) error { return err } - return e.controller.ForEach(func(l instrumentation.Scope, r export.Reader) error { - lib := Scope{ + return e.controller.ForEach(func(l instrumentation.Library, r export.Reader) error { + lib := Library{ InstrumentationName: l.Name, InstrumentationVersion: l.Version, SchemaURL: l.SchemaURL, diff --git a/sdk/metric/processor/basic/basic_test.go b/sdk/metric/processor/basic/basic_test.go index 43d06109c25..21d816b44a0 100644 --- a/sdk/metric/processor/basic/basic_test.go +++ b/sdk/metric/processor/basic/basic_test.go @@ -471,7 +471,7 @@ func TestCounterObserverEndToEnd(t *testing.T) { exporter := processortest.New(eselector, attribute.DefaultEncoder()) require.NoError(t, exporter.Export(ctx, resource.Empty(), processortest.OneInstrumentationLibraryReader( - instrumentation.Scope{ + instrumentation.Library{ Name: "test", }, reader))) diff --git a/sdk/metric/processor/processortest/test_test.go b/sdk/metric/processor/processortest/test_test.go index 2ca854edb7a..98c15f2f763 100644 --- a/sdk/metric/processor/processortest/test_test.go +++ b/sdk/metric/processor/processortest/test_test.go @@ -80,7 +80,7 @@ func TestProcessorTesting(t *testing.T) { ) err := exporter.Export(context.Background(), res, processortest.OneInstrumentationLibraryReader( - instrumentation.Scope{ + instrumentation.Library{ Name: "test", }, checkpointer.Reader(), diff --git a/sdk/metric/processor/reducer/reducer_test.go b/sdk/metric/processor/reducer/reducer_test.go index 197cafe516f..12fbb7f86e0 100644 --- a/sdk/metric/processor/reducer/reducer_test.go +++ b/sdk/metric/processor/reducer/reducer_test.go @@ -106,7 +106,7 @@ func TestFilterBasicProcessor(t *testing.T) { } res := resource.NewSchemaless(attribute.String("R", "V")) - require.NoError(t, exporter.Export(context.Background(), res, processortest.OneInstrumentationLibraryReader(instrumentation.Scope{ + require.NoError(t, exporter.Export(context.Background(), res, processortest.OneInstrumentationLibraryReader(instrumentation.Library{ Name: "test", }, basicProc.Reader()))) diff --git a/sdk/trace/provider.go b/sdk/trace/provider.go index ff53a76d203..eac69f34d76 100644 --- a/sdk/trace/provider.go +++ b/sdk/trace/provider.go @@ -141,18 +141,18 @@ func (p *TracerProvider) Tracer(name string, opts ...trace.TracerOption) trace.T if name == "" { name = defaultTracerName } - il := instrumentation.Scope{ + is := instrumentation.Scope{ Name: name, Version: c.InstrumentationVersion(), SchemaURL: c.SchemaURL(), } - t, ok := p.namedTracer[il] + t, ok := p.namedTracer[is] if !ok { t = &tracer{ - provider: p, - instrumentationLibrary: il, + provider: p, + instrumentationScope: is, } - p.namedTracer[il] = t + p.namedTracer[is] = t global.Info("Tracer created", "name", name, "version", c.InstrumentationVersion(), "schemaURL", c.SchemaURL()) } return t diff --git a/sdk/trace/provider_test.go b/sdk/trace/provider_test.go index 1f5d460d739..39caf5a91df 100644 --- a/sdk/trace/provider_test.go +++ b/sdk/trace/provider_test.go @@ -96,7 +96,7 @@ func TestSchemaURL(t *testing.T) { // Verify that the SchemaURL of the constructed Tracer is correctly populated. tracerStruct := tracerIface.(*tracer) - assert.EqualValues(t, schemaURL, tracerStruct.instrumentationLibrary.SchemaURL) + assert.EqualValues(t, schemaURL, tracerStruct.instrumentationScope.SchemaURL) } func TestTracerProviderSamplerConfigFromEnv(t *testing.T) { diff --git a/sdk/trace/snapshot.go b/sdk/trace/snapshot.go index 5cd93779ff0..0349b2f198e 100644 --- a/sdk/trace/snapshot.go +++ b/sdk/trace/snapshot.go @@ -26,22 +26,22 @@ import ( // snapshot is an record of a spans state at a particular checkpointed time. // It is used as a read-only representation of that state. type snapshot struct { - name string - spanContext trace.SpanContext - parent trace.SpanContext - spanKind trace.SpanKind - startTime time.Time - endTime time.Time - attributes []attribute.KeyValue - events []Event - links []Link - status Status - childSpanCount int - droppedAttributeCount int - droppedEventCount int - droppedLinkCount int - resource *resource.Resource - instrumentationLibrary instrumentation.Scope + name string + spanContext trace.SpanContext + parent trace.SpanContext + spanKind trace.SpanKind + startTime time.Time + endTime time.Time + attributes []attribute.KeyValue + events []Event + links []Link + status Status + childSpanCount int + droppedAttributeCount int + droppedEventCount int + droppedLinkCount int + resource *resource.Resource + instrumentationScope instrumentation.Scope } var _ ReadOnlySpan = snapshot{} @@ -105,13 +105,13 @@ func (s snapshot) Status() Status { // InstrumentationScope returns information about the instrumentation // scope that created the span. func (s snapshot) InstrumentationScope() instrumentation.Scope { - return s.instrumentationLibrary + return s.instrumentationScope } // InstrumentationLibrary returns information about the instrumentation // library that created the span. func (s snapshot) InstrumentationLibrary() instrumentation.Library { - return s.instrumentationLibrary + return s.instrumentationScope } // Resource returns information about the entity that produced the span. diff --git a/sdk/trace/span.go b/sdk/trace/span.go index d7c20f1f9b3..df45aa8070e 100644 --- a/sdk/trace/span.go +++ b/sdk/trace/span.go @@ -593,7 +593,7 @@ func (s *recordingSpan) Status() Status { func (s *recordingSpan) InstrumentationScope() instrumentation.Scope { s.mu.Lock() defer s.mu.Unlock() - return s.tracer.instrumentationLibrary + return s.tracer.instrumentationScope } // InstrumentationLibrary returns the instrumentation.Library associated with @@ -601,7 +601,7 @@ func (s *recordingSpan) InstrumentationScope() instrumentation.Scope { func (s *recordingSpan) InstrumentationLibrary() instrumentation.Library { s.mu.Lock() defer s.mu.Unlock() - return s.tracer.instrumentationLibrary + return s.tracer.instrumentationScope } // Resource returns the Resource associated with the Tracer that created this @@ -680,7 +680,7 @@ func (s *recordingSpan) snapshot() ReadOnlySpan { defer s.mu.Unlock() sd.endTime = s.endTime - sd.instrumentationLibrary = s.tracer.instrumentationLibrary + sd.instrumentationScope = s.tracer.instrumentationScope sd.name = s.name sd.parent = s.parent sd.resource = s.tracer.provider.resource diff --git a/sdk/trace/trace_test.go b/sdk/trace/trace_test.go index cb3852acbdf..eac6eb1d51a 100644 --- a/sdk/trace/trace_test.go +++ b/sdk/trace/trace_test.go @@ -411,8 +411,8 @@ func TestSetSpanAttributesOnStart(t *testing.T) { attribute.String("key1", "value1"), attribute.String("key2", "value2"), }, - spanKind: trace.SpanKindInternal, - instrumentationLibrary: instrumentation.Scope{Name: "StartSpanAttribute"}, + spanKind: trace.SpanKindInternal, + instrumentationScope: instrumentation.Scope{Name: "StartSpanAttribute"}, } if diff := cmpDiff(got, want); diff != "" { t.Errorf("SetSpanAttributesOnStart: -got +want %s", diff) @@ -666,8 +666,8 @@ func TestEvents(t *testing.T) { {Name: "foo", Attributes: []attribute.KeyValue{k1v1}}, {Name: "bar", Attributes: []attribute.KeyValue{k2v2, k3v3}}, }, - spanKind: trace.SpanKindInternal, - instrumentationLibrary: instrumentation.Scope{Name: "Events"}, + spanKind: trace.SpanKindInternal, + instrumentationScope: instrumentation.Scope{Name: "Events"}, } if diff := cmpDiff(got, want); diff != "" { t.Errorf("Message Events: -got +want %s", diff) @@ -717,9 +717,9 @@ func TestEventsOverLimit(t *testing.T) { {Name: "foo", Attributes: []attribute.KeyValue{k1v1}}, {Name: "bar", Attributes: []attribute.KeyValue{k2v2, k3v3}}, }, - droppedEventCount: 2, - spanKind: trace.SpanKindInternal, - instrumentationLibrary: instrumentation.Scope{Name: "EventsOverLimit"}, + droppedEventCount: 2, + spanKind: trace.SpanKindInternal, + instrumentationScope: instrumentation.Scope{Name: "EventsOverLimit"}, } if diff := cmpDiff(got, want); diff != "" { t.Errorf("Message Event over limit: -got +want %s", diff) @@ -753,11 +753,11 @@ func TestLinks(t *testing.T) { TraceID: tid, TraceFlags: 0x1, }), - parent: sc.WithRemote(true), - name: "span0", - links: []Link{{l1.SpanContext, l1.Attributes, 0}, {l2.SpanContext, l2.Attributes, 0}}, - spanKind: trace.SpanKindInternal, - instrumentationLibrary: instrumentation.Scope{Name: "Links"}, + parent: sc.WithRemote(true), + name: "span0", + links: []Link{{l1.SpanContext, l1.Attributes, 0}, {l2.SpanContext, l2.Attributes, 0}}, + spanKind: trace.SpanKindInternal, + instrumentationScope: instrumentation.Scope{Name: "Links"}, } if diff := cmpDiff(got, want); diff != "" { t.Errorf("Link: -got +want %s", diff) @@ -811,9 +811,9 @@ func TestLinksOverLimit(t *testing.T) { {SpanContext: sc2, Attributes: []attribute.KeyValue{k2v2}, DroppedAttributeCount: 0}, {SpanContext: sc3, Attributes: []attribute.KeyValue{k3v3}, DroppedAttributeCount: 0}, }, - droppedLinkCount: 1, - spanKind: trace.SpanKindInternal, - instrumentationLibrary: instrumentation.Scope{Name: "LinksOverLimit"}, + droppedLinkCount: 1, + spanKind: trace.SpanKindInternal, + instrumentationScope: instrumentation.Scope{Name: "LinksOverLimit"}, } if diff := cmpDiff(got, want); diff != "" { t.Errorf("Link over limit: -got +want %s", diff) @@ -861,7 +861,7 @@ func TestSetSpanStatus(t *testing.T) { Code: codes.Error, Description: "Error", }, - instrumentationLibrary: instrumentation.Scope{Name: "SpanStatus"}, + instrumentationScope: instrumentation.Scope{Name: "SpanStatus"}, } if diff := cmpDiff(got, want); diff != "" { t.Errorf("SetSpanStatus: -got +want %s", diff) @@ -891,7 +891,7 @@ func TestSetSpanStatusWithoutMessageWhenStatusIsNotError(t *testing.T) { Code: codes.Ok, Description: "", }, - instrumentationLibrary: instrumentation.Scope{Name: "SpanStatus"}, + instrumentationScope: instrumentation.Scope{Name: "SpanStatus"}, } if diff := cmpDiff(got, want); diff != "" { t.Errorf("SetSpanStatus: -got +want %s", diff) @@ -1230,7 +1230,7 @@ func TestRecordError(t *testing.T) { }, }, }, - instrumentationLibrary: instrumentation.Scope{Name: "RecordError"}, + instrumentationScope: instrumentation.Scope{Name: "RecordError"}, } if diff := cmpDiff(got, want); diff != "" { t.Errorf("SpanErrorOptions: -got +want %s", diff) @@ -1274,7 +1274,7 @@ func TestRecordErrorWithStackTrace(t *testing.T) { }, }, }, - instrumentationLibrary: instrumentation.Scope{Name: "RecordError"}, + instrumentationScope: instrumentation.Scope{Name: "RecordError"}, } assert.Equal(t, got.spanContext, want.spanContext) @@ -1314,7 +1314,7 @@ func TestRecordErrorNil(t *testing.T) { Code: codes.Unset, Description: "", }, - instrumentationLibrary: instrumentation.Scope{Name: "RecordErrorNil"}, + instrumentationScope: instrumentation.Scope{Name: "RecordErrorNil"}, } if diff := cmpDiff(got, want); diff != "" { t.Errorf("SpanErrorOptions: -got +want %s", diff) @@ -1428,9 +1428,9 @@ func TestWithResource(t *testing.T) { attributes: []attribute.KeyValue{ attribute.String("key1", "value1"), }, - spanKind: trace.SpanKindInternal, - resource: tc.want, - instrumentationLibrary: instrumentation.Scope{Name: "WithResource"}, + spanKind: trace.SpanKindInternal, + resource: tc.want, + instrumentationScope: instrumentation.Scope{Name: "WithResource"}, } if diff := cmpDiff(got, want); diff != "" { t.Errorf("WithResource:\n -got +want %s", diff) @@ -1463,7 +1463,7 @@ func TestWithInstrumentationVersionAndSchema(t *testing.T) { parent: sc.WithRemote(true), name: "span0", spanKind: trace.SpanKindInternal, - instrumentationLibrary: instrumentation.Scope{ + instrumentationScope: instrumentation.Scope{ Name: "WithInstrumentationVersion", Version: "v0.1.0", SchemaURL: "https://opentelemetry.io/schemas/1.2.0", @@ -1695,8 +1695,8 @@ func TestAddEventsWithMoreAttributesThanLimit(t *testing.T) { DroppedAttributeCount: 2, }, }, - spanKind: trace.SpanKindInternal, - instrumentationLibrary: instrumentation.Scope{Name: "AddSpanEventWithOverLimitedAttributes"}, + spanKind: trace.SpanKindInternal, + instrumentationScope: instrumentation.Scope{Name: "AddSpanEventWithOverLimitedAttributes"}, } if diff := cmpDiff(got, want); diff != "" { t.Errorf("SetSpanAttributesOverLimit: -got +want %s", diff) @@ -1750,8 +1750,8 @@ func TestAddLinksWithMoreAttributesThanLimit(t *testing.T) { DroppedAttributeCount: 2, }, }, - spanKind: trace.SpanKindInternal, - instrumentationLibrary: instrumentation.Scope{Name: "Links"}, + spanKind: trace.SpanKindInternal, + instrumentationScope: instrumentation.Scope{Name: "Links"}, } if diff := cmpDiff(got, want); diff != "" { t.Errorf("Link: -got +want %s", diff) diff --git a/sdk/trace/tracer.go b/sdk/trace/tracer.go index 49baeb65387..f4a1f96f3d6 100644 --- a/sdk/trace/tracer.go +++ b/sdk/trace/tracer.go @@ -23,8 +23,8 @@ import ( ) type tracer struct { - provider *TracerProvider - instrumentationLibrary instrumentation.Scope + provider *TracerProvider + instrumentationScope instrumentation.Scope } var _ trace.Tracer = &tracer{} From 5d886baf1b24a2c8b59ba5e628c2cd5bf42653ae Mon Sep 17 00:00:00 2001 From: Craig Pastro Date: Mon, 27 Jun 2022 15:50:22 -0700 Subject: [PATCH 6/9] A bit more renaming --- .../otlptrace/internal/otlptracetest/data.go | 2 +- .../span_processor_filter_example_test.go | 2 +- sdk/trace/tracetest/span.go | 70 +++++++++---------- 3 files changed, 37 insertions(+), 37 deletions(-) diff --git a/exporters/otlp/otlptrace/internal/otlptracetest/data.go b/exporters/otlp/otlptrace/internal/otlptracetest/data.go index 4e51f317c84..d039105cb29 100644 --- a/exporters/otlp/otlptrace/internal/otlptracetest/data.go +++ b/exporters/otlp/otlptrace/internal/otlptracetest/data.go @@ -54,7 +54,7 @@ func SingleReadOnlySpan() []tracesdk.ReadOnlySpan { DroppedLinks: 0, ChildSpanCount: 0, Resource: resource.NewSchemaless(attribute.String("a", "b")), - InstrumentationLibrary: instrumentation.Scope{ + InstrumentationLibrary: instrumentation.Library{ Name: "bar", Version: "0.0.0", }, diff --git a/sdk/trace/span_processor_filter_example_test.go b/sdk/trace/span_processor_filter_example_test.go index 6409bb57aaf..f5dd84e472a 100644 --- a/sdk/trace/span_processor_filter_example_test.go +++ b/sdk/trace/span_processor_filter_example_test.go @@ -67,7 +67,7 @@ func (f InstrumentationBlacklist) ForceFlush(ctx context.Context) error { return f.Next.ForceFlush(ctx) } func (f InstrumentationBlacklist) OnEnd(s ReadOnlySpan) { - if f.Blacklist != nil && f.Blacklist[s.InstrumentationLibrary().Name] { + if f.Blacklist != nil && f.Blacklist[s.InstrumentationScope().Name] { // Drop spans from this instrumentation return } diff --git a/sdk/trace/tracetest/span.go b/sdk/trace/tracetest/span.go index e8108a05a55..bfe73de9c41 100644 --- a/sdk/trace/tracetest/span.go +++ b/sdk/trace/tracetest/span.go @@ -96,29 +96,29 @@ func SpanStubFromReadOnlySpan(ro tracesdk.ReadOnlySpan) SpanStub { DroppedLinks: ro.DroppedLinks(), ChildSpanCount: ro.ChildSpanCount(), Resource: ro.Resource(), - InstrumentationLibrary: ro.InstrumentationLibrary(), + InstrumentationLibrary: ro.InstrumentationScope(), } } // Snapshot returns a read-only copy of the SpanStub. func (s SpanStub) Snapshot() tracesdk.ReadOnlySpan { return spanSnapshot{ - name: s.Name, - spanContext: s.SpanContext, - parent: s.Parent, - spanKind: s.SpanKind, - startTime: s.StartTime, - endTime: s.EndTime, - attributes: s.Attributes, - events: s.Events, - links: s.Links, - status: s.Status, - droppedAttributes: s.DroppedAttributes, - droppedEvents: s.DroppedEvents, - droppedLinks: s.DroppedLinks, - childSpanCount: s.ChildSpanCount, - resource: s.Resource, - instrumentationLibrary: s.InstrumentationLibrary, + name: s.Name, + spanContext: s.SpanContext, + parent: s.Parent, + spanKind: s.SpanKind, + startTime: s.StartTime, + endTime: s.EndTime, + attributes: s.Attributes, + events: s.Events, + links: s.Links, + status: s.Status, + droppedAttributes: s.DroppedAttributes, + droppedEvents: s.DroppedEvents, + droppedLinks: s.DroppedLinks, + childSpanCount: s.ChildSpanCount, + resource: s.Resource, + instrumentationScope: s.InstrumentationLibrary, } } @@ -126,22 +126,22 @@ type spanSnapshot struct { // Embed the interface to implement the private method. tracesdk.ReadOnlySpan - name string - spanContext trace.SpanContext - parent trace.SpanContext - spanKind trace.SpanKind - startTime time.Time - endTime time.Time - attributes []attribute.KeyValue - events []tracesdk.Event - links []tracesdk.Link - status tracesdk.Status - droppedAttributes int - droppedEvents int - droppedLinks int - childSpanCount int - resource *resource.Resource - instrumentationLibrary instrumentation.Library + name string + spanContext trace.SpanContext + parent trace.SpanContext + spanKind trace.SpanKind + startTime time.Time + endTime time.Time + attributes []attribute.KeyValue + events []tracesdk.Event + links []tracesdk.Link + status tracesdk.Status + droppedAttributes int + droppedEvents int + droppedLinks int + childSpanCount int + resource *resource.Resource + instrumentationScope instrumentation.Scope } func (s spanSnapshot) Name() string { return s.name } @@ -160,8 +160,8 @@ func (s spanSnapshot) DroppedEvents() int { return s.droppedEvents func (s spanSnapshot) ChildSpanCount() int { return s.childSpanCount } func (s spanSnapshot) Resource() *resource.Resource { return s.resource } func (s spanSnapshot) InstrumentationScope() instrumentation.Scope { - return s.instrumentationLibrary + return s.instrumentationScope } func (s spanSnapshot) InstrumentationLibrary() instrumentation.Library { - return s.instrumentationLibrary + return s.instrumentationScope } From 50d95c8e6323e95944faf6555533fc2b8360bc0b Mon Sep 17 00:00:00 2001 From: Craig Pastro Date: Tue, 28 Jun 2022 10:59:37 -0700 Subject: [PATCH 7/9] Update sdk/trace/span.go Co-authored-by: Tyler Yahn --- sdk/trace/span.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/trace/span.go b/sdk/trace/span.go index df45aa8070e..d380c2719a7 100644 --- a/sdk/trace/span.go +++ b/sdk/trace/span.go @@ -68,7 +68,7 @@ type ReadOnlySpan interface { InstrumentationScope() instrumentation.Scope // InstrumentationLibrary returns information about the instrumentation // library that created the span. - // Deprecated: please use InstrumentationScope instead + // Deprecated: please use InstrumentationScope instead. InstrumentationLibrary() instrumentation.Library // Resource returns information about the entity that produced the span. Resource() *resource.Resource From 77f270a13ebcf5baabd9b41018dfe7df0c764d1a Mon Sep 17 00:00:00 2001 From: Craig Pastro Date: Tue, 28 Jun 2022 20:59:26 -0700 Subject: [PATCH 8/9] Update based on feedback --- CHANGELOG.md | 2 ++ sdk/trace/trace_test.go | 1 + 2 files changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6f140772496..713eed7fd90 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,8 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm - The `Library` struct in the `go.opentelemetry.io/otel/sdk/instrumentation` package is deprecated. Use the equivalent `Scope` struct instead. (#2977) +- The `ReadOnlySpan.InstrumentationLibrary` method from the `go.opentelemetry.io/otel/sdk/trace` package is deprecated. + Use the equivalent `ReadOnlySpan.InstrumentationScope` method instead. (#2977) ## [1.7.0/0.30.0] - 2022-04-28 diff --git a/sdk/trace/trace_test.go b/sdk/trace/trace_test.go index eac6eb1d51a..5a1ae98ff8b 100644 --- a/sdk/trace/trace_test.go +++ b/sdk/trace/trace_test.go @@ -1570,6 +1570,7 @@ func TestReadOnlySpan(t *testing.T) { assert.Equal(t, kv.Value, ro.Events()[0].Attributes[0].Value) assert.Equal(t, codes.Ok, ro.Status().Code) assert.Equal(t, "", ro.Status().Description) + assert.Equal(t, "ReadOnlySpan", ro.InstrumentationLibrary().Name) assert.Equal(t, "ReadOnlySpan", ro.InstrumentationScope().Name) assert.Equal(t, "3", ro.InstrumentationScope().Version) assert.Equal(t, kv.Key, ro.Resource().Attributes()[0].Key) From 81575ebd3fa2aa8acb3171a40efcd47e0cddbf04 Mon Sep 17 00:00:00 2001 From: Craig Pastro Date: Tue, 28 Jun 2022 21:01:44 -0700 Subject: [PATCH 9/9] Revert change --- sdk/trace/trace_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/sdk/trace/trace_test.go b/sdk/trace/trace_test.go index 5a1ae98ff8b..58b2c04c6e8 100644 --- a/sdk/trace/trace_test.go +++ b/sdk/trace/trace_test.go @@ -1571,6 +1571,7 @@ func TestReadOnlySpan(t *testing.T) { assert.Equal(t, codes.Ok, ro.Status().Code) assert.Equal(t, "", ro.Status().Description) assert.Equal(t, "ReadOnlySpan", ro.InstrumentationLibrary().Name) + assert.Equal(t, "3", ro.InstrumentationLibrary().Version) assert.Equal(t, "ReadOnlySpan", ro.InstrumentationScope().Name) assert.Equal(t, "3", ro.InstrumentationScope().Version) assert.Equal(t, kv.Key, ro.Resource().Attributes()[0].Key)