mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2025-01-03 22:52:30 +02:00
adding NewNoopMeterProvider to follow trace api (#2237)
* adding NewNoopMeterProvider to follow trace api * Update CHANGELOG.md Co-authored-by: Anthony Mirabella <a9@aneurysm9.com> * fix lint Co-authored-by: Anthony Mirabella <a9@aneurysm9.com> Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
This commit is contained in:
parent
c338a5efde
commit
fe7058daa2
@ -8,6 +8,10 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
### Changed
|
||||
|
||||
- NoopMeterProvider is now private and NewNoopMeterProvider must be used to obtain a noopMeterProvider. (#2237)
|
||||
|
||||
### Fixed
|
||||
|
||||
- Slice-valued attributes can correctly be used as map keys. (#2223)
|
||||
|
@ -30,12 +30,12 @@ func (*testMeterProvider) Meter(_ string, _ ...metric.MeterOption) metric.Meter
|
||||
|
||||
func TestMultipleGlobalMeterProvider(t *testing.T) {
|
||||
p1 := testMeterProvider{}
|
||||
p2 := metric.NoopMeterProvider{}
|
||||
p2 := metric.NewNoopMeterProvider()
|
||||
SetMeterProvider(&p1)
|
||||
SetMeterProvider(&p2)
|
||||
SetMeterProvider(p2)
|
||||
|
||||
got := GetMeterProvider()
|
||||
want := &p2
|
||||
want := p2
|
||||
if got != want {
|
||||
t.Fatalf("MeterProvider: got %p, want %p\n", got, want)
|
||||
}
|
||||
|
@ -21,19 +21,26 @@ import (
|
||||
"go.opentelemetry.io/otel/metric/number"
|
||||
)
|
||||
|
||||
type NoopMeterProvider struct{}
|
||||
// NewNoopMeterProvider returns an implementation of MeterProvider that
|
||||
// performs no operations. The Meter and Instrument created from the returned
|
||||
// MeterProvider also perform no operations.
|
||||
func NewNoopMeterProvider() MeterProvider {
|
||||
return noopMeterProvider{}
|
||||
}
|
||||
|
||||
type noopMeterProvider struct{}
|
||||
|
||||
type noopInstrument struct{}
|
||||
type noopBoundInstrument struct{}
|
||||
type NoopSync struct{ noopInstrument }
|
||||
type NoopAsync struct{ noopInstrument }
|
||||
|
||||
var _ MeterProvider = NoopMeterProvider{}
|
||||
var _ MeterProvider = noopMeterProvider{}
|
||||
var _ SyncImpl = NoopSync{}
|
||||
var _ BoundSyncImpl = noopBoundInstrument{}
|
||||
var _ AsyncImpl = NoopAsync{}
|
||||
|
||||
func (NoopMeterProvider) Meter(_ string, _ ...MeterOption) Meter {
|
||||
func (noopMeterProvider) Meter(instrumentationName string, opts ...MeterOption) Meter {
|
||||
return Meter{}
|
||||
}
|
||||
|
34
metric/noop_test.go
Normal file
34
metric/noop_test.go
Normal file
@ -0,0 +1,34 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package metric
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestNewNoopMeterProvider(t *testing.T) {
|
||||
got, want := NewNoopMeterProvider(), noopMeterProvider{}
|
||||
if got != want {
|
||||
t.Errorf("NewNoopMeterProvider() returned %#v, want %#v", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNoopMeterProviderMeter(t *testing.T) {
|
||||
mp := NewNoopMeterProvider()
|
||||
got, want := mp.Meter(""), Meter{}
|
||||
if got != want {
|
||||
t.Errorf("noopMeterProvider.Meter() returned %#v, want %#v", got, want)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user