Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Remove dependency on metrics packages #1988

Merged
merged 7 commits into from
Jun 10, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,16 @@ updates:
schedule:
day: sunday
interval: weekly
-
package-ecosystem: gomod
directory: /internal/metric
labels:
- dependencies
- go
- "Skip Changelog"
schedule:
day: sunday
interval: weekly
-
package-ecosystem: gomod
directory: /internal/tools
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- The `Get` method of the `TraceState` type from the `go.opentelemetry.io/otel/trace` package has been updated to accept a `string` instead of an `attribute.Key` type. (#1931)
- The `Insert` method of the `TraceState` type from the `go.opentelemetry.io/otel/trace` package has been updated to accept a pair of `string`s instead of an `attribute.KeyValue` type. (#1931)
- The `Delete` method of the `TraceState` type from the `go.opentelemetry.io/otel/trace` package has been updated to accept a `string` instead of an `attribute.Key` type. (#1931)
- Metrics test helpers in `go.opentelemetry.io/otel/oteltest` have been moved to `go.opentelemetry.io/otel/metric/oteltest`. (#1988)

### Deprecated

Expand Down
2 changes: 2 additions & 0 deletions bridge/opencensus/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,5 @@ replace go.opentelemetry.io/otel/exporters/otlp/otlptrace => ../../exporters/otl
replace go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc => ../../exporters/otlp/otlptrace/otlptracegrpc

replace go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp => ../../exporters/otlp/otlptrace/otlptracehttp

replace go.opentelemetry.io/otel/internal/metric => ../../internal/metric
2 changes: 2 additions & 0 deletions bridge/opentracing/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,5 @@ replace go.opentelemetry.io/otel/exporters/otlp/otlptrace => ../../exporters/otl
replace go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc => ../../exporters/otlp/otlptrace/otlptracegrpc

replace go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp => ../../exporters/otlp/otlptrace/otlptracehttp

replace go.opentelemetry.io/otel/internal/metric => ../../internal/metric
2 changes: 2 additions & 0 deletions example/jaeger/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,5 @@ replace go.opentelemetry.io/otel/exporters/otlp/otlptrace => ../../exporters/otl
replace go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc => ../../exporters/otlp/otlptrace/otlptracegrpc

replace go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp => ../../exporters/otlp/otlptrace/otlptracehttp

replace go.opentelemetry.io/otel/internal/metric => ../../internal/metric
2 changes: 2 additions & 0 deletions example/namedtracer/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,5 @@ replace go.opentelemetry.io/otel/exporters/otlp/otlptrace => ../../exporters/otl
replace go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc => ../../exporters/otlp/otlptrace/otlptracegrpc

replace go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp => ../../exporters/otlp/otlptrace/otlptracehttp

replace go.opentelemetry.io/otel/internal/metric => ../../internal/metric
2 changes: 2 additions & 0 deletions example/opencensus/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,5 @@ replace go.opentelemetry.io/otel/exporters/otlp/otlptrace => ../../exporters/otl
replace go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc => ../../exporters/otlp/otlptrace/otlptracegrpc

replace go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp => ../../exporters/otlp/otlptrace/otlptracehttp

replace go.opentelemetry.io/otel/internal/metric => ../../internal/metric
2 changes: 2 additions & 0 deletions example/otel-collector/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,5 @@ replace go.opentelemetry.io/otel/exporters/otlp/otlptrace => ../../exporters/otl
replace go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc => ../../exporters/otlp/otlptrace/otlptracegrpc

replace go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp => ../../exporters/otlp/otlptrace/otlptracehttp

replace go.opentelemetry.io/otel/internal/metric => ../../internal/metric
2 changes: 2 additions & 0 deletions example/passthrough/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,5 @@ replace go.opentelemetry.io/otel/exporters/otlp/otlptrace => ../../exporters/otl
replace go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc => ../../exporters/otlp/otlptrace/otlptracegrpc

replace go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp => ../../exporters/otlp/otlptrace/otlptracehttp

replace go.opentelemetry.io/otel/internal/metric => ../../internal/metric
2 changes: 2 additions & 0 deletions example/prom-collector/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,5 @@ replace go.opentelemetry.io/otel/exporters/otlp/otlptrace => ../../exporters/otl
replace go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc => ../../exporters/otlp/otlptrace/otlptracegrpc

replace go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp => ../../exporters/otlp/otlptrace/otlptracehttp

replace go.opentelemetry.io/otel/internal/metric => ../../internal/metric
2 changes: 2 additions & 0 deletions example/prometheus/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,5 @@ replace go.opentelemetry.io/otel/exporters/otlp/otlptrace => ../../exporters/otl
replace go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc => ../../exporters/otlp/otlptrace/otlptracegrpc

replace go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp => ../../exporters/otlp/otlptrace/otlptracehttp

replace go.opentelemetry.io/otel/internal/metric => ../../internal/metric
2 changes: 2 additions & 0 deletions example/zipkin/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,5 @@ replace go.opentelemetry.io/otel/exporters/otlp/otlptrace => ../../exporters/otl
replace go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc => ../../exporters/otlp/otlptrace/otlptracegrpc

replace go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp => ../../exporters/otlp/otlptrace/otlptracehttp

replace go.opentelemetry.io/otel/internal/metric => ../../internal/metric
2 changes: 2 additions & 0 deletions exporters/metric/prometheus/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,5 @@ replace go.opentelemetry.io/otel/exporters/otlp/otlptrace => ../../otlp/otlptrac
replace go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc => ../../otlp/otlptrace/otlptracegrpc

replace go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp => ../../otlp/otlptrace/otlptracehttp

replace go.opentelemetry.io/otel/internal/metric => ../../../internal/metric
2 changes: 2 additions & 0 deletions exporters/otlp/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,5 @@ replace go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc => ./otl
replace go.opentelemetry.io/otel/example/passthrough => ../../example/passthrough

replace go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp => ./otlptrace/otlptracehttp

replace go.opentelemetry.io/otel/internal/metric => ../../internal/metric
2 changes: 2 additions & 0 deletions exporters/otlp/otlptrace/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,5 @@ replace go.opentelemetry.io/otel/sdk/metric => ../../../sdk/metric
replace go.opentelemetry.io/otel/example/passthrough => ../../../example/passthrough

replace go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp => ./otlptracehttp

replace go.opentelemetry.io/otel/internal/metric => ../../../internal/metric
2 changes: 2 additions & 0 deletions exporters/otlp/otlptrace/otlptracegrpc/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,5 @@ replace go.opentelemetry.io/otel/sdk/metric => ../../../../sdk/metric
replace go.opentelemetry.io/otel/example/passthrough => ../../../../example/passthrough

replace go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp => ../otlptracehttp

replace go.opentelemetry.io/otel/internal/metric => ../../../../internal/metric
2 changes: 2 additions & 0 deletions exporters/otlp/otlptrace/otlptracehttp/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,5 @@ replace go.opentelemetry.io/otel/sdk/export/metric => ../../../../sdk/export/met
replace go.opentelemetry.io/otel/sdk/metric => ../../../../sdk/metric

replace go.opentelemetry.io/otel/trace => ../../../../trace

replace go.opentelemetry.io/otel/internal/metric => ../../../../internal/metric
2 changes: 2 additions & 0 deletions exporters/stdout/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,5 @@ replace go.opentelemetry.io/otel/exporters/otlp/otlptrace => ../otlp/otlptrace
replace go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc => ../otlp/otlptrace/otlptracegrpc

replace go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp => ../otlp/otlptrace/otlptracehttp

replace go.opentelemetry.io/otel/internal/metric => ../../internal/metric
2 changes: 2 additions & 0 deletions exporters/trace/jaeger/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,5 @@ replace go.opentelemetry.io/otel/exporters/otlp/otlptrace => ../../otlp/otlptrac
replace go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc => ../../otlp/otlptrace/otlptracegrpc

replace go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp => ../../otlp/otlptrace/otlptracehttp

replace go.opentelemetry.io/otel/internal/metric => ../../../internal/metric
2 changes: 2 additions & 0 deletions exporters/trace/zipkin/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,5 @@ replace go.opentelemetry.io/otel/exporters/otlp/otlptrace => ../../otlp/otlptrac
replace go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc => ../../otlp/otlptrace/otlptracegrpc

replace go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp => ../../otlp/otlptrace/otlptracehttp

replace go.opentelemetry.io/otel/internal/metric => ../../../internal/metric
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ go 1.15
require (
github.com/google/go-cmp v0.5.6
github.com/stretchr/testify v1.7.0
go.opentelemetry.io/otel/metric v0.20.0
go.opentelemetry.io/otel/oteltest v0.20.0
go.opentelemetry.io/otel/trace v0.20.0
)
Expand Down Expand Up @@ -44,6 +43,8 @@ replace go.opentelemetry.io/otel/internal/tools => ./internal/tools

replace go.opentelemetry.io/otel/sdk => ./sdk

replace go.opentelemetry.io/otel/internal/metric => ./internal/metric

replace go.opentelemetry.io/otel/metric => ./metric

replace go.opentelemetry.io/otel/oteltest => ./oteltest
Expand Down
19 changes: 0 additions & 19 deletions internal/global/benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,9 @@ import (
"testing"

"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/internal/global"
metricglobal "go.opentelemetry.io/otel/metric/global"
)

func BenchmarkGlobalInt64CounterAddNoSDK(b *testing.B) {
// Compare with BenchmarkGlobalInt64CounterAddWithSDK() in
// ../../sdk/metric/benchmark_test.go to see the overhead of the
// global no-op system against a registered SDK.
global.ResetForTest()
ctx := context.Background()
sdk := metricglobal.Meter("test")
labs := []attribute.KeyValue{attribute.String("A", "B")}
cnt := Must(sdk).NewInt64Counter("int64.counter")

b.ResetTimer()

for i := 0; i < b.N; i++ {
cnt.Add(ctx, 1, labs...)
}
}

func BenchmarkStartEndSpanNoSDK(b *testing.B) {
// Compare with BenchmarkStartEndSpan() in
// ../../sdk/trace/benchmark_test.go.
Expand Down
37 changes: 0 additions & 37 deletions internal/global/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"sync"
"sync/atomic"

"go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/propagation"
"go.opentelemetry.io/otel/trace"
)
Expand All @@ -28,21 +27,15 @@ type (
tp trace.TracerProvider
}

meterProviderHolder struct {
mp metric.MeterProvider
}

propagatorsHolder struct {
tm propagation.TextMapPropagator
}
)

var (
globalTracer = defaultTracerValue()
globalMeter = defaultMeterValue()
globalPropagators = defaultPropagatorsValue()

delegateMeterOnce sync.Once
delegateTraceOnce sync.Once
delegateTextMapPropagatorOnce sync.Once
)
Expand All @@ -69,28 +62,6 @@ func SetTracerProvider(tp trace.TracerProvider) {
globalTracer.Store(tracerProviderHolder{tp: tp})
}

// MeterProvider is the internal implementation for global.MeterProvider.
func MeterProvider() metric.MeterProvider {
return globalMeter.Load().(meterProviderHolder).mp
}

// SetMeterProvider is the internal implementation for global.SetMeterProvider.
func SetMeterProvider(mp metric.MeterProvider) {
delegateMeterOnce.Do(func() {
current := MeterProvider()

if current == mp {
// Setting the provider to the prior default is nonsense, panic.
// Panic is acceptable because we are likely still early in the
// process lifetime.
panic("invalid MeterProvider, the global instance cannot be reinstalled")
} else if def, ok := current.(*meterProvider); ok {
def.setDelegate(mp)
}
})
globalMeter.Store(meterProviderHolder{mp: mp})
}

// TextMapPropagator is the internal implementation for global.TextMapPropagator.
func TextMapPropagator() propagation.TextMapPropagator {
return globalPropagators.Load().(propagatorsHolder).tm
Expand Down Expand Up @@ -120,12 +91,6 @@ func defaultTracerValue() *atomic.Value {
return v
}

func defaultMeterValue() *atomic.Value {
v := &atomic.Value{}
v.Store(meterProviderHolder{mp: newMeterProvider()})
return v
}

func defaultPropagatorsValue() *atomic.Value {
v := &atomic.Value{}
v.Store(propagatorsHolder{tm: newTextMapPropagator()})
Expand All @@ -135,9 +100,7 @@ func defaultPropagatorsValue() *atomic.Value {
// ResetForTest restores the initial global state, for testing purposes.
func ResetForTest() {
globalTracer = defaultTracerValue()
globalMeter = defaultMeterValue()
globalPropagators = defaultPropagatorsValue()
delegateMeterOnce = sync.Once{}
delegateTraceOnce = sync.Once{}
delegateTextMapPropagatorOnce = sync.Once{}
}
3 changes: 0 additions & 3 deletions internal/global/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ func TestResetsOfGlobalsPanic(t *testing.T) {
"SetTracerProvider": func() {
global.SetTracerProvider(global.TracerProvider())
},
"SetMeterProvider": func() {
global.SetMeterProvider(global.MeterProvider())
},
}

for name, test := range tests {
Expand Down
41 changes: 41 additions & 0 deletions internal/metric/global/benchmark_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// 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 global_test

import (
"context"
"testing"

"go.opentelemetry.io/otel/attribute"
internalglobal "go.opentelemetry.io/otel/internal/metric/global"
metricglobal "go.opentelemetry.io/otel/metric/global"
)

func BenchmarkGlobalInt64CounterAddNoSDK(b *testing.B) {
// Compare with BenchmarkGlobalInt64CounterAddWithSDK() in
// ../../sdk/metric/benchmark_test.go to see the overhead of the
// global no-op system against a registered SDK.
internalglobal.ResetForTest()
ctx := context.Background()
sdk := metricglobal.Meter("test")
labs := []attribute.KeyValue{attribute.String("A", "B")}
cnt := Must(sdk).NewInt64Counter("int64.counter")

b.ResetTimer()

for i := 0; i < b.N; i++ {
cnt.Add(ctx, 1, labs...)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import (
"os"
"testing"

"go.opentelemetry.io/otel/internal/global"
ottest "go.opentelemetry.io/otel/internal/internaltest"
"go.opentelemetry.io/otel/internal/metric/global"
)

// Ensure struct alignment prior to running tests.
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ import (
"github.com/stretchr/testify/require"

"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/internal/global"
"go.opentelemetry.io/otel/internal/metric/global"
"go.opentelemetry.io/otel/metric"
metricglobal "go.opentelemetry.io/otel/metric/global"
"go.opentelemetry.io/otel/metric/number"
"go.opentelemetry.io/otel/oteltest"
"go.opentelemetry.io/otel/metric/oteltest"
)

var Must = metric.Must
Expand Down
Loading