Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove usage of deprecated instrumentation.Library in favor of Scope #3104

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions bridge/opencensus/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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})
}
Expand Down
2 changes: 1 addition & 1 deletion bridge/opencensus/exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion exporters/jaeger/jaeger_benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
}
Expand Down
8 changes: 4 additions & 4 deletions exporters/jaeger/jaeger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down Expand Up @@ -245,7 +245,7 @@ func TestSpanSnapshotToThrift(t *testing.T) {
Description: statusMessage,
},
SpanKind: trace.SpanKindClient,
InstrumentationLibrary: instrumentation.Library{
InstrumentationLibrary: instrumentation.Scope{
Name: instrLibName,
Version: instrLibVersion,
},
Expand Down Expand Up @@ -330,7 +330,7 @@ func TestSpanSnapshotToThrift(t *testing.T) {
Description: statusMessage,
},
SpanKind: trace.SpanKindInternal,
InstrumentationLibrary: instrumentation.Library{
InstrumentationLibrary: instrumentation.Scope{
Name: instrLibName,
Version: instrLibVersion,
},
Expand Down Expand Up @@ -383,7 +383,7 @@ func TestSpanSnapshotToThrift(t *testing.T) {
Description: statusMessage,
},
SpanKind: trace.SpanKindInternal,
InstrumentationLibrary: instrumentation.Library{
InstrumentationLibrary: instrumentation.Scope{
Name: instrLibName,
Version: instrLibVersion,
},
Expand Down
6 changes: 3 additions & 3 deletions exporters/otlp/otlpmetric/exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions exporters/otlp/otlpmetric/internal/otlpmetrictest/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -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")
}
2 changes: 1 addition & 1 deletion exporters/otlp/otlptrace/internal/otlptracetest/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
Expand Down
4 changes: 2 additions & 2 deletions exporters/prometheus/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion exporters/stdout/stdoutmetric/metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
6 changes: 3 additions & 3 deletions exporters/zipkin/model_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -829,15 +829,15 @@ func TestTagsTransformation(t *testing.T) {
{
name: "instrLib-empty",
data: tracetest.SpanStub{
InstrumentationLibrary: instrumentation.Library{},
InstrumentationLibrary: instrumentation.Scope{},
},
want: nil,
},
{
name: "instrLib-noversion",
data: tracetest.SpanStub{
Attributes: []attribute.KeyValue{},
InstrumentationLibrary: instrumentation.Library{
InstrumentationLibrary: instrumentation.Scope{
Name: instrLibName,
},
},
Expand All @@ -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,
},
Expand Down
14 changes: 7 additions & 7 deletions sdk/metric/controller/basic/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ var ErrControllerStarted = fmt.Errorf("controller already started")
// both "pull" and "push" configurations. This supports two distinct
// modes:
//
// - Push and Pull: Start() must be called to begin calling the exporter;
// Collect() is called periodically by a background thread after starting
// the controller.
// - Pull-Only: Start() is optional in this case, to call Collect periodically.
// If Start() is not called, Collect() can be called manually to initiate
// collection
// - Push and Pull: Start() must be called to begin calling the exporter;
// Collect() is called periodically by a background thread after starting
// the controller.
// - Pull-Only: Start() is optional in this case, to call Collect periodically.
// If Start() is not called, Collect() can be called manually to initiate
// collection
//
// The controller supports mixing push and pull access to metric data
// using the export.Reader RWLock interface. Collection will
Expand Down Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions sdk/metric/controller/controllertest/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
Expand Down
2 changes: 1 addition & 1 deletion sdk/metric/export/metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion sdk/metric/metrictest/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func (e *Exporter) Collect(ctx context.Context) error {
return err
}

return e.controller.ForEach(func(l instrumentation.Library, r export.Reader) error {
return e.controller.ForEach(func(l instrumentation.Scope, r export.Reader) error {
lib := Library{
InstrumentationName: l.Name,
InstrumentationVersion: l.Version,
Expand Down
2 changes: 1 addition & 1 deletion sdk/metric/processor/basic/basic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)))

Expand Down
28 changes: 14 additions & 14 deletions sdk/metric/processor/processortest/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@ func (f testFactory) NewCheckpointer() export.Checkpointer {
// NewProcessor returns a new testing Processor implementation.
// Verify expected outputs using Values(), e.g.:
//
// require.EqualValues(t, map[string]float64{
// "counter.sum/A=1,B=2/R=V": 100,
// }, processor.Values())
// require.EqualValues(t, map[string]float64{
// "counter.sum/A=1,B=2/R=V": 100,
// }, processor.Values())
//
// Where in the example A=1,B=2 is the encoded attributes and R=V is the
// encoded resource value.
Expand Down Expand Up @@ -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())
}

Expand Down Expand Up @@ -322,9 +322,9 @@ func (o *Output) AddAccumulation(acc export.Accumulation) error {
// New returns a new testing Exporter implementation.
// Verify exporter outputs using Values(), e.g.,:
//
// require.EqualValues(t, map[string]float64{
// "counter.sum/A=1,B=2/R=V": 100,
// }, exporter.Values())
// require.EqualValues(t, map[string]float64{
// "counter.sum/A=1,B=2/R=V": 100,
// }, exporter.Values())
//
// Where in the example A=1,B=2 is the encoded attributes and R=V is the
// encoded resource value.
Expand All @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion sdk/metric/processor/processortest/test_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
2 changes: 1 addition & 1 deletion sdk/metric/processor/reducer/reducer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())))

Expand Down
2 changes: 1 addition & 1 deletion sdk/trace/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func (s snapshot) InstrumentationScope() instrumentation.Scope {

// 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.instrumentationScope
}

Expand Down
6 changes: 3 additions & 3 deletions sdk/trace/span.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ type ReadOnlySpan interface {
// InstrumentationLibrary returns information about the instrumentation
// library that created the span.
// Deprecated: please use InstrumentationScope instead.
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
Expand Down Expand Up @@ -596,9 +596,9 @@ func (s *recordingSpan) InstrumentationScope() instrumentation.Scope {
return s.tracer.instrumentationScope
}

// 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.instrumentationScope
Expand Down
4 changes: 2 additions & 2 deletions sdk/trace/tracetest/span.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -162,6 +162,6 @@ func (s spanSnapshot) Resource() *resource.Resource { return s.resource }
func (s spanSnapshot) InstrumentationScope() instrumentation.Scope {
return s.instrumentationScope
}
func (s spanSnapshot) InstrumentationLibrary() instrumentation.Library {
func (s spanSnapshot) InstrumentationLibrary() instrumentation.Scope {
return s.instrumentationScope
}