From 8f4e0f99be579b7f10339ce6c1e2cd3bccd6a695 Mon Sep 17 00:00:00 2001 From: Tyler Yahn Date: Tue, 9 Jun 2020 15:25:53 -0700 Subject: [PATCH 01/10] Support instrumentation library in metrics --- api/global/internal/benchmark_test.go | 5 +- api/global/internal/meter.go | 27 +++-- api/global/internal/meter_test.go | 105 ++++++++++---------- api/global/metric_test.go | 2 +- api/metric/api_test.go | 4 +- api/metric/config.go | 64 +++++++++--- api/metric/descriptor.go | 13 ++- api/metric/meter.go | 19 ++-- api/metric/noop.go | 2 +- api/metric/registry/registry.go | 21 ++-- api/metric/sdkapi.go | 7 +- exporters/otlp/internal/transform/metric.go | 34 ++++--- exporters/otlp/otlp_metric_test.go | 54 ++++++++-- sdk/metric/benchmark_test.go | 4 +- sdk/metric/correct_test.go | 4 +- sdk/metric/stress_test.go | 4 +- 16 files changed, 243 insertions(+), 126 deletions(-) diff --git a/api/global/internal/benchmark_test.go b/api/global/internal/benchmark_test.go index 0f5d5437daf..b5d5fda1c74 100644 --- a/api/global/internal/benchmark_test.go +++ b/api/global/internal/benchmark_test.go @@ -25,6 +25,7 @@ import ( "go.opentelemetry.io/otel/api/metric" "go.opentelemetry.io/otel/api/trace" export "go.opentelemetry.io/otel/sdk/export/metric" + "go.opentelemetry.io/otel/sdk/instrumentation" sdk "go.opentelemetry.io/otel/sdk/metric" "go.opentelemetry.io/otel/sdk/metric/aggregator/ddsketch" "go.opentelemetry.io/otel/sdk/metric/aggregator/minmaxsumcount" @@ -51,7 +52,7 @@ func newFixture(b *testing.B) *benchFixture { } bf.accumulator = sdk.NewAccumulator(bf) - bf.meter = metric.WrapMeterImpl(bf.accumulator, "test") + bf.meter = metric.WrapMeterImpl(bf.accumulator, instrumentation.Library{Name: "test"}) return bf } @@ -82,7 +83,7 @@ func (*benchFixture) CheckpointSet() export.CheckpointSet { func (*benchFixture) FinishedCollection() { } -func (fix *benchFixture) Meter(name string) metric.Meter { +func (fix *benchFixture) Meter(_ string, _ ...metric.MeterOption) metric.Meter { return fix.meter } diff --git a/api/global/internal/meter.go b/api/global/internal/meter.go index 723def119fe..7b4e7ac59d5 100644 --- a/api/global/internal/meter.go +++ b/api/global/internal/meter.go @@ -23,6 +23,7 @@ import ( "go.opentelemetry.io/otel/api/kv" "go.opentelemetry.io/otel/api/metric" "go.opentelemetry.io/otel/api/metric/registry" + "go.opentelemetry.io/otel/sdk/instrumentation" ) // This file contains the forwarding implementation of metric.Provider @@ -54,7 +55,7 @@ type meterProvider struct { // meters maintains a unique entry for every named Meter // that has been registered through the global instance. - meters map[string]*meterEntry + meters map[instrumentation.Library]*meterEntry } type meterImpl struct { @@ -123,7 +124,7 @@ func (inst *instrument) Descriptor() metric.Descriptor { func newMeterProvider() *meterProvider { return &meterProvider{ - meters: map[string]*meterEntry{}, + meters: map[instrumentation.Library]*meterEntry{}, } } @@ -132,38 +133,42 @@ func (p *meterProvider) setDelegate(provider metric.Provider) { defer p.lock.Unlock() p.delegate = provider - for name, entry := range p.meters { - entry.impl.setDelegate(name, provider) + for il, entry := range p.meters { + entry.impl.setDelegate(il, provider) } p.meters = nil } -func (p *meterProvider) Meter(name string) metric.Meter { +func (p *meterProvider) Meter(instrumentationName string, opts ...metric.MeterOption) metric.Meter { p.lock.Lock() defer p.lock.Unlock() if p.delegate != nil { - return p.delegate.Meter(name) + return p.delegate.Meter(instrumentationName, opts...) } - entry, ok := p.meters[name] + il := instrumentation.Library{ + Name: instrumentationName, + Version: metric.MeterConfigure(opts).InstrumentationVersion, + } + entry, ok := p.meters[il] if !ok { entry = &meterEntry{} entry.unique = registry.NewUniqueInstrumentMeterImpl(&entry.impl) - p.meters[name] = entry + p.meters[il] = entry } - return metric.WrapMeterImpl(entry.unique, name) + return metric.WrapMeterImpl(entry.unique, il) } // Meter interface and delegation -func (m *meterImpl) setDelegate(name string, provider metric.Provider) { +func (m *meterImpl) setDelegate(il instrumentation.Library, provider metric.Provider) { m.lock.Lock() defer m.lock.Unlock() d := new(metric.MeterImpl) - *d = provider.Meter(name).MeterImpl() + *d = provider.Meter(il.Name, metric.WithInstrumentationVersion(il.Version)).MeterImpl() m.delegate = unsafe.Pointer(d) for _, inst := range m.syncInsts { diff --git a/api/global/internal/meter_test.go b/api/global/internal/meter_test.go index 013a3d5a2e2..4d7fb555fec 100644 --- a/api/global/internal/meter_test.go +++ b/api/global/internal/meter_test.go @@ -23,6 +23,7 @@ import ( "testing" "go.opentelemetry.io/otel/api/kv/value" + "go.opentelemetry.io/otel/sdk/instrumentation" "github.com/stretchr/testify/require" @@ -36,10 +37,10 @@ import ( // Note: Maybe this should be factored into ../../../internal/metric? type measured struct { - Name string - LibraryName string - Labels map[kv.Key]value.Value - Number metric.Number + Name string + InstrumentationLibrary instrumentation.Library + Labels map[kv.Key]value.Value + Number metric.Number } func asStructs(batches []metrictest.Batch) []measured { @@ -47,10 +48,10 @@ func asStructs(batches []metrictest.Batch) []measured { for _, batch := range batches { for _, m := range batch.Measurements { r = append(r, measured{ - Name: m.Instrument.Descriptor().Name(), - LibraryName: m.Instrument.Descriptor().LibraryName(), - Labels: asMap(batch.Labels...), - Number: m.Number, + Name: m.Instrument.Descriptor().Name(), + InstrumentationLibrary: m.Instrument.Descriptor().InstrumentationLibrary(), + Labels: asMap(batch.Labels...), + Number: m.Number, }) } } @@ -114,46 +115,46 @@ func TestDirect(t *testing.T) { require.EqualValues(t, []measured{ { - Name: "test.counter", - LibraryName: "test1", - Labels: asMap(labels1...), - Number: asInt(1), + Name: "test.counter", + InstrumentationLibrary: instrumentation.Library{Name: "test1"}, + Labels: asMap(labels1...), + Number: asInt(1), }, { - Name: "test.valuerecorder", - LibraryName: "test1", - Labels: asMap(labels1...), - Number: asFloat(3), + Name: "test.valuerecorder", + InstrumentationLibrary: instrumentation.Library{Name: "test1"}, + Labels: asMap(labels1...), + Number: asFloat(3), }, { - Name: "test.second", - LibraryName: "test2", - Labels: asMap(labels3...), - Number: asFloat(3), + Name: "test.second", + InstrumentationLibrary: instrumentation.Library{Name: "test2"}, + Labels: asMap(labels3...), + Number: asFloat(3), }, { - Name: "test.valueobserver.float", - LibraryName: "test1", - Labels: asMap(labels1...), - Number: asFloat(1), + Name: "test.valueobserver.float", + InstrumentationLibrary: instrumentation.Library{Name: "test1"}, + Labels: asMap(labels1...), + Number: asFloat(1), }, { - Name: "test.valueobserver.float", - LibraryName: "test1", - Labels: asMap(labels2...), - Number: asFloat(2), + Name: "test.valueobserver.float", + InstrumentationLibrary: instrumentation.Library{Name: "test1"}, + Labels: asMap(labels2...), + Number: asFloat(2), }, { - Name: "test.valueobserver.int", - LibraryName: "test1", - Labels: asMap(labels1...), - Number: asInt(1), + Name: "test.valueobserver.int", + InstrumentationLibrary: instrumentation.Library{Name: "test1"}, + Labels: asMap(labels1...), + Number: asInt(1), }, { - Name: "test.valueobserver.int", - LibraryName: "test1", - Labels: asMap(labels2...), - Number: asInt(2), + Name: "test.valueobserver.int", + InstrumentationLibrary: instrumentation.Library{Name: "test1"}, + Labels: asMap(labels2...), + Number: asInt(2), }, }, measurements, @@ -188,16 +189,16 @@ func TestBound(t *testing.T) { require.EqualValues(t, []measured{ { - Name: "test.counter", - LibraryName: "test", - Labels: asMap(labels1...), - Number: asFloat(1), + Name: "test.counter", + InstrumentationLibrary: instrumentation.Library{Name: "test"}, + Labels: asMap(labels1...), + Number: asFloat(1), }, { - Name: "test.valuerecorder", - LibraryName: "test", - Labels: asMap(labels1...), - Number: asInt(3), + Name: "test.valuerecorder", + InstrumentationLibrary: instrumentation.Library{Name: "test"}, + Labels: asMap(labels1...), + Number: asInt(3), }, }, asStructs(mock.MeasurementBatches)) @@ -284,8 +285,12 @@ type meterWithConstructorError struct { metric.MeterImpl } -func (m *meterProviderWithConstructorError) Meter(name string) metric.Meter { - return metric.WrapMeterImpl(&meterWithConstructorError{m.Provider.Meter(name).MeterImpl()}, name) +func (m *meterProviderWithConstructorError) Meter(instrumentationName string, opts ...metric.MeterOption) metric.Meter { + il := instrumentation.Library{ + Name: instrumentationName, + Version: metric.MeterConfigure(opts).InstrumentationVersion, + } + return metric.WrapMeterImpl(&meterWithConstructorError{m.Provider.Meter(instrumentationName, opts...).MeterImpl()}, il) } func (m *meterWithConstructorError) NewSyncInstrument(_ metric.Descriptor) (metric.SyncImpl, error) { @@ -380,10 +385,10 @@ func TestRecordBatchMock(t *testing.T) { require.EqualValues(t, []measured{ { - Name: "test.counter", - LibraryName: "builtin", - Labels: asMap(), - Number: asInt(1), + Name: "test.counter", + InstrumentationLibrary: instrumentation.Library{Name: "builtin"}, + Labels: asMap(), + Number: asInt(1), }, }, asStructs(mock.MeasurementBatches)) diff --git a/api/global/metric_test.go b/api/global/metric_test.go index e5b77befa6c..2262a32ac91 100644 --- a/api/global/metric_test.go +++ b/api/global/metric_test.go @@ -25,7 +25,7 @@ type testMeterProvider struct{} var _ metric.Provider = &testMeterProvider{} -func (*testMeterProvider) Meter(_ string) metric.Meter { +func (*testMeterProvider) Meter(_ string, _ ...metric.MeterOption) metric.Meter { return metric.Meter{} } diff --git a/api/metric/api_test.go b/api/metric/api_test.go index ca702788286..bae2cdb2b51 100644 --- a/api/metric/api_test.go +++ b/api/metric/api_test.go @@ -25,6 +25,7 @@ import ( "go.opentelemetry.io/otel/api/oterror" "go.opentelemetry.io/otel/api/unit" mockTest "go.opentelemetry.io/otel/internal/metric" + "go.opentelemetry.io/otel/sdk/instrumentation" "github.com/google/go-cmp/cmp" "github.com/stretchr/testify/assert" @@ -388,7 +389,8 @@ func (testWrappedMeter) NewAsyncInstrument(_ metric.Descriptor, _ metric.AsyncRu func TestWrappedInstrumentError(t *testing.T) { impl := &testWrappedMeter{} - meter := metric.WrapMeterImpl(impl, "test") + il := instrumentation.Library{Name: "test"} + meter := metric.WrapMeterImpl(impl, il) valuerecorder, err := meter.NewInt64ValueRecorder("test.valuerecorder") diff --git a/api/metric/config.go b/api/metric/config.go index 30a3f8a0bd6..d80be25fd77 100644 --- a/api/metric/config.go +++ b/api/metric/config.go @@ -14,7 +14,10 @@ package metric -import "go.opentelemetry.io/otel/api/unit" +import ( + "go.opentelemetry.io/otel/api/unit" + "go.opentelemetry.io/otel/sdk/instrumentation" +) // Config contains some options for metrics of any kind. type Config struct { @@ -23,9 +26,9 @@ type Config struct { Description string // Unit is an optional field describing the metric instrument. Unit unit.Unit - // LibraryName is the name given to the Meter that created - // this instrument. See `Provider`. - LibraryName string + // InstrumentationLibrary describes the library that provided + // instrumentation. + InstrumentationLibrary instrumentation.Library } // Option is an interface for applying metric options. @@ -65,20 +68,55 @@ func (u unitOption) Apply(config *Config) { config.Unit = unit.Unit(u) } -// WithLibraryName applies provided library name. This is meant for -// use in `Provider` implementations that have not used -// `WrapMeterImpl`. Implementations built using `WrapMeterImpl` have -// instrument descriptors taken care of through this package. +// WithInstrumentationLibrary sets the library used to provided +// instrumentation. This is meant for use in `Provider` implementations that +// have not used `WrapMeterImpl`. Implementations built using +// `WrapMeterImpl` have instrument descriptors taken care of through this +// package. // // This option will have no effect when supplied by the user. // Provider implementations are expected to append this option after // the user-supplied options when building instrument descriptors. -func WithLibraryName(name string) Option { - return libraryNameOption(name) +func WithInstrumentationLibrary(il instrumentation.Library) Option { + return instrumentationLibraryOption(il) } -type libraryNameOption string +type instrumentationLibraryOption instrumentation.Library -func (r libraryNameOption) Apply(config *Config) { - config.LibraryName = string(r) +func (i instrumentationLibraryOption) Apply(config *Config) { + config.InstrumentationLibrary = instrumentation.Library(i) +} + +// Config contains options for a Meter. +type MeterConfig struct { + // InstrumentationVersion is the version of the library providing + // instrumentation. + InstrumentationVersion string +} + +// MeterOption is an interface for applying meter options. +type MeterOption interface { + // Apply is used to set the MeterOption value of a MeterConfig. + Apply(*MeterConfig) +} + +// MeterConfigure is a helper that applies all the MeterOptions to a +// MeterConfig. +func MeterConfigure(opts []MeterOption) MeterConfig { + var config MeterConfig + for _, o := range opts { + o.Apply(&config) + } + return config +} + +// WithInstrumentationVersion sets the instrumentation version. +func WithInstrumentationVersion(version string) MeterOption { + return instrumentationVersionOption(version) +} + +type instrumentationVersionOption string + +func (i instrumentationVersionOption) Apply(config *MeterConfig) { + config.InstrumentationVersion = string(i) } diff --git a/api/metric/descriptor.go b/api/metric/descriptor.go index a87cd6d75ed..9153c96414b 100644 --- a/api/metric/descriptor.go +++ b/api/metric/descriptor.go @@ -14,7 +14,10 @@ package metric -import "go.opentelemetry.io/otel/api/unit" +import ( + "go.opentelemetry.io/otel/api/unit" + "go.opentelemetry.io/otel/sdk/instrumentation" +) // Descriptor contains all the settings that describe an instrument, // including its name, metric kind, number kind, and the configurable @@ -64,8 +67,8 @@ func (d Descriptor) NumberKind() NumberKind { return d.numberKind } -// LibraryName returns the metric instrument's library name, typically -// given via a call to Provider.Meter(). -func (d Descriptor) LibraryName() string { - return d.config.LibraryName +// InstrumentationLibrary returns the instrumentation.Library describing the +// library that provided instrumentation of this instrument. +func (d Descriptor) InstrumentationLibrary() instrumentation.Library { + return d.config.InstrumentationLibrary } diff --git a/api/metric/meter.go b/api/metric/meter.go index 200431f24e9..dfc77d7f274 100644 --- a/api/metric/meter.go +++ b/api/metric/meter.go @@ -18,6 +18,7 @@ import ( "context" "go.opentelemetry.io/otel/api/kv" + "go.opentelemetry.io/otel/sdk/instrumentation" ) // The file is organized as follows: @@ -33,9 +34,13 @@ import ( // Provider supports named Meter instances. type Provider interface { - // Meter gets a named Meter interface. If the name is an - // empty string, the provider uses a default name. - Meter(name string) Meter + // Meter creates an implementation of the Meter interface. + // The instrumentationName must be the name of the library providing + // instrumentation. This name may be the same as the instrumented code + // only if that code provides built-in instrumentation. If the + // instrumentationName is empty, then a implementation defined default + // name will be used instead. + Meter(instrumentationName string, opts ...MeterOption) Meter } // Meter is the OpenTelemetry metric API, based on a `MeterImpl` @@ -43,8 +48,8 @@ type Provider interface { // // An uninitialized Meter is a no-op implementation. type Meter struct { - impl MeterImpl - libraryName string + impl MeterImpl + il instrumentation.Library } // RecordBatch atomically records a batch of measurements. @@ -291,7 +296,7 @@ func (m Meter) newAsync( return NoopAsync{}, nil } desc := NewDescriptor(name, mkind, nkind, opts...) - desc.config.LibraryName = m.libraryName + desc.config.InstrumentationLibrary = m.il return m.impl.NewAsyncInstrument(desc, runner) } @@ -309,6 +314,6 @@ func (m Meter) newSync( return NoopSync{}, nil } desc := NewDescriptor(name, metricKind, numberKind, opts...) - desc.config.LibraryName = m.libraryName + desc.config.InstrumentationLibrary = m.il return m.impl.NewSyncInstrument(desc) } diff --git a/api/metric/noop.go b/api/metric/noop.go index 54d659c541f..9a54ebc5b00 100644 --- a/api/metric/noop.go +++ b/api/metric/noop.go @@ -32,7 +32,7 @@ var _ SyncImpl = NoopSync{} var _ BoundSyncImpl = noopBoundInstrument{} var _ AsyncImpl = NoopAsync{} -func (NoopProvider) Meter(name string) Meter { +func (NoopProvider) Meter(_ string, _ ...MeterOption) Meter { return Meter{} } diff --git a/api/metric/registry/registry.go b/api/metric/registry/registry.go index 56b1878613c..2fd183211c1 100644 --- a/api/metric/registry/registry.go +++ b/api/metric/registry/registry.go @@ -21,6 +21,7 @@ import ( "go.opentelemetry.io/otel/api/kv" "go.opentelemetry.io/otel/api/metric" + "go.opentelemetry.io/otel/sdk/instrumentation" ) // Provider is a standard metric.Provider for wrapping `MeterImpl` @@ -42,8 +43,8 @@ type uniqueInstrumentMeterImpl struct { var _ metric.MeterImpl = (*uniqueInstrumentMeterImpl)(nil) type key struct { - name string - libraryName string + name string + il instrumentation.Library } // NewProvider returns a new provider that implements instrument @@ -55,8 +56,12 @@ func NewProvider(impl metric.MeterImpl) *Provider { } // Meter implements metric.Provider. -func (p *Provider) Meter(name string) metric.Meter { - return metric.WrapMeterImpl(p.impl, name) +func (p *Provider) Meter(instrumentationName string, opts ...metric.MeterOption) metric.Meter { + il := instrumentation.Library{ + Name: instrumentationName, + Version: metric.MeterConfigure(opts).InstrumentationVersion, + } + return metric.WrapMeterImpl(p.impl, il) } // ErrMetricKindMismatch is the standard error for mismatched metric @@ -81,16 +86,18 @@ func (u *uniqueInstrumentMeterImpl) RecordBatch(ctx context.Context, labels []kv func keyOf(descriptor metric.Descriptor) key { return key{ descriptor.Name(), - descriptor.LibraryName(), + descriptor.InstrumentationLibrary(), } } // NewMetricKindMismatchError formats an error that describes a // mismatched metric instrument definition. func NewMetricKindMismatchError(desc metric.Descriptor) error { - return fmt.Errorf("Metric was %s (%s) registered as a %s %s: %w", + il := desc.InstrumentationLibrary() + return fmt.Errorf("Metric was %s (%s %s) registered as a %s %s: %w", desc.Name(), - desc.LibraryName(), + il.Name, + il.Version, desc.NumberKind(), desc.MetricKind(), ErrMetricKindMismatch) diff --git a/api/metric/sdkapi.go b/api/metric/sdkapi.go index c7a6fe4c52a..7df8a73e353 100644 --- a/api/metric/sdkapi.go +++ b/api/metric/sdkapi.go @@ -18,6 +18,7 @@ import ( "context" "go.opentelemetry.io/otel/api/kv" + "go.opentelemetry.io/otel/sdk/instrumentation" ) // MeterImpl is the interface an SDK must implement to supply a Meter @@ -85,9 +86,9 @@ type AsyncImpl interface { // WrapMeterImpl constructs a `Meter` implementation from a // `MeterImpl` implementation. -func WrapMeterImpl(impl MeterImpl, libraryName string) Meter { +func WrapMeterImpl(impl MeterImpl, il instrumentation.Library) Meter { return Meter{ - impl: impl, - libraryName: libraryName, + impl: impl, + il: il, } } diff --git a/exporters/otlp/internal/transform/metric.go b/exporters/otlp/internal/transform/metric.go index 318378961bc..bf581899e66 100644 --- a/exporters/otlp/internal/transform/metric.go +++ b/exporters/otlp/internal/transform/metric.go @@ -31,6 +31,7 @@ import ( "go.opentelemetry.io/otel/api/metric" export "go.opentelemetry.io/otel/sdk/export/metric" "go.opentelemetry.io/otel/sdk/export/metric/aggregator" + "go.opentelemetry.io/otel/sdk/instrumentation" "go.opentelemetry.io/otel/sdk/resource" ) @@ -53,10 +54,10 @@ var ( // result is the product of transforming Records into OTLP Metrics. type result struct { - Resource *resource.Resource - Library string - Metric *metricpb.Metric - Err error + Resource *resource.Resource + InstrumentationLibrary instrumentation.Library + Metric *metricpb.Metric + Err error } // CheckpointSet transforms all records contained in a checkpoint into @@ -124,10 +125,10 @@ func transformer(ctx context.Context, in <-chan export.Record, out chan<- result continue } res := result{ - Resource: r.Resource(), - Library: r.Descriptor().LibraryName(), - Metric: m, - Err: err, + Resource: r.Resource(), + InstrumentationLibrary: r.Descriptor().InstrumentationLibrary(), + Metric: m, + Err: err, } select { case <-ctx.Done(): @@ -148,7 +149,7 @@ func sink(ctx context.Context, in <-chan result) ([]*metricpb.ResourceMetrics, e type resourceBatch struct { Resource *resourcepb.Resource // Group by instrumentation library name and then the MetricDescriptor. - InstrumentationLibraryBatches map[string]map[string]*metricpb.Metric + InstrumentationLibraryBatches map[instrumentation.Library]map[string]*metricpb.Metric } // group by unique Resource string. @@ -164,15 +165,15 @@ func sink(ctx context.Context, in <-chan result) ([]*metricpb.ResourceMetrics, e if !ok { rb = resourceBatch{ Resource: Resource(res.Resource), - InstrumentationLibraryBatches: make(map[string]map[string]*metricpb.Metric), + InstrumentationLibraryBatches: make(map[instrumentation.Library]map[string]*metricpb.Metric), } grouped[rID] = rb } - mb, ok := rb.InstrumentationLibraryBatches[res.Library] + mb, ok := rb.InstrumentationLibraryBatches[res.InstrumentationLibrary] if !ok { mb = make(map[string]*metricpb.Metric) - rb.InstrumentationLibraryBatches[res.Library] = mb + rb.InstrumentationLibraryBatches[res.InstrumentationLibrary] = mb } mID := res.Metric.GetMetricDescriptor().String() @@ -202,12 +203,15 @@ func sink(ctx context.Context, in <-chan result) ([]*metricpb.ResourceMetrics, e var rms []*metricpb.ResourceMetrics for _, rb := range grouped { rm := &metricpb.ResourceMetrics{Resource: rb.Resource} - for ilName, mb := range rb.InstrumentationLibraryBatches { + for il, mb := range rb.InstrumentationLibraryBatches { ilm := &metricpb.InstrumentationLibraryMetrics{ Metrics: make([]*metricpb.Metric, 0, len(mb)), } - if ilName != "" { - ilm.InstrumentationLibrary = &commonpb.InstrumentationLibrary{Name: ilName} + if il != (instrumentation.Library{}) { + ilm.InstrumentationLibrary = &commonpb.InstrumentationLibrary{ + Name: il.Name, + Version: il.Version, + } } for _, m := range mb { ilm.Metrics = append(ilm.Metrics, m) diff --git a/exporters/otlp/otlp_metric_test.go b/exporters/otlp/otlp_metric_test.go index 4d90c5f024b..a8287ba0c0a 100644 --- a/exporters/otlp/otlp_metric_test.go +++ b/exporters/otlp/otlp_metric_test.go @@ -31,6 +31,7 @@ import ( "go.opentelemetry.io/otel/api/metric" metricsdk "go.opentelemetry.io/otel/sdk/export/metric" "go.opentelemetry.io/otel/sdk/export/metric/aggregator" + "go.opentelemetry.io/otel/sdk/instrumentation" "go.opentelemetry.io/otel/sdk/metric/aggregator/minmaxsumcount" "go.opentelemetry.io/otel/sdk/metric/aggregator/sum" "go.opentelemetry.io/otel/sdk/resource" @@ -489,6 +490,17 @@ func TestResourceMetricGroupingExport(t *testing.T) { } func TestResourceInstLibMetricGroupingExport(t *testing.T) { + countingLib1 := instrumentation.Library{ + Name: "couting-lib", + Version: "v1", + } + countingLib2 := instrumentation.Library{ + Name: "couting-lib", + Version: "v2", + } + summingLib := instrumentation.Library{ + Name: "summing-lib", + } runMetricExportTests( t, []record{ @@ -498,7 +510,7 @@ func TestResourceInstLibMetricGroupingExport(t *testing.T) { metric.Int64NumberKind, testInstA, []metric.Option{ - metric.WithLibraryName("couting-lib"), + metric.WithInstrumentationLibrary(countingLib1), }, append(baseKeyValues, cpuKey.Int(1)), }, @@ -508,7 +520,7 @@ func TestResourceInstLibMetricGroupingExport(t *testing.T) { metric.Int64NumberKind, testInstA, []metric.Option{ - metric.WithLibraryName("couting-lib"), + metric.WithInstrumentationLibrary(countingLib2), }, append(baseKeyValues, cpuKey.Int(1)), }, @@ -518,7 +530,17 @@ func TestResourceInstLibMetricGroupingExport(t *testing.T) { metric.Int64NumberKind, testInstA, []metric.Option{ - metric.WithLibraryName("couting-lib"), + metric.WithInstrumentationLibrary(countingLib1), + }, + append(baseKeyValues, cpuKey.Int(1)), + }, + { + "int64-count", + metric.CounterKind, + metric.Int64NumberKind, + testInstA, + []metric.Option{ + metric.WithInstrumentationLibrary(countingLib1), }, append(baseKeyValues, cpuKey.Int(2)), }, @@ -528,7 +550,7 @@ func TestResourceInstLibMetricGroupingExport(t *testing.T) { metric.Int64NumberKind, testInstA, []metric.Option{ - metric.WithLibraryName("summing-lib"), + metric.WithInstrumentationLibrary(summingLib), }, append(baseKeyValues, cpuKey.Int(1)), }, @@ -538,7 +560,7 @@ func TestResourceInstLibMetricGroupingExport(t *testing.T) { metric.Int64NumberKind, testInstB, []metric.Option{ - metric.WithLibraryName("couting-lib"), + metric.WithInstrumentationLibrary(countingLib1), }, append(baseKeyValues, cpuKey.Int(1)), }, @@ -549,7 +571,8 @@ func TestResourceInstLibMetricGroupingExport(t *testing.T) { InstrumentationLibraryMetrics: []*metricpb.InstrumentationLibraryMetrics{ { InstrumentationLibrary: &commonpb.InstrumentationLibrary{ - Name: "couting-lib", + Name: "couting-lib", + Version: "v1", }, Metrics: []*metricpb.Metric{ { @@ -573,6 +596,22 @@ func TestResourceInstLibMetricGroupingExport(t *testing.T) { }, }, }, + { + InstrumentationLibrary: &commonpb.InstrumentationLibrary{ + Name: "couting-lib", + Version: "v2", + }, + Metrics: []*metricpb.Metric{ + { + MetricDescriptor: cpu1MD, + Int64DataPoints: []*metricpb.Int64DataPoint{ + { + Value: 11, + }, + }, + }, + }, + }, { InstrumentationLibrary: &commonpb.InstrumentationLibrary{ Name: "summing-lib", @@ -595,7 +634,8 @@ func TestResourceInstLibMetricGroupingExport(t *testing.T) { InstrumentationLibraryMetrics: []*metricpb.InstrumentationLibraryMetrics{ { InstrumentationLibrary: &commonpb.InstrumentationLibrary{ - Name: "couting-lib", + Name: "couting-lib", + Version: "v1", }, Metrics: []*metricpb.Metric{ { diff --git a/sdk/metric/benchmark_test.go b/sdk/metric/benchmark_test.go index 2f880705f0a..14de813956e 100644 --- a/sdk/metric/benchmark_test.go +++ b/sdk/metric/benchmark_test.go @@ -25,6 +25,7 @@ import ( "go.opentelemetry.io/otel/api/label" "go.opentelemetry.io/otel/api/metric" export "go.opentelemetry.io/otel/sdk/export/metric" + "go.opentelemetry.io/otel/sdk/instrumentation" sdk "go.opentelemetry.io/otel/sdk/metric" "go.opentelemetry.io/otel/sdk/metric/aggregator/ddsketch" "go.opentelemetry.io/otel/sdk/metric/aggregator/lastvalue" @@ -45,7 +46,8 @@ func newFixture(b *testing.B) *benchFixture { } bf.accumulator = sdk.NewAccumulator(bf) - bf.meter = metric.Must(metric.WrapMeterImpl(bf.accumulator, "benchmarks")) + il := instrumentation.Library{Name: "benchmarks"} + bf.meter = metric.Must(metric.WrapMeterImpl(bf.accumulator, il)) return bf } diff --git a/sdk/metric/correct_test.go b/sdk/metric/correct_test.go index ac5b35c4a0d..889c7e55363 100644 --- a/sdk/metric/correct_test.go +++ b/sdk/metric/correct_test.go @@ -31,6 +31,7 @@ import ( "go.opentelemetry.io/otel/api/metric" export "go.opentelemetry.io/otel/sdk/export/metric" "go.opentelemetry.io/otel/sdk/export/metric/aggregator" + "go.opentelemetry.io/otel/sdk/instrumentation" metricsdk "go.opentelemetry.io/otel/sdk/metric" "go.opentelemetry.io/otel/sdk/metric/aggregator/array" "go.opentelemetry.io/otel/sdk/metric/aggregator/sum" @@ -90,7 +91,8 @@ func newSDK(t *testing.T) (metric.Meter, *metricsdk.Accumulator, *correctnessInt integrator, metricsdk.WithResource(testResource), ) - meter := metric.WrapMeterImpl(accum, "test") + il := instrumentation.Library{Name: "test"} + meter := metric.WrapMeterImpl(accum, il) return meter, accum, integrator } diff --git a/sdk/metric/stress_test.go b/sdk/metric/stress_test.go index 92094de340a..4392c3d3878 100644 --- a/sdk/metric/stress_test.go +++ b/sdk/metric/stress_test.go @@ -36,6 +36,7 @@ import ( api "go.opentelemetry.io/otel/api/metric" export "go.opentelemetry.io/otel/sdk/export/metric" "go.opentelemetry.io/otel/sdk/export/metric/aggregator" + "go.opentelemetry.io/otel/sdk/instrumentation" "go.opentelemetry.io/otel/sdk/metric/aggregator/lastvalue" "go.opentelemetry.io/otel/sdk/metric/aggregator/sum" ) @@ -307,7 +308,8 @@ func stressTest(t *testing.T, impl testImpl) { } cc := concurrency() sdk := NewAccumulator(fixture) - meter := metric.WrapMeterImpl(sdk, "stress_test") + il := instrumentation.Library{Name: "stress_test"} + meter := metric.WrapMeterImpl(sdk, il) fixture.wg.Add(cc + 1) for i := 0; i < cc; i++ { From bb93b6ed6f2fe3ff0f33a2e5540d99a680ec0800 Mon Sep 17 00:00:00 2001 From: Tyler Yahn Date: Wed, 10 Jun 2020 09:59:17 -0700 Subject: [PATCH 02/10] Update stdout exporter to display instrumentation info --- exporters/metric/stdout/example_test.go | 7 +++++-- exporters/metric/stdout/stdout.go | 19 +++++++++++++++++-- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/exporters/metric/stdout/example_test.go b/exporters/metric/stdout/example_test.go index 306a9f50126..60861cdc27d 100644 --- a/exporters/metric/stdout/example_test.go +++ b/exporters/metric/stdout/example_test.go @@ -37,7 +37,10 @@ func ExampleNewExportPipeline() { ctx := context.Background() key := kv.Key("key") - meter := pusher.Provider().Meter("example") + meter := pusher.Provider().Meter( + "github.com/instrumentron", + metric.WithInstrumentationVersion("v0.1.0"), + ) // Create and update a single counter: counter := metric.Must(meter).NewInt64Counter("a.counter") @@ -49,7 +52,7 @@ func ExampleNewExportPipeline() { // { // "updates": [ // { - // "name": "a.counter{key=value}", + // "name": "a.counter{instrumentation.name=github.com/instrumentron,instrumentation.version=v0.1.0,key=value}", // "sum": 100 // } // ] diff --git a/exporters/metric/stdout/stdout.go b/exporters/metric/stdout/stdout.go index 270edaa0245..d1e4141d80b 100644 --- a/exporters/metric/stdout/stdout.go +++ b/exporters/metric/stdout/stdout.go @@ -24,6 +24,7 @@ import ( "time" "go.opentelemetry.io/otel/api/global" + "go.opentelemetry.io/otel/api/kv" "go.opentelemetry.io/otel/api/label" export "go.opentelemetry.io/otel/sdk/export/metric" @@ -162,6 +163,16 @@ func (e *Exporter) Export(_ context.Context, checkpointSet export.CheckpointSet) kind := desc.NumberKind() encodedResource := record.Resource().Encoded(e.config.LabelEncoder) + var instLabels []kv.KeyValue + if il := desc.InstrumentationLibrary(); il.Name != "" { + instLabels = append(instLabels, kv.String("instrumentation.name", il.Name)) + if il.Version != "" { + instLabels = append(instLabels, kv.String("instrumentation.version", il.Version)) + } + } + instSet := label.NewSet(instLabels...) + encodedInstLabels := instSet.Encoded(e.config.LabelEncoder) + var expose expoLine if sum, ok := agg.(aggregator.Sum); ok { @@ -230,10 +241,14 @@ func (e *Exporter) Export(_ context.Context, checkpointSet export.CheckpointSet) sb.WriteString(desc.Name()) - if len(encodedLabels) > 0 || len(encodedResource) > 0 { + if len(encodedLabels) > 0 || len(encodedResource) > 0 || len(encodedInstLabels) > 0 { sb.WriteRune('{') sb.WriteString(encodedResource) - if len(encodedLabels) > 0 && len(encodedResource) > 0 { + if len(encodedInstLabels) > 0 && len(encodedResource) > 0 { + sb.WriteRune(',') + } + sb.WriteString(encodedInstLabels) + if len(encodedLabels) > 0 && (len(encodedInstLabels) > 0 || len(encodedResource) > 0) { sb.WriteRune(',') } sb.WriteString(encodedLabels) From 39bd71543072e5d0b53b20df497dbe0e2acfd921 Mon Sep 17 00:00:00 2001 From: Tyler Yahn Date: Wed, 10 Jun 2020 10:11:08 -0700 Subject: [PATCH 03/10] Fix tests that use the STDOUT exporter --- api/global/internal/meter_test.go | 4 ++-- sdk/metric/example_test.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/api/global/internal/meter_test.go b/api/global/internal/meter_test.go index 4d7fb555fec..9e31faf8dbf 100644 --- a/api/global/internal/meter_test.go +++ b/api/global/internal/meter_test.go @@ -255,7 +255,7 @@ func TestDefaultSDK(t *testing.T) { pusher.Stop() out.Close() - require.Equal(t, `{"updates":[{"name":"test.builtin{A=B}","sum":1}]} + require.Equal(t, `{"updates":[{"name":"test.builtin{instrumentation.name=builtin,A=B}","sum":1}]} `, <-ch) } @@ -417,6 +417,6 @@ func TestRecordBatchRealSDK(t *testing.T) { meter.RecordBatch(context.Background(), nil, counter.Measurement(1)) pusher.Stop() - require.Equal(t, `{"updates":[{"name":"test.counter","sum":1}]} + require.Equal(t, `{"updates":[{"name":"test.counter{instrumentation.name=builtin}","sum":1}]} `, buf.String()) } diff --git a/sdk/metric/example_test.go b/sdk/metric/example_test.go index d76766c7e11..a48b8dfb46c 100644 --- a/sdk/metric/example_test.go +++ b/sdk/metric/example_test.go @@ -47,7 +47,7 @@ func ExampleNew() { // { // "updates": [ // { - // "name": "a.counter{key=value}", + // "name": "a.counter{instrumentation.name=example,key=value}", // "sum": 100 // } // ] From 9e526f06371f84f5aed6a35b3f80347347e841f9 Mon Sep 17 00:00:00 2001 From: Tyler Yahn Date: Wed, 10 Jun 2020 20:38:00 -0700 Subject: [PATCH 04/10] Refactor to keep SDK out of API --- api/global/internal/benchmark_test.go | 3 +- api/global/internal/meter.go | 27 +++--- api/global/internal/meter_test.go | 95 ++++++++++----------- api/metric/api_test.go | 16 ++-- api/metric/config.go | 91 ++++++++++---------- api/metric/descriptor.go | 21 +++-- api/metric/meter.go | 51 +++++------ api/metric/must.go | 36 ++++---- api/metric/registry/registry.go | 22 ++--- api/metric/sdkapi.go | 8 +- exporters/metric/stdout/stdout.go | 8 +- exporters/otlp/internal/transform/metric.go | 11 ++- exporters/otlp/otlp_metric_test.go | 49 ++++------- sdk/metric/benchmark_test.go | 4 +- sdk/metric/correct_test.go | 4 +- sdk/metric/stress_test.go | 4 +- 16 files changed, 219 insertions(+), 231 deletions(-) diff --git a/api/global/internal/benchmark_test.go b/api/global/internal/benchmark_test.go index b5d5fda1c74..ed0af9d7196 100644 --- a/api/global/internal/benchmark_test.go +++ b/api/global/internal/benchmark_test.go @@ -25,7 +25,6 @@ import ( "go.opentelemetry.io/otel/api/metric" "go.opentelemetry.io/otel/api/trace" export "go.opentelemetry.io/otel/sdk/export/metric" - "go.opentelemetry.io/otel/sdk/instrumentation" sdk "go.opentelemetry.io/otel/sdk/metric" "go.opentelemetry.io/otel/sdk/metric/aggregator/ddsketch" "go.opentelemetry.io/otel/sdk/metric/aggregator/minmaxsumcount" @@ -52,7 +51,7 @@ func newFixture(b *testing.B) *benchFixture { } bf.accumulator = sdk.NewAccumulator(bf) - bf.meter = metric.WrapMeterImpl(bf.accumulator, instrumentation.Library{Name: "test"}) + bf.meter = metric.WrapMeterImpl(bf.accumulator, "test") return bf } diff --git a/api/global/internal/meter.go b/api/global/internal/meter.go index 7b4e7ac59d5..43f28227c6d 100644 --- a/api/global/internal/meter.go +++ b/api/global/internal/meter.go @@ -23,7 +23,6 @@ import ( "go.opentelemetry.io/otel/api/kv" "go.opentelemetry.io/otel/api/metric" "go.opentelemetry.io/otel/api/metric/registry" - "go.opentelemetry.io/otel/sdk/instrumentation" ) // This file contains the forwarding implementation of metric.Provider @@ -47,6 +46,10 @@ import ( // Metric uniqueness checking is implemented by calling the exported // methods of the api/metric/registry package. +type meterKey struct { + Name, Version string +} + type meterProvider struct { delegate metric.Provider @@ -55,7 +58,7 @@ type meterProvider struct { // meters maintains a unique entry for every named Meter // that has been registered through the global instance. - meters map[instrumentation.Library]*meterEntry + meters map[meterKey]*meterEntry } type meterImpl struct { @@ -124,7 +127,7 @@ func (inst *instrument) Descriptor() metric.Descriptor { func newMeterProvider() *meterProvider { return &meterProvider{ - meters: map[instrumentation.Library]*meterEntry{}, + meters: map[meterKey]*meterEntry{}, } } @@ -133,8 +136,8 @@ func (p *meterProvider) setDelegate(provider metric.Provider) { defer p.lock.Unlock() p.delegate = provider - for il, entry := range p.meters { - entry.impl.setDelegate(il, provider) + for key, entry := range p.meters { + entry.impl.setDelegate(key.Name, key.Version, provider) } p.meters = nil } @@ -147,28 +150,28 @@ func (p *meterProvider) Meter(instrumentationName string, opts ...metric.MeterOp return p.delegate.Meter(instrumentationName, opts...) } - il := instrumentation.Library{ + key := meterKey{ Name: instrumentationName, - Version: metric.MeterConfigure(opts).InstrumentationVersion, + Version: metric.ConfigureMeter(opts).InstrumentationVersion, } - entry, ok := p.meters[il] + entry, ok := p.meters[key] if !ok { entry = &meterEntry{} entry.unique = registry.NewUniqueInstrumentMeterImpl(&entry.impl) - p.meters[il] = entry + p.meters[key] = entry } - return metric.WrapMeterImpl(entry.unique, il) + return metric.WrapMeterImpl(entry.unique, key.Name, metric.WithInstrumentationVersion(key.Version)) } // Meter interface and delegation -func (m *meterImpl) setDelegate(il instrumentation.Library, provider metric.Provider) { +func (m *meterImpl) setDelegate(name, version string, provider metric.Provider) { m.lock.Lock() defer m.lock.Unlock() d := new(metric.MeterImpl) - *d = provider.Meter(il.Name, metric.WithInstrumentationVersion(il.Version)).MeterImpl() + *d = provider.Meter(name, metric.WithInstrumentationVersion(version)).MeterImpl() m.delegate = unsafe.Pointer(d) for _, inst := range m.syncInsts { diff --git a/api/global/internal/meter_test.go b/api/global/internal/meter_test.go index 9e31faf8dbf..71a6d7e9c61 100644 --- a/api/global/internal/meter_test.go +++ b/api/global/internal/meter_test.go @@ -23,7 +23,6 @@ import ( "testing" "go.opentelemetry.io/otel/api/kv/value" - "go.opentelemetry.io/otel/sdk/instrumentation" "github.com/stretchr/testify/require" @@ -38,7 +37,8 @@ import ( // Note: Maybe this should be factored into ../../../internal/metric? type measured struct { Name string - InstrumentationLibrary instrumentation.Library + InstrumentationName string + InstrumentationVersion string Labels map[kv.Key]value.Value Number metric.Number } @@ -49,7 +49,8 @@ func asStructs(batches []metrictest.Batch) []measured { for _, m := range batch.Measurements { r = append(r, measured{ Name: m.Instrument.Descriptor().Name(), - InstrumentationLibrary: m.Instrument.Descriptor().InstrumentationLibrary(), + InstrumentationName: m.Instrument.Descriptor().InstrumentationName(), + InstrumentationVersion: m.Instrument.Descriptor().InstrumentationVersion(), Labels: asMap(batch.Labels...), Number: m.Number, }) @@ -115,46 +116,46 @@ func TestDirect(t *testing.T) { require.EqualValues(t, []measured{ { - Name: "test.counter", - InstrumentationLibrary: instrumentation.Library{Name: "test1"}, - Labels: asMap(labels1...), - Number: asInt(1), + Name: "test.counter", + InstrumentationName: "test1", + Labels: asMap(labels1...), + Number: asInt(1), }, { - Name: "test.valuerecorder", - InstrumentationLibrary: instrumentation.Library{Name: "test1"}, - Labels: asMap(labels1...), - Number: asFloat(3), + Name: "test.valuerecorder", + InstrumentationName: "test1", + Labels: asMap(labels1...), + Number: asFloat(3), }, { - Name: "test.second", - InstrumentationLibrary: instrumentation.Library{Name: "test2"}, - Labels: asMap(labels3...), - Number: asFloat(3), + Name: "test.second", + InstrumentationName: "test2", + Labels: asMap(labels3...), + Number: asFloat(3), }, { - Name: "test.valueobserver.float", - InstrumentationLibrary: instrumentation.Library{Name: "test1"}, - Labels: asMap(labels1...), - Number: asFloat(1), + Name: "test.valueobserver.float", + InstrumentationName: "test1", + Labels: asMap(labels1...), + Number: asFloat(1), }, { - Name: "test.valueobserver.float", - InstrumentationLibrary: instrumentation.Library{Name: "test1"}, - Labels: asMap(labels2...), - Number: asFloat(2), + Name: "test.valueobserver.float", + InstrumentationName: "test1", + Labels: asMap(labels2...), + Number: asFloat(2), }, { - Name: "test.valueobserver.int", - InstrumentationLibrary: instrumentation.Library{Name: "test1"}, - Labels: asMap(labels1...), - Number: asInt(1), + Name: "test.valueobserver.int", + InstrumentationName: "test1", + Labels: asMap(labels1...), + Number: asInt(1), }, { - Name: "test.valueobserver.int", - InstrumentationLibrary: instrumentation.Library{Name: "test1"}, - Labels: asMap(labels2...), - Number: asInt(2), + Name: "test.valueobserver.int", + InstrumentationName: "test1", + Labels: asMap(labels2...), + Number: asInt(2), }, }, measurements, @@ -189,16 +190,16 @@ func TestBound(t *testing.T) { require.EqualValues(t, []measured{ { - Name: "test.counter", - InstrumentationLibrary: instrumentation.Library{Name: "test"}, - Labels: asMap(labels1...), - Number: asFloat(1), + Name: "test.counter", + InstrumentationName: "test", + Labels: asMap(labels1...), + Number: asFloat(1), }, { - Name: "test.valuerecorder", - InstrumentationLibrary: instrumentation.Library{Name: "test"}, - Labels: asMap(labels1...), - Number: asInt(3), + Name: "test.valuerecorder", + InstrumentationName: "test", + Labels: asMap(labels1...), + Number: asInt(3), }, }, asStructs(mock.MeasurementBatches)) @@ -285,12 +286,8 @@ type meterWithConstructorError struct { metric.MeterImpl } -func (m *meterProviderWithConstructorError) Meter(instrumentationName string, opts ...metric.MeterOption) metric.Meter { - il := instrumentation.Library{ - Name: instrumentationName, - Version: metric.MeterConfigure(opts).InstrumentationVersion, - } - return metric.WrapMeterImpl(&meterWithConstructorError{m.Provider.Meter(instrumentationName, opts...).MeterImpl()}, il) +func (m *meterProviderWithConstructorError) Meter(iName string, opts ...metric.MeterOption) metric.Meter { + return metric.WrapMeterImpl(&meterWithConstructorError{m.Provider.Meter(iName, opts...).MeterImpl()}, iName, opts...) } func (m *meterWithConstructorError) NewSyncInstrument(_ metric.Descriptor) (metric.SyncImpl, error) { @@ -385,10 +382,10 @@ func TestRecordBatchMock(t *testing.T) { require.EqualValues(t, []measured{ { - Name: "test.counter", - InstrumentationLibrary: instrumentation.Library{Name: "builtin"}, - Labels: asMap(), - Number: asInt(1), + Name: "test.counter", + InstrumentationName: "builtin", + Labels: asMap(), + Number: asInt(1), }, }, asStructs(mock.MeasurementBatches)) diff --git a/api/metric/api_test.go b/api/metric/api_test.go index bae2cdb2b51..4375a2b3197 100644 --- a/api/metric/api_test.go +++ b/api/metric/api_test.go @@ -25,7 +25,6 @@ import ( "go.opentelemetry.io/otel/api/oterror" "go.opentelemetry.io/otel/api/unit" mockTest "go.opentelemetry.io/otel/internal/metric" - "go.opentelemetry.io/otel/sdk/instrumentation" "github.com/google/go-cmp/cmp" "github.com/stretchr/testify/assert" @@ -37,7 +36,7 @@ var Must = metric.Must func TestOptions(t *testing.T) { type testcase struct { name string - opts []metric.Option + opts []metric.InstrumentOption desc string unit unit.Unit } @@ -50,7 +49,7 @@ func TestOptions(t *testing.T) { }, { name: "description", - opts: []metric.Option{ + opts: []metric.InstrumentOption{ metric.WithDescription("stuff"), }, desc: "stuff", @@ -58,7 +57,7 @@ func TestOptions(t *testing.T) { }, { name: "description override", - opts: []metric.Option{ + opts: []metric.InstrumentOption{ metric.WithDescription("stuff"), metric.WithDescription("things"), }, @@ -67,7 +66,7 @@ func TestOptions(t *testing.T) { }, { name: "unit", - opts: []metric.Option{ + opts: []metric.InstrumentOption{ metric.WithUnit("s"), }, desc: "", @@ -75,7 +74,7 @@ func TestOptions(t *testing.T) { }, { name: "unit override", - opts: []metric.Option{ + opts: []metric.InstrumentOption{ metric.WithUnit("s"), metric.WithUnit("h"), }, @@ -85,7 +84,7 @@ func TestOptions(t *testing.T) { } for idx, tt := range testcases { t.Logf("Testing counter case %s (%d)", tt.name, idx) - if diff := cmp.Diff(metric.Configure(tt.opts), metric.Config{ + if diff := cmp.Diff(metric.ConfigureInstrument(tt.opts), metric.InstrumentConfig{ Description: tt.desc, Unit: tt.unit, }); diff != "" { @@ -389,8 +388,7 @@ func (testWrappedMeter) NewAsyncInstrument(_ metric.Descriptor, _ metric.AsyncRu func TestWrappedInstrumentError(t *testing.T) { impl := &testWrappedMeter{} - il := instrumentation.Library{Name: "test"} - meter := metric.WrapMeterImpl(impl, il) + meter := metric.WrapMeterImpl(impl, "test") valuerecorder, err := meter.NewInt64ValueRecorder("test.valuerecorder") diff --git a/api/metric/config.go b/api/metric/config.go index d80be25fd77..8ff0394d120 100644 --- a/api/metric/config.go +++ b/api/metric/config.go @@ -16,107 +16,112 @@ package metric import ( "go.opentelemetry.io/otel/api/unit" - "go.opentelemetry.io/otel/sdk/instrumentation" ) -// Config contains some options for metrics of any kind. -type Config struct { - // Description is an optional field describing the metric - // instrument. +// InstrumentConfig contains options for instrument descriptors. +type InstrumentConfig struct { + // Description describes the metric instrument in human-readable terms. Description string - // Unit is an optional field describing the metric instrument. + // Unit describing the measurement unit for a metric instrument. Unit unit.Unit - // InstrumentationLibrary describes the library that provided + // InstrumentationName is the name of the library providing // instrumentation. - InstrumentationLibrary instrumentation.Library + InstrumentationName string + // InstrumentationVersion is the version of the library providing + // instrumentation. + InstrumentationVersion string } -// Option is an interface for applying metric options. -type Option interface { - // Apply is used to set the Option value of a Config. - Apply(*Config) +// InstrumentOption is an interface for applying metric options. +type InstrumentOption interface { + // ApplyMeter is used to set a InstrumentOption value of a + // InstrumentConfig. + ApplyInstrument(*InstrumentConfig) } -// Configure is a helper that applies all the options to a Config. -func Configure(opts []Option) Config { - var config Config +// ConfigureInstrument is a helper that applies all the InstrumentOptions +// to a InstrumentConfig. +func ConfigureInstrument(opts []InstrumentOption) InstrumentConfig { + var config InstrumentConfig for _, o := range opts { - o.Apply(&config) + o.ApplyInstrument(&config) } return config } // WithDescription applies provided description. -func WithDescription(desc string) Option { +func WithDescription(desc string) InstrumentOption { return descriptionOption(desc) } type descriptionOption string -func (d descriptionOption) Apply(config *Config) { +func (d descriptionOption) ApplyInstrument(config *InstrumentConfig) { config.Description = string(d) } // WithUnit applies provided unit. -func WithUnit(unit unit.Unit) Option { +func WithUnit(unit unit.Unit) InstrumentOption { return unitOption(unit) } type unitOption unit.Unit -func (u unitOption) Apply(config *Config) { +func (u unitOption) ApplyInstrument(config *InstrumentConfig) { config.Unit = unit.Unit(u) } -// WithInstrumentationLibrary sets the library used to provided -// instrumentation. This is meant for use in `Provider` implementations that -// have not used `WrapMeterImpl`. Implementations built using -// `WrapMeterImpl` have instrument descriptors taken care of through this -// package. -// -// This option will have no effect when supplied by the user. -// Provider implementations are expected to append this option after -// the user-supplied options when building instrument descriptors. -func WithInstrumentationLibrary(il instrumentation.Library) Option { - return instrumentationLibraryOption(il) +// WithInstrumentationName sets the instrumentation name. +func WithInstrumentationName(name string) InstrumentOption { + return instrumentationNameOption(name) } -type instrumentationLibraryOption instrumentation.Library +type instrumentationNameOption string -func (i instrumentationLibraryOption) Apply(config *Config) { - config.InstrumentationLibrary = instrumentation.Library(i) +func (i instrumentationNameOption) ApplyInstrument(config *InstrumentConfig) { + config.InstrumentationName = string(i) } -// Config contains options for a Meter. +// MeterConfig contains options for Meters. type MeterConfig struct { // InstrumentationVersion is the version of the library providing // instrumentation. InstrumentationVersion string } -// MeterOption is an interface for applying meter options. +// MeterOption is an interface for applying Meter options. type MeterOption interface { - // Apply is used to set the MeterOption value of a MeterConfig. - Apply(*MeterConfig) + // ApplyMeter is used to set a MeterOption value of a MeterConfig. + ApplyMeter(*MeterConfig) } -// MeterConfigure is a helper that applies all the MeterOptions to a +// ConfigureMeter is a helper that applies all the MeterOptions to a // MeterConfig. -func MeterConfigure(opts []MeterOption) MeterConfig { +func ConfigureMeter(opts []MeterOption) MeterConfig { var config MeterConfig for _, o := range opts { - o.Apply(&config) + o.ApplyMeter(&config) } return config } +// Option is an interface for applying Instrument or Meter options. +type Option interface { + InstrumentOption + MeterOption +} + // WithInstrumentationVersion sets the instrumentation version. -func WithInstrumentationVersion(version string) MeterOption { +func WithInstrumentationVersion(version string) Option { return instrumentationVersionOption(version) } type instrumentationVersionOption string -func (i instrumentationVersionOption) Apply(config *MeterConfig) { +func (i instrumentationVersionOption) ApplyMeter(config *MeterConfig) { + config.InstrumentationVersion = string(i) +} + +func (i instrumentationVersionOption) ApplyInstrument(config *InstrumentConfig) { config.InstrumentationVersion = string(i) } diff --git a/api/metric/descriptor.go b/api/metric/descriptor.go index 9153c96414b..9218f09a333 100644 --- a/api/metric/descriptor.go +++ b/api/metric/descriptor.go @@ -16,7 +16,6 @@ package metric import ( "go.opentelemetry.io/otel/api/unit" - "go.opentelemetry.io/otel/sdk/instrumentation" ) // Descriptor contains all the settings that describe an instrument, @@ -26,16 +25,16 @@ type Descriptor struct { name string kind Kind numberKind NumberKind - config Config + config InstrumentConfig } // NewDescriptor returns a Descriptor with the given contents. -func NewDescriptor(name string, mkind Kind, nkind NumberKind, opts ...Option) Descriptor { +func NewDescriptor(name string, mkind Kind, nkind NumberKind, opts ...InstrumentOption) Descriptor { return Descriptor{ name: name, kind: mkind, numberKind: nkind, - config: Configure(opts), + config: ConfigureInstrument(opts), } } @@ -67,8 +66,14 @@ func (d Descriptor) NumberKind() NumberKind { return d.numberKind } -// InstrumentationLibrary returns the instrumentation.Library describing the -// library that provided instrumentation of this instrument. -func (d Descriptor) InstrumentationLibrary() instrumentation.Library { - return d.config.InstrumentationLibrary +// InstrumentationName returns the name of the library that provided +// instrumentation for this instrument. +func (d Descriptor) InstrumentationName() string { + return d.config.InstrumentationName +} + +// InstrumentationVersion returns the version of the library that provided +// instrumentation for this instrument. +func (d Descriptor) InstrumentationVersion() string { + return d.config.InstrumentationVersion } diff --git a/api/metric/meter.go b/api/metric/meter.go index dfc77d7f274..eacfb68a464 100644 --- a/api/metric/meter.go +++ b/api/metric/meter.go @@ -18,7 +18,6 @@ import ( "context" "go.opentelemetry.io/otel/api/kv" - "go.opentelemetry.io/otel/sdk/instrumentation" ) // The file is organized as follows: @@ -48,8 +47,8 @@ type Provider interface { // // An uninitialized Meter is a no-op implementation. type Meter struct { - impl MeterImpl - il instrumentation.Library + impl MeterImpl + name, version string } // RecordBatch atomically records a batch of measurements. @@ -73,7 +72,7 @@ func (m Meter) NewBatchObserver(callback BatchObserverCallback) BatchObserver { // given name, customized with options. May return an error if the // name is invalid (e.g., empty) or improperly registered (e.g., // duplicate registration). -func (m Meter) NewInt64Counter(name string, options ...Option) (Int64Counter, error) { +func (m Meter) NewInt64Counter(name string, options ...InstrumentOption) (Int64Counter, error) { return wrapInt64CounterInstrument( m.newSync(name, CounterKind, Int64NumberKind, options)) } @@ -82,7 +81,7 @@ func (m Meter) NewInt64Counter(name string, options ...Option) (Int64Counter, er // given name, customized with options. May return an error if the // name is invalid (e.g., empty) or improperly registered (e.g., // duplicate registration). -func (m Meter) NewFloat64Counter(name string, options ...Option) (Float64Counter, error) { +func (m Meter) NewFloat64Counter(name string, options ...InstrumentOption) (Float64Counter, error) { return wrapFloat64CounterInstrument( m.newSync(name, CounterKind, Float64NumberKind, options)) } @@ -91,7 +90,7 @@ func (m Meter) NewFloat64Counter(name string, options ...Option) (Float64Counter // given name, customized with options. May return an error if the // name is invalid (e.g., empty) or improperly registered (e.g., // duplicate registration). -func (m Meter) NewInt64UpDownCounter(name string, options ...Option) (Int64UpDownCounter, error) { +func (m Meter) NewInt64UpDownCounter(name string, options ...InstrumentOption) (Int64UpDownCounter, error) { return wrapInt64UpDownCounterInstrument( m.newSync(name, UpDownCounterKind, Int64NumberKind, options)) } @@ -100,7 +99,7 @@ func (m Meter) NewInt64UpDownCounter(name string, options ...Option) (Int64UpDow // given name, customized with options. May return an error if the // name is invalid (e.g., empty) or improperly registered (e.g., // duplicate registration). -func (m Meter) NewFloat64UpDownCounter(name string, options ...Option) (Float64UpDownCounter, error) { +func (m Meter) NewFloat64UpDownCounter(name string, options ...InstrumentOption) (Float64UpDownCounter, error) { return wrapFloat64UpDownCounterInstrument( m.newSync(name, UpDownCounterKind, Float64NumberKind, options)) } @@ -109,7 +108,7 @@ func (m Meter) NewFloat64UpDownCounter(name string, options ...Option) (Float64U // given name, customized with options. May return an error if the // name is invalid (e.g., empty) or improperly registered (e.g., // duplicate registration). -func (m Meter) NewInt64ValueRecorder(name string, opts ...Option) (Int64ValueRecorder, error) { +func (m Meter) NewInt64ValueRecorder(name string, opts ...InstrumentOption) (Int64ValueRecorder, error) { return wrapInt64ValueRecorderInstrument( m.newSync(name, ValueRecorderKind, Int64NumberKind, opts)) } @@ -118,7 +117,7 @@ func (m Meter) NewInt64ValueRecorder(name string, opts ...Option) (Int64ValueRec // given name, customized with options. May return an error if the // name is invalid (e.g., empty) or improperly registered (e.g., // duplicate registration). -func (m Meter) NewFloat64ValueRecorder(name string, opts ...Option) (Float64ValueRecorder, error) { +func (m Meter) NewFloat64ValueRecorder(name string, opts ...InstrumentOption) (Float64ValueRecorder, error) { return wrapFloat64ValueRecorderInstrument( m.newSync(name, ValueRecorderKind, Float64NumberKind, opts)) } @@ -127,7 +126,7 @@ func (m Meter) NewFloat64ValueRecorder(name string, opts ...Option) (Float64Valu // with the given name, running a given callback, and customized with // options. May return an error if the name is invalid (e.g., empty) // or improperly registered (e.g., duplicate registration). -func (m Meter) NewInt64ValueObserver(name string, callback Int64ObserverCallback, opts ...Option) (Int64ValueObserver, error) { +func (m Meter) NewInt64ValueObserver(name string, callback Int64ObserverCallback, opts ...InstrumentOption) (Int64ValueObserver, error) { if callback == nil { return wrapInt64ValueObserverInstrument(NoopAsync{}, nil) } @@ -140,7 +139,7 @@ func (m Meter) NewInt64ValueObserver(name string, callback Int64ObserverCallback // the given name, running a given callback, and customized with // options. May return an error if the name is invalid (e.g., empty) // or improperly registered (e.g., duplicate registration). -func (m Meter) NewFloat64ValueObserver(name string, callback Float64ObserverCallback, opts ...Option) (Float64ValueObserver, error) { +func (m Meter) NewFloat64ValueObserver(name string, callback Float64ObserverCallback, opts ...InstrumentOption) (Float64ValueObserver, error) { if callback == nil { return wrapFloat64ValueObserverInstrument(NoopAsync{}, nil) } @@ -153,7 +152,7 @@ func (m Meter) NewFloat64ValueObserver(name string, callback Float64ObserverCall // with the given name, running a given callback, and customized with // options. May return an error if the name is invalid (e.g., empty) // or improperly registered (e.g., duplicate registration). -func (m Meter) NewInt64SumObserver(name string, callback Int64ObserverCallback, opts ...Option) (Int64SumObserver, error) { +func (m Meter) NewInt64SumObserver(name string, callback Int64ObserverCallback, opts ...InstrumentOption) (Int64SumObserver, error) { if callback == nil { return wrapInt64SumObserverInstrument(NoopAsync{}, nil) } @@ -166,7 +165,7 @@ func (m Meter) NewInt64SumObserver(name string, callback Int64ObserverCallback, // the given name, running a given callback, and customized with // options. May return an error if the name is invalid (e.g., empty) // or improperly registered (e.g., duplicate registration). -func (m Meter) NewFloat64SumObserver(name string, callback Float64ObserverCallback, opts ...Option) (Float64SumObserver, error) { +func (m Meter) NewFloat64SumObserver(name string, callback Float64ObserverCallback, opts ...InstrumentOption) (Float64SumObserver, error) { if callback == nil { return wrapFloat64SumObserverInstrument(NoopAsync{}, nil) } @@ -179,7 +178,7 @@ func (m Meter) NewFloat64SumObserver(name string, callback Float64ObserverCallba // with the given name, running a given callback, and customized with // options. May return an error if the name is invalid (e.g., empty) // or improperly registered (e.g., duplicate registration). -func (m Meter) NewInt64UpDownSumObserver(name string, callback Int64ObserverCallback, opts ...Option) (Int64UpDownSumObserver, error) { +func (m Meter) NewInt64UpDownSumObserver(name string, callback Int64ObserverCallback, opts ...InstrumentOption) (Int64UpDownSumObserver, error) { if callback == nil { return wrapInt64UpDownSumObserverInstrument(NoopAsync{}, nil) } @@ -192,7 +191,7 @@ func (m Meter) NewInt64UpDownSumObserver(name string, callback Int64ObserverCall // the given name, running a given callback, and customized with // options. May return an error if the name is invalid (e.g., empty) // or improperly registered (e.g., duplicate registration). -func (m Meter) NewFloat64UpDownSumObserver(name string, callback Float64ObserverCallback, opts ...Option) (Float64UpDownSumObserver, error) { +func (m Meter) NewFloat64UpDownSumObserver(name string, callback Float64ObserverCallback, opts ...InstrumentOption) (Float64UpDownSumObserver, error) { if callback == nil { return wrapFloat64UpDownSumObserverInstrument(NoopAsync{}, nil) } @@ -205,7 +204,7 @@ func (m Meter) NewFloat64UpDownSumObserver(name string, callback Float64Observer // with the given name, running in a batch callback, and customized with // options. May return an error if the name is invalid (e.g., empty) // or improperly registered (e.g., duplicate registration). -func (b BatchObserver) NewInt64ValueObserver(name string, opts ...Option) (Int64ValueObserver, error) { +func (b BatchObserver) NewInt64ValueObserver(name string, opts ...InstrumentOption) (Int64ValueObserver, error) { if b.runner == nil { return wrapInt64ValueObserverInstrument(NoopAsync{}, nil) } @@ -217,7 +216,7 @@ func (b BatchObserver) NewInt64ValueObserver(name string, opts ...Option) (Int64 // the given name, running in a batch callback, and customized with // options. May return an error if the name is invalid (e.g., empty) // or improperly registered (e.g., duplicate registration). -func (b BatchObserver) NewFloat64ValueObserver(name string, opts ...Option) (Float64ValueObserver, error) { +func (b BatchObserver) NewFloat64ValueObserver(name string, opts ...InstrumentOption) (Float64ValueObserver, error) { if b.runner == nil { return wrapFloat64ValueObserverInstrument(NoopAsync{}, nil) } @@ -230,7 +229,7 @@ func (b BatchObserver) NewFloat64ValueObserver(name string, opts ...Option) (Flo // with the given name, running in a batch callback, and customized with // options. May return an error if the name is invalid (e.g., empty) // or improperly registered (e.g., duplicate registration). -func (b BatchObserver) NewInt64SumObserver(name string, opts ...Option) (Int64SumObserver, error) { +func (b BatchObserver) NewInt64SumObserver(name string, opts ...InstrumentOption) (Int64SumObserver, error) { if b.runner == nil { return wrapInt64SumObserverInstrument(NoopAsync{}, nil) } @@ -242,7 +241,7 @@ func (b BatchObserver) NewInt64SumObserver(name string, opts ...Option) (Int64Su // the given name, running in a batch callback, and customized with // options. May return an error if the name is invalid (e.g., empty) // or improperly registered (e.g., duplicate registration). -func (b BatchObserver) NewFloat64SumObserver(name string, opts ...Option) (Float64SumObserver, error) { +func (b BatchObserver) NewFloat64SumObserver(name string, opts ...InstrumentOption) (Float64SumObserver, error) { if b.runner == nil { return wrapFloat64SumObserverInstrument(NoopAsync{}, nil) } @@ -255,7 +254,7 @@ func (b BatchObserver) NewFloat64SumObserver(name string, opts ...Option) (Float // with the given name, running in a batch callback, and customized with // options. May return an error if the name is invalid (e.g., empty) // or improperly registered (e.g., duplicate registration). -func (b BatchObserver) NewInt64UpDownSumObserver(name string, opts ...Option) (Int64UpDownSumObserver, error) { +func (b BatchObserver) NewInt64UpDownSumObserver(name string, opts ...InstrumentOption) (Int64UpDownSumObserver, error) { if b.runner == nil { return wrapInt64UpDownSumObserverInstrument(NoopAsync{}, nil) } @@ -267,7 +266,7 @@ func (b BatchObserver) NewInt64UpDownSumObserver(name string, opts ...Option) (I // the given name, running in a batch callback, and customized with // options. May return an error if the name is invalid (e.g., empty) // or improperly registered (e.g., duplicate registration). -func (b BatchObserver) NewFloat64UpDownSumObserver(name string, opts ...Option) (Float64UpDownSumObserver, error) { +func (b BatchObserver) NewFloat64UpDownSumObserver(name string, opts ...InstrumentOption) (Float64UpDownSumObserver, error) { if b.runner == nil { return wrapFloat64UpDownSumObserverInstrument(NoopAsync{}, nil) } @@ -286,7 +285,7 @@ func (m Meter) newAsync( name string, mkind Kind, nkind NumberKind, - opts []Option, + opts []InstrumentOption, runner AsyncRunner, ) ( AsyncImpl, @@ -296,7 +295,8 @@ func (m Meter) newAsync( return NoopAsync{}, nil } desc := NewDescriptor(name, mkind, nkind, opts...) - desc.config.InstrumentationLibrary = m.il + desc.config.InstrumentationName = m.name + desc.config.InstrumentationVersion = m.version return m.impl.NewAsyncInstrument(desc, runner) } @@ -305,7 +305,7 @@ func (m Meter) newSync( name string, metricKind Kind, numberKind NumberKind, - opts []Option, + opts []InstrumentOption, ) ( SyncImpl, error, @@ -314,6 +314,7 @@ func (m Meter) newSync( return NoopSync{}, nil } desc := NewDescriptor(name, metricKind, numberKind, opts...) - desc.config.InstrumentationLibrary = m.il + desc.config.InstrumentationName = m.name + desc.config.InstrumentationVersion = m.version return m.impl.NewSyncInstrument(desc) } diff --git a/api/metric/must.go b/api/metric/must.go index c409c6b55fc..13c40a87b0b 100644 --- a/api/metric/must.go +++ b/api/metric/must.go @@ -35,7 +35,7 @@ func Must(meter Meter) MeterMust { // NewInt64Counter calls `Meter.NewInt64Counter` and returns the // instrument, panicking if it encounters an error. -func (mm MeterMust) NewInt64Counter(name string, cos ...Option) Int64Counter { +func (mm MeterMust) NewInt64Counter(name string, cos ...InstrumentOption) Int64Counter { if inst, err := mm.meter.NewInt64Counter(name, cos...); err != nil { panic(err) } else { @@ -45,7 +45,7 @@ func (mm MeterMust) NewInt64Counter(name string, cos ...Option) Int64Counter { // NewFloat64Counter calls `Meter.NewFloat64Counter` and returns the // instrument, panicking if it encounters an error. -func (mm MeterMust) NewFloat64Counter(name string, cos ...Option) Float64Counter { +func (mm MeterMust) NewFloat64Counter(name string, cos ...InstrumentOption) Float64Counter { if inst, err := mm.meter.NewFloat64Counter(name, cos...); err != nil { panic(err) } else { @@ -55,7 +55,7 @@ func (mm MeterMust) NewFloat64Counter(name string, cos ...Option) Float64Counter // NewInt64UpDownCounter calls `Meter.NewInt64UpDownCounter` and returns the // instrument, panicking if it encounters an error. -func (mm MeterMust) NewInt64UpDownCounter(name string, cos ...Option) Int64UpDownCounter { +func (mm MeterMust) NewInt64UpDownCounter(name string, cos ...InstrumentOption) Int64UpDownCounter { if inst, err := mm.meter.NewInt64UpDownCounter(name, cos...); err != nil { panic(err) } else { @@ -65,7 +65,7 @@ func (mm MeterMust) NewInt64UpDownCounter(name string, cos ...Option) Int64UpDow // NewFloat64UpDownCounter calls `Meter.NewFloat64UpDownCounter` and returns the // instrument, panicking if it encounters an error. -func (mm MeterMust) NewFloat64UpDownCounter(name string, cos ...Option) Float64UpDownCounter { +func (mm MeterMust) NewFloat64UpDownCounter(name string, cos ...InstrumentOption) Float64UpDownCounter { if inst, err := mm.meter.NewFloat64UpDownCounter(name, cos...); err != nil { panic(err) } else { @@ -75,7 +75,7 @@ func (mm MeterMust) NewFloat64UpDownCounter(name string, cos ...Option) Float64U // NewInt64ValueRecorder calls `Meter.NewInt64ValueRecorder` and returns the // instrument, panicking if it encounters an error. -func (mm MeterMust) NewInt64ValueRecorder(name string, mos ...Option) Int64ValueRecorder { +func (mm MeterMust) NewInt64ValueRecorder(name string, mos ...InstrumentOption) Int64ValueRecorder { if inst, err := mm.meter.NewInt64ValueRecorder(name, mos...); err != nil { panic(err) } else { @@ -85,7 +85,7 @@ func (mm MeterMust) NewInt64ValueRecorder(name string, mos ...Option) Int64Value // NewFloat64ValueRecorder calls `Meter.NewFloat64ValueRecorder` and returns the // instrument, panicking if it encounters an error. -func (mm MeterMust) NewFloat64ValueRecorder(name string, mos ...Option) Float64ValueRecorder { +func (mm MeterMust) NewFloat64ValueRecorder(name string, mos ...InstrumentOption) Float64ValueRecorder { if inst, err := mm.meter.NewFloat64ValueRecorder(name, mos...); err != nil { panic(err) } else { @@ -95,7 +95,7 @@ func (mm MeterMust) NewFloat64ValueRecorder(name string, mos ...Option) Float64V // NewInt64ValueObserver calls `Meter.NewInt64ValueObserver` and // returns the instrument, panicking if it encounters an error. -func (mm MeterMust) NewInt64ValueObserver(name string, callback Int64ObserverCallback, oos ...Option) Int64ValueObserver { +func (mm MeterMust) NewInt64ValueObserver(name string, callback Int64ObserverCallback, oos ...InstrumentOption) Int64ValueObserver { if inst, err := mm.meter.NewInt64ValueObserver(name, callback, oos...); err != nil { panic(err) } else { @@ -105,7 +105,7 @@ func (mm MeterMust) NewInt64ValueObserver(name string, callback Int64ObserverCal // NewFloat64ValueObserver calls `Meter.NewFloat64ValueObserver` and // returns the instrument, panicking if it encounters an error. -func (mm MeterMust) NewFloat64ValueObserver(name string, callback Float64ObserverCallback, oos ...Option) Float64ValueObserver { +func (mm MeterMust) NewFloat64ValueObserver(name string, callback Float64ObserverCallback, oos ...InstrumentOption) Float64ValueObserver { if inst, err := mm.meter.NewFloat64ValueObserver(name, callback, oos...); err != nil { panic(err) } else { @@ -115,7 +115,7 @@ func (mm MeterMust) NewFloat64ValueObserver(name string, callback Float64Observe // NewInt64SumObserver calls `Meter.NewInt64SumObserver` and // returns the instrument, panicking if it encounters an error. -func (mm MeterMust) NewInt64SumObserver(name string, callback Int64ObserverCallback, oos ...Option) Int64SumObserver { +func (mm MeterMust) NewInt64SumObserver(name string, callback Int64ObserverCallback, oos ...InstrumentOption) Int64SumObserver { if inst, err := mm.meter.NewInt64SumObserver(name, callback, oos...); err != nil { panic(err) } else { @@ -125,7 +125,7 @@ func (mm MeterMust) NewInt64SumObserver(name string, callback Int64ObserverCallb // NewFloat64SumObserver calls `Meter.NewFloat64SumObserver` and // returns the instrument, panicking if it encounters an error. -func (mm MeterMust) NewFloat64SumObserver(name string, callback Float64ObserverCallback, oos ...Option) Float64SumObserver { +func (mm MeterMust) NewFloat64SumObserver(name string, callback Float64ObserverCallback, oos ...InstrumentOption) Float64SumObserver { if inst, err := mm.meter.NewFloat64SumObserver(name, callback, oos...); err != nil { panic(err) } else { @@ -135,7 +135,7 @@ func (mm MeterMust) NewFloat64SumObserver(name string, callback Float64ObserverC // NewInt64UpDownSumObserver calls `Meter.NewInt64UpDownSumObserver` and // returns the instrument, panicking if it encounters an error. -func (mm MeterMust) NewInt64UpDownSumObserver(name string, callback Int64ObserverCallback, oos ...Option) Int64UpDownSumObserver { +func (mm MeterMust) NewInt64UpDownSumObserver(name string, callback Int64ObserverCallback, oos ...InstrumentOption) Int64UpDownSumObserver { if inst, err := mm.meter.NewInt64UpDownSumObserver(name, callback, oos...); err != nil { panic(err) } else { @@ -145,7 +145,7 @@ func (mm MeterMust) NewInt64UpDownSumObserver(name string, callback Int64Observe // NewFloat64UpDownSumObserver calls `Meter.NewFloat64UpDownSumObserver` and // returns the instrument, panicking if it encounters an error. -func (mm MeterMust) NewFloat64UpDownSumObserver(name string, callback Float64ObserverCallback, oos ...Option) Float64UpDownSumObserver { +func (mm MeterMust) NewFloat64UpDownSumObserver(name string, callback Float64ObserverCallback, oos ...InstrumentOption) Float64UpDownSumObserver { if inst, err := mm.meter.NewFloat64UpDownSumObserver(name, callback, oos...); err != nil { panic(err) } else { @@ -163,7 +163,7 @@ func (mm MeterMust) NewBatchObserver(callback BatchObserverCallback) BatchObserv // NewInt64ValueObserver calls `BatchObserver.NewInt64ValueObserver` and // returns the instrument, panicking if it encounters an error. -func (bm BatchObserverMust) NewInt64ValueObserver(name string, oos ...Option) Int64ValueObserver { +func (bm BatchObserverMust) NewInt64ValueObserver(name string, oos ...InstrumentOption) Int64ValueObserver { if inst, err := bm.batch.NewInt64ValueObserver(name, oos...); err != nil { panic(err) } else { @@ -173,7 +173,7 @@ func (bm BatchObserverMust) NewInt64ValueObserver(name string, oos ...Option) In // NewFloat64ValueObserver calls `BatchObserver.NewFloat64ValueObserver` and // returns the instrument, panicking if it encounters an error. -func (bm BatchObserverMust) NewFloat64ValueObserver(name string, oos ...Option) Float64ValueObserver { +func (bm BatchObserverMust) NewFloat64ValueObserver(name string, oos ...InstrumentOption) Float64ValueObserver { if inst, err := bm.batch.NewFloat64ValueObserver(name, oos...); err != nil { panic(err) } else { @@ -183,7 +183,7 @@ func (bm BatchObserverMust) NewFloat64ValueObserver(name string, oos ...Option) // NewInt64SumObserver calls `BatchObserver.NewInt64SumObserver` and // returns the instrument, panicking if it encounters an error. -func (bm BatchObserverMust) NewInt64SumObserver(name string, oos ...Option) Int64SumObserver { +func (bm BatchObserverMust) NewInt64SumObserver(name string, oos ...InstrumentOption) Int64SumObserver { if inst, err := bm.batch.NewInt64SumObserver(name, oos...); err != nil { panic(err) } else { @@ -193,7 +193,7 @@ func (bm BatchObserverMust) NewInt64SumObserver(name string, oos ...Option) Int6 // NewFloat64SumObserver calls `BatchObserver.NewFloat64SumObserver` and // returns the instrument, panicking if it encounters an error. -func (bm BatchObserverMust) NewFloat64SumObserver(name string, oos ...Option) Float64SumObserver { +func (bm BatchObserverMust) NewFloat64SumObserver(name string, oos ...InstrumentOption) Float64SumObserver { if inst, err := bm.batch.NewFloat64SumObserver(name, oos...); err != nil { panic(err) } else { @@ -203,7 +203,7 @@ func (bm BatchObserverMust) NewFloat64SumObserver(name string, oos ...Option) Fl // NewInt64UpDownSumObserver calls `BatchObserver.NewInt64UpDownSumObserver` and // returns the instrument, panicking if it encounters an error. -func (bm BatchObserverMust) NewInt64UpDownSumObserver(name string, oos ...Option) Int64UpDownSumObserver { +func (bm BatchObserverMust) NewInt64UpDownSumObserver(name string, oos ...InstrumentOption) Int64UpDownSumObserver { if inst, err := bm.batch.NewInt64UpDownSumObserver(name, oos...); err != nil { panic(err) } else { @@ -213,7 +213,7 @@ func (bm BatchObserverMust) NewInt64UpDownSumObserver(name string, oos ...Option // NewFloat64UpDownSumObserver calls `BatchObserver.NewFloat64UpDownSumObserver` and // returns the instrument, panicking if it encounters an error. -func (bm BatchObserverMust) NewFloat64UpDownSumObserver(name string, oos ...Option) Float64UpDownSumObserver { +func (bm BatchObserverMust) NewFloat64UpDownSumObserver(name string, oos ...InstrumentOption) Float64UpDownSumObserver { if inst, err := bm.batch.NewFloat64UpDownSumObserver(name, oos...); err != nil { panic(err) } else { diff --git a/api/metric/registry/registry.go b/api/metric/registry/registry.go index 2fd183211c1..dfcd1fbc28e 100644 --- a/api/metric/registry/registry.go +++ b/api/metric/registry/registry.go @@ -21,7 +21,6 @@ import ( "go.opentelemetry.io/otel/api/kv" "go.opentelemetry.io/otel/api/metric" - "go.opentelemetry.io/otel/sdk/instrumentation" ) // Provider is a standard metric.Provider for wrapping `MeterImpl` @@ -43,8 +42,9 @@ type uniqueInstrumentMeterImpl struct { var _ metric.MeterImpl = (*uniqueInstrumentMeterImpl)(nil) type key struct { - name string - il instrumentation.Library + instrumentName string + instrumentationName string + InstrumentationVersion string } // NewProvider returns a new provider that implements instrument @@ -57,11 +57,7 @@ func NewProvider(impl metric.MeterImpl) *Provider { // Meter implements metric.Provider. func (p *Provider) Meter(instrumentationName string, opts ...metric.MeterOption) metric.Meter { - il := instrumentation.Library{ - Name: instrumentationName, - Version: metric.MeterConfigure(opts).InstrumentationVersion, - } - return metric.WrapMeterImpl(p.impl, il) + return metric.WrapMeterImpl(p.impl, instrumentationName, opts...) } // ErrMetricKindMismatch is the standard error for mismatched metric @@ -86,18 +82,18 @@ func (u *uniqueInstrumentMeterImpl) RecordBatch(ctx context.Context, labels []kv func keyOf(descriptor metric.Descriptor) key { return key{ descriptor.Name(), - descriptor.InstrumentationLibrary(), + descriptor.InstrumentationName(), + descriptor.InstrumentationVersion(), } } // NewMetricKindMismatchError formats an error that describes a // mismatched metric instrument definition. func NewMetricKindMismatchError(desc metric.Descriptor) error { - il := desc.InstrumentationLibrary() - return fmt.Errorf("Metric was %s (%s %s) registered as a %s %s: %w", + return fmt.Errorf("Metric was %s (%s %s)registered as a %s %s: %w", desc.Name(), - il.Name, - il.Version, + desc.InstrumentationName(), + desc.InstrumentationVersion(), desc.NumberKind(), desc.MetricKind(), ErrMetricKindMismatch) diff --git a/api/metric/sdkapi.go b/api/metric/sdkapi.go index 7df8a73e353..1d255d56c41 100644 --- a/api/metric/sdkapi.go +++ b/api/metric/sdkapi.go @@ -18,7 +18,6 @@ import ( "context" "go.opentelemetry.io/otel/api/kv" - "go.opentelemetry.io/otel/sdk/instrumentation" ) // MeterImpl is the interface an SDK must implement to supply a Meter @@ -86,9 +85,10 @@ type AsyncImpl interface { // WrapMeterImpl constructs a `Meter` implementation from a // `MeterImpl` implementation. -func WrapMeterImpl(impl MeterImpl, il instrumentation.Library) Meter { +func WrapMeterImpl(impl MeterImpl, instrumentatioName string, opts ...MeterOption) Meter { return Meter{ - impl: impl, - il: il, + impl: impl, + name: instrumentatioName, + version: ConfigureMeter(opts).InstrumentationVersion, } } diff --git a/exporters/metric/stdout/stdout.go b/exporters/metric/stdout/stdout.go index 55532314b81..b0ca0ecfa5b 100644 --- a/exporters/metric/stdout/stdout.go +++ b/exporters/metric/stdout/stdout.go @@ -164,10 +164,10 @@ func (e *Exporter) Export(_ context.Context, checkpointSet export.CheckpointSet) encodedResource := record.Resource().Encoded(e.config.LabelEncoder) var instLabels []kv.KeyValue - if il := desc.InstrumentationLibrary(); il.Name != "" { - instLabels = append(instLabels, kv.String("instrumentation.name", il.Name)) - if il.Version != "" { - instLabels = append(instLabels, kv.String("instrumentation.version", il.Version)) + if name := desc.InstrumentationName(); name != "" { + instLabels = append(instLabels, kv.String("instrumentation.name", name)) + if version := desc.InstrumentationVersion(); version != "" { + instLabels = append(instLabels, kv.String("instrumentation.version", version)) } } instSet := label.NewSet(instLabels...) diff --git a/exporters/otlp/internal/transform/metric.go b/exporters/otlp/internal/transform/metric.go index f62b83b511b..a51db48c909 100644 --- a/exporters/otlp/internal/transform/metric.go +++ b/exporters/otlp/internal/transform/metric.go @@ -125,10 +125,13 @@ func transformer(ctx context.Context, in <-chan export.Record, out chan<- result continue } res := result{ - Resource: r.Resource(), - InstrumentationLibrary: r.Descriptor().InstrumentationLibrary(), - Metric: m, - Err: err, + Resource: r.Resource(), + InstrumentationLibrary: instrumentation.Library{ + Name: r.Descriptor().InstrumentationName(), + Version: r.Descriptor().InstrumentationVersion(), + }, + Metric: m, + Err: err, } select { case <-ctx.Done(): diff --git a/exporters/otlp/otlp_metric_test.go b/exporters/otlp/otlp_metric_test.go index 6e6d67281a8..0a9d76b2c4b 100644 --- a/exporters/otlp/otlp_metric_test.go +++ b/exporters/otlp/otlp_metric_test.go @@ -31,7 +31,6 @@ import ( "go.opentelemetry.io/otel/api/metric" metricsdk "go.opentelemetry.io/otel/sdk/export/metric" "go.opentelemetry.io/otel/sdk/export/metric/aggregation" - "go.opentelemetry.io/otel/sdk/instrumentation" "go.opentelemetry.io/otel/sdk/metric/aggregator/minmaxsumcount" "go.opentelemetry.io/otel/sdk/metric/aggregator/sum" "go.opentelemetry.io/otel/sdk/resource" @@ -80,7 +79,7 @@ type record struct { mKind metric.Kind nKind metric.NumberKind resource *resource.Resource - opts []metric.Option + opts []metric.InstrumentOption labels []kv.KeyValue } @@ -490,16 +489,16 @@ func TestResourceMetricGroupingExport(t *testing.T) { } func TestResourceInstLibMetricGroupingExport(t *testing.T) { - countingLib1 := instrumentation.Library{ - Name: "couting-lib", - Version: "v1", + countingLib1 := []metric.InstrumentOption{ + metric.WithInstrumentationName("counting-lib"), + metric.WithInstrumentationVersion("v1"), } - countingLib2 := instrumentation.Library{ - Name: "couting-lib", - Version: "v2", + countingLib2 := []metric.InstrumentOption{ + metric.WithInstrumentationName("counting-lib"), + metric.WithInstrumentationVersion("v2"), } - summingLib := instrumentation.Library{ - Name: "summing-lib", + summingLib := []metric.InstrumentOption{ + metric.WithInstrumentationName("summing-lib"), } runMetricExportTests( t, @@ -509,9 +508,7 @@ func TestResourceInstLibMetricGroupingExport(t *testing.T) { metric.CounterKind, metric.Int64NumberKind, testInstA, - []metric.Option{ - metric.WithInstrumentationLibrary(countingLib1), - }, + countingLib1, append(baseKeyValues, cpuKey.Int(1)), }, { @@ -519,9 +516,7 @@ func TestResourceInstLibMetricGroupingExport(t *testing.T) { metric.CounterKind, metric.Int64NumberKind, testInstA, - []metric.Option{ - metric.WithInstrumentationLibrary(countingLib2), - }, + countingLib2, append(baseKeyValues, cpuKey.Int(1)), }, { @@ -529,9 +524,7 @@ func TestResourceInstLibMetricGroupingExport(t *testing.T) { metric.CounterKind, metric.Int64NumberKind, testInstA, - []metric.Option{ - metric.WithInstrumentationLibrary(countingLib1), - }, + countingLib1, append(baseKeyValues, cpuKey.Int(1)), }, { @@ -539,9 +532,7 @@ func TestResourceInstLibMetricGroupingExport(t *testing.T) { metric.CounterKind, metric.Int64NumberKind, testInstA, - []metric.Option{ - metric.WithInstrumentationLibrary(countingLib1), - }, + countingLib1, append(baseKeyValues, cpuKey.Int(2)), }, { @@ -549,9 +540,7 @@ func TestResourceInstLibMetricGroupingExport(t *testing.T) { metric.CounterKind, metric.Int64NumberKind, testInstA, - []metric.Option{ - metric.WithInstrumentationLibrary(summingLib), - }, + summingLib, append(baseKeyValues, cpuKey.Int(1)), }, { @@ -559,9 +548,7 @@ func TestResourceInstLibMetricGroupingExport(t *testing.T) { metric.CounterKind, metric.Int64NumberKind, testInstB, - []metric.Option{ - metric.WithInstrumentationLibrary(countingLib1), - }, + countingLib1, append(baseKeyValues, cpuKey.Int(1)), }, }, @@ -571,7 +558,7 @@ func TestResourceInstLibMetricGroupingExport(t *testing.T) { InstrumentationLibraryMetrics: []*metricpb.InstrumentationLibraryMetrics{ { InstrumentationLibrary: &commonpb.InstrumentationLibrary{ - Name: "couting-lib", + Name: "counting-lib", Version: "v1", }, Metrics: []*metricpb.Metric{ @@ -598,7 +585,7 @@ func TestResourceInstLibMetricGroupingExport(t *testing.T) { }, { InstrumentationLibrary: &commonpb.InstrumentationLibrary{ - Name: "couting-lib", + Name: "counting-lib", Version: "v2", }, Metrics: []*metricpb.Metric{ @@ -634,7 +621,7 @@ func TestResourceInstLibMetricGroupingExport(t *testing.T) { InstrumentationLibraryMetrics: []*metricpb.InstrumentationLibraryMetrics{ { InstrumentationLibrary: &commonpb.InstrumentationLibrary{ - Name: "couting-lib", + Name: "counting-lib", Version: "v1", }, Metrics: []*metricpb.Metric{ diff --git a/sdk/metric/benchmark_test.go b/sdk/metric/benchmark_test.go index 14de813956e..2f880705f0a 100644 --- a/sdk/metric/benchmark_test.go +++ b/sdk/metric/benchmark_test.go @@ -25,7 +25,6 @@ import ( "go.opentelemetry.io/otel/api/label" "go.opentelemetry.io/otel/api/metric" export "go.opentelemetry.io/otel/sdk/export/metric" - "go.opentelemetry.io/otel/sdk/instrumentation" sdk "go.opentelemetry.io/otel/sdk/metric" "go.opentelemetry.io/otel/sdk/metric/aggregator/ddsketch" "go.opentelemetry.io/otel/sdk/metric/aggregator/lastvalue" @@ -46,8 +45,7 @@ func newFixture(b *testing.B) *benchFixture { } bf.accumulator = sdk.NewAccumulator(bf) - il := instrumentation.Library{Name: "benchmarks"} - bf.meter = metric.Must(metric.WrapMeterImpl(bf.accumulator, il)) + bf.meter = metric.Must(metric.WrapMeterImpl(bf.accumulator, "benchmarks")) return bf } diff --git a/sdk/metric/correct_test.go b/sdk/metric/correct_test.go index a4ff92943e5..014ff3f4429 100644 --- a/sdk/metric/correct_test.go +++ b/sdk/metric/correct_test.go @@ -31,7 +31,6 @@ import ( "go.opentelemetry.io/otel/api/metric" export "go.opentelemetry.io/otel/sdk/export/metric" "go.opentelemetry.io/otel/sdk/export/metric/aggregation" - "go.opentelemetry.io/otel/sdk/instrumentation" metricsdk "go.opentelemetry.io/otel/sdk/metric" "go.opentelemetry.io/otel/sdk/metric/aggregator/array" "go.opentelemetry.io/otel/sdk/metric/aggregator/sum" @@ -91,8 +90,7 @@ func newSDK(t *testing.T) (metric.Meter, *metricsdk.Accumulator, *correctnessInt integrator, metricsdk.WithResource(testResource), ) - il := instrumentation.Library{Name: "test"} - meter := metric.WrapMeterImpl(accum, il) + meter := metric.WrapMeterImpl(accum, "test") return meter, accum, integrator } diff --git a/sdk/metric/stress_test.go b/sdk/metric/stress_test.go index 55b5d96f777..fa2bfa44563 100644 --- a/sdk/metric/stress_test.go +++ b/sdk/metric/stress_test.go @@ -36,7 +36,6 @@ import ( api "go.opentelemetry.io/otel/api/metric" export "go.opentelemetry.io/otel/sdk/export/metric" "go.opentelemetry.io/otel/sdk/export/metric/aggregation" - "go.opentelemetry.io/otel/sdk/instrumentation" "go.opentelemetry.io/otel/sdk/metric/aggregator/lastvalue" "go.opentelemetry.io/otel/sdk/metric/aggregator/sum" ) @@ -308,8 +307,7 @@ func stressTest(t *testing.T, impl testImpl) { } cc := concurrency() sdk := NewAccumulator(fixture) - il := instrumentation.Library{Name: "stress_test"} - meter := metric.WrapMeterImpl(sdk, il) + meter := metric.WrapMeterImpl(sdk, "stress_test") fixture.wg.Add(cc + 1) for i := 0; i < cc; i++ { From a8e55246ff645334a8820c0a311b77bcb59fb011 Mon Sep 17 00:00:00 2001 From: Tyler Yahn Date: Wed, 10 Jun 2020 20:49:28 -0700 Subject: [PATCH 05/10] Update global Meter and test Meter version --- api/global/internal/meter_test.go | 56 +++++++++++++++++-------------- api/global/metric.go | 12 ++++--- 2 files changed, 39 insertions(+), 29 deletions(-) diff --git a/api/global/internal/meter_test.go b/api/global/internal/meter_test.go index 71a6d7e9c61..ca47b464972 100644 --- a/api/global/internal/meter_test.go +++ b/api/global/internal/meter_test.go @@ -74,7 +74,7 @@ func TestDirect(t *testing.T) { internal.ResetForTest() ctx := context.Background() - meter1 := global.Meter("test1") + meter1 := global.Meter("test1", metric.WithInstrumentationVersion("semver:v1.0.0")) meter2 := global.Meter("test2") labels1 := []kv.KeyValue{kv.String("A", "B")} labels2 := []kv.KeyValue{kv.String("C", "D")} @@ -116,16 +116,18 @@ func TestDirect(t *testing.T) { require.EqualValues(t, []measured{ { - Name: "test.counter", - InstrumentationName: "test1", - Labels: asMap(labels1...), - Number: asInt(1), + Name: "test.counter", + InstrumentationName: "test1", + InstrumentationVersion: "semver:v1.0.0", + Labels: asMap(labels1...), + Number: asInt(1), }, { - Name: "test.valuerecorder", - InstrumentationName: "test1", - Labels: asMap(labels1...), - Number: asFloat(3), + Name: "test.valuerecorder", + InstrumentationName: "test1", + InstrumentationVersion: "semver:v1.0.0", + Labels: asMap(labels1...), + Number: asFloat(3), }, { Name: "test.second", @@ -134,28 +136,32 @@ func TestDirect(t *testing.T) { Number: asFloat(3), }, { - Name: "test.valueobserver.float", - InstrumentationName: "test1", - Labels: asMap(labels1...), - Number: asFloat(1), + Name: "test.valueobserver.float", + InstrumentationName: "test1", + InstrumentationVersion: "semver:v1.0.0", + Labels: asMap(labels1...), + Number: asFloat(1), }, { - Name: "test.valueobserver.float", - InstrumentationName: "test1", - Labels: asMap(labels2...), - Number: asFloat(2), + Name: "test.valueobserver.float", + InstrumentationName: "test1", + InstrumentationVersion: "semver:v1.0.0", + Labels: asMap(labels2...), + Number: asFloat(2), }, { - Name: "test.valueobserver.int", - InstrumentationName: "test1", - Labels: asMap(labels1...), - Number: asInt(1), + Name: "test.valueobserver.int", + InstrumentationName: "test1", + InstrumentationVersion: "semver:v1.0.0", + Labels: asMap(labels1...), + Number: asInt(1), }, { - Name: "test.valueobserver.int", - InstrumentationName: "test1", - Labels: asMap(labels2...), - Number: asInt(2), + Name: "test.valueobserver.int", + InstrumentationName: "test1", + InstrumentationVersion: "semver:v1.0.0", + Labels: asMap(labels2...), + Number: asInt(2), }, }, measurements, diff --git a/api/global/metric.go b/api/global/metric.go index 4de85180fea..04409c46ea9 100644 --- a/api/global/metric.go +++ b/api/global/metric.go @@ -19,12 +19,16 @@ import ( "go.opentelemetry.io/otel/api/metric" ) -// Meter gets a named Meter interface. If the name is an -// empty string, the provider uses a default name. +// Meter creates an implementation of the Meter interface from the global +// Provider. The instrumentationName must be the name of the library +// providing instrumentation. This name may be the same as the instrumented +// code only if that code provides built-in instrumentation. If the +// instrumentationName is empty, then a implementation defined default name +// will be used instead. // // This is short for MeterProvider().Meter(name) -func Meter(name string) metric.Meter { - return MeterProvider().Meter(name) +func Meter(instrumentationName string, opts ...metric.MeterOption) metric.Meter { + return MeterProvider().Meter(instrumentationName, opts...) } // MeterProvider returns the registered global meter provider. If From 5b959f8d2e31541e1e30238cc7817b088ecb5263 Mon Sep 17 00:00:00 2001 From: Tyler Yahn Date: Wed, 10 Jun 2020 20:51:24 -0700 Subject: [PATCH 06/10] Revert unneeded import syntax change --- api/metric/config.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/api/metric/config.go b/api/metric/config.go index 8ff0394d120..5733b8ba35e 100644 --- a/api/metric/config.go +++ b/api/metric/config.go @@ -14,9 +14,7 @@ package metric -import ( - "go.opentelemetry.io/otel/api/unit" -) +import "go.opentelemetry.io/otel/api/unit" // InstrumentConfig contains options for instrument descriptors. type InstrumentConfig struct { From 23562fb235d345aa36289a5f57c87d697e7ae12b Mon Sep 17 00:00:00 2001 From: Tyler Yahn Date: Wed, 10 Jun 2020 20:52:10 -0700 Subject: [PATCH 07/10] Fix Unit comment --- api/metric/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/metric/config.go b/api/metric/config.go index 5733b8ba35e..ba4617ee741 100644 --- a/api/metric/config.go +++ b/api/metric/config.go @@ -20,7 +20,7 @@ import "go.opentelemetry.io/otel/api/unit" type InstrumentConfig struct { // Description describes the metric instrument in human-readable terms. Description string - // Unit describing the measurement unit for a metric instrument. + // Unit describes the measurement unit for a metric instrument. Unit unit.Unit // InstrumentationName is the name of the library providing // instrumentation. From 126832edfffff4e0ab6d51119cd40a54d9cdbc25 Mon Sep 17 00:00:00 2001 From: Tyler Yahn Date: Wed, 10 Jun 2020 20:53:17 -0700 Subject: [PATCH 08/10] Update comments --- api/metric/config.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/api/metric/config.go b/api/metric/config.go index ba4617ee741..50e2cb3db44 100644 --- a/api/metric/config.go +++ b/api/metric/config.go @@ -18,9 +18,9 @@ import "go.opentelemetry.io/otel/api/unit" // InstrumentConfig contains options for instrument descriptors. type InstrumentConfig struct { - // Description describes the metric instrument in human-readable terms. + // Description describes the instrument in human-readable terms. Description string - // Unit describes the measurement unit for a metric instrument. + // Unit describes the measurement unit for a instrument. Unit unit.Unit // InstrumentationName is the name of the library providing // instrumentation. @@ -30,7 +30,7 @@ type InstrumentConfig struct { InstrumentationVersion string } -// InstrumentOption is an interface for applying metric options. +// InstrumentOption is an interface for applying instrument options. type InstrumentOption interface { // ApplyMeter is used to set a InstrumentOption value of a // InstrumentConfig. From 39c84568b3aabbab77cc71fd8a49c35897fde226 Mon Sep 17 00:00:00 2001 From: Tyler Yahn Date: Wed, 10 Jun 2020 21:00:18 -0700 Subject: [PATCH 09/10] Update comment --- api/metric/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/metric/config.go b/api/metric/config.go index 50e2cb3db44..b5d45f9aeb9 100644 --- a/api/metric/config.go +++ b/api/metric/config.go @@ -38,7 +38,7 @@ type InstrumentOption interface { } // ConfigureInstrument is a helper that applies all the InstrumentOptions -// to a InstrumentConfig. +// to an InstrumentConfig. func ConfigureInstrument(opts []InstrumentOption) InstrumentConfig { var config InstrumentConfig for _, o := range opts { From 2095a5d20e49e97095a26c1bf7a30f7179837c9c Mon Sep 17 00:00:00 2001 From: Tyler Yahn Date: Wed, 10 Jun 2020 21:09:08 -0700 Subject: [PATCH 10/10] Revert no-op change to import --- api/metric/descriptor.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/api/metric/descriptor.go b/api/metric/descriptor.go index 9218f09a333..ccc2e94b5c6 100644 --- a/api/metric/descriptor.go +++ b/api/metric/descriptor.go @@ -14,9 +14,7 @@ package metric -import ( - "go.opentelemetry.io/otel/api/unit" -) +import "go.opentelemetry.io/otel/api/unit" // Descriptor contains all the settings that describe an instrument, // including its name, metric kind, number kind, and the configurable