mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2025-01-05 22:54:18 +02:00
Split global.go
This commit is contained in:
parent
7cccff7944
commit
8e70cfb5c4
@ -17,34 +17,8 @@ package global
|
||||
import (
|
||||
"go.opentelemetry.io/otel/api/global/internal"
|
||||
"go.opentelemetry.io/otel/api/metric"
|
||||
"go.opentelemetry.io/otel/api/propagation"
|
||||
"go.opentelemetry.io/otel/api/trace"
|
||||
)
|
||||
|
||||
// Tracer creates a named tracer that implements Tracer interface.
|
||||
// If the name is an empty string then provider uses default name.
|
||||
//
|
||||
// This is short for TraceProvider().Tracer(name)
|
||||
func Tracer(name string) trace.Tracer {
|
||||
return TraceProvider().Tracer(name)
|
||||
}
|
||||
|
||||
// TraceProvider returns the registered global trace provider.
|
||||
// If none is registered then an instance of trace.NoopProvider is returned.
|
||||
//
|
||||
// Use the trace provider to create a named tracer. E.g.
|
||||
// tracer := global.TraceProvider().Tracer("example.com/foo")
|
||||
// or
|
||||
// tracer := global.Tracer("example.com/foo")
|
||||
func TraceProvider() trace.Provider {
|
||||
return internal.TraceProvider()
|
||||
}
|
||||
|
||||
// SetTraceProvider registers `tp` as the global trace provider.
|
||||
func SetTraceProvider(tp trace.Provider) {
|
||||
internal.SetTraceProvider(tp)
|
||||
}
|
||||
|
||||
// Meter gets a named Meter interface. If the name is an
|
||||
// empty string, the provider uses a default name.
|
||||
//
|
||||
@ -69,15 +43,3 @@ func MeterProvider() metric.Provider {
|
||||
func SetMeterProvider(mp metric.Provider) {
|
||||
internal.SetMeterProvider(mp)
|
||||
}
|
||||
|
||||
// Propagators returns the registered global propagators instance. If
|
||||
// none is registered then an instance of propagators.NoopPropagators
|
||||
// is returned.
|
||||
func Propagators() propagation.Propagators {
|
||||
return internal.Propagators()
|
||||
}
|
||||
|
||||
// SetPropagators registers `p` as the global propagators instance.
|
||||
func SetPropagators(p propagation.Propagators) {
|
||||
internal.SetPropagators(p)
|
||||
}
|
43
api/global/metric_test.go
Normal file
43
api/global/metric_test.go
Normal file
@ -0,0 +1,43 @@
|
||||
// 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 (
|
||||
"testing"
|
||||
|
||||
"go.opentelemetry.io/otel/api/global"
|
||||
"go.opentelemetry.io/otel/api/metric"
|
||||
)
|
||||
|
||||
type testMeterProvider struct{}
|
||||
|
||||
var _ metric.Provider = &testMeterProvider{}
|
||||
|
||||
func (*testMeterProvider) Meter(_ string) metric.Meter {
|
||||
return metric.Meter{}
|
||||
}
|
||||
|
||||
func TestMultipleGlobalMeterProvider(t *testing.T) {
|
||||
p1 := testMeterProvider{}
|
||||
p2 := metric.NoopProvider{}
|
||||
global.SetMeterProvider(&p1)
|
||||
global.SetMeterProvider(&p2)
|
||||
|
||||
got := global.MeterProvider()
|
||||
want := &p2
|
||||
if got != want {
|
||||
t.Fatalf("Provider: got %p, want %p\n", got, want)
|
||||
}
|
||||
}
|
32
api/global/propagation.go
Normal file
32
api/global/propagation.go
Normal file
@ -0,0 +1,32 @@
|
||||
// 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
|
||||
|
||||
import (
|
||||
"go.opentelemetry.io/otel/api/global/internal"
|
||||
"go.opentelemetry.io/otel/api/propagation"
|
||||
)
|
||||
|
||||
// Propagators returns the registered global propagators instance. If
|
||||
// none is registered then an instance of propagators.NoopPropagators
|
||||
// is returned.
|
||||
func Propagators() propagation.Propagators {
|
||||
return internal.Propagators()
|
||||
}
|
||||
|
||||
// SetPropagators registers `p` as the global propagators instance.
|
||||
func SetPropagators(p propagation.Propagators) {
|
||||
internal.SetPropagators(p)
|
||||
}
|
44
api/global/trace.go
Normal file
44
api/global/trace.go
Normal file
@ -0,0 +1,44 @@
|
||||
// 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
|
||||
|
||||
import (
|
||||
"go.opentelemetry.io/otel/api/global/internal"
|
||||
"go.opentelemetry.io/otel/api/trace"
|
||||
)
|
||||
|
||||
// Tracer creates a named tracer that implements Tracer interface.
|
||||
// If the name is an empty string then provider uses default name.
|
||||
//
|
||||
// This is short for TraceProvider().Tracer(name)
|
||||
func Tracer(name string) trace.Tracer {
|
||||
return TraceProvider().Tracer(name)
|
||||
}
|
||||
|
||||
// TraceProvider returns the registered global trace provider.
|
||||
// If none is registered then an instance of trace.NoopProvider is returned.
|
||||
//
|
||||
// Use the trace provider to create a named tracer. E.g.
|
||||
// tracer := global.TraceProvider().Tracer("example.com/foo")
|
||||
// or
|
||||
// tracer := global.Tracer("example.com/foo")
|
||||
func TraceProvider() trace.Provider {
|
||||
return internal.TraceProvider()
|
||||
}
|
||||
|
||||
// SetTraceProvider registers `tp` as the global trace provider.
|
||||
func SetTraceProvider(tp trace.Provider) {
|
||||
internal.SetTraceProvider(tp)
|
||||
}
|
@ -18,28 +18,17 @@ import (
|
||||
"testing"
|
||||
|
||||
"go.opentelemetry.io/otel/api/global"
|
||||
"go.opentelemetry.io/otel/api/metric"
|
||||
"go.opentelemetry.io/otel/api/trace"
|
||||
)
|
||||
|
||||
type (
|
||||
testTraceProvider struct{}
|
||||
testMeterProvider struct{}
|
||||
)
|
||||
type testTraceProvider struct{}
|
||||
|
||||
var (
|
||||
_ trace.Provider = &testTraceProvider{}
|
||||
_ metric.Provider = &testMeterProvider{}
|
||||
)
|
||||
var _ trace.Provider = &testTraceProvider{}
|
||||
|
||||
func (*testTraceProvider) Tracer(_ string) trace.Tracer {
|
||||
return &trace.NoopTracer{}
|
||||
}
|
||||
|
||||
func (*testMeterProvider) Meter(_ string) metric.Meter {
|
||||
return metric.Meter{}
|
||||
}
|
||||
|
||||
func TestMultipleGlobalTracerProvider(t *testing.T) {
|
||||
p1 := testTraceProvider{}
|
||||
p2 := trace.NoopProvider{}
|
||||
@ -52,16 +41,3 @@ func TestMultipleGlobalTracerProvider(t *testing.T) {
|
||||
t.Fatalf("Provider: got %p, want %p\n", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMultipleGlobalMeterProvider(t *testing.T) {
|
||||
p1 := testMeterProvider{}
|
||||
p2 := metric.NoopProvider{}
|
||||
global.SetMeterProvider(&p1)
|
||||
global.SetMeterProvider(&p2)
|
||||
|
||||
got := global.MeterProvider()
|
||||
want := &p2
|
||||
if got != want {
|
||||
t.Fatalf("Provider: got %p, want %p\n", got, want)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user