diff --git a/api/global/global.go b/api/global/metric.go similarity index 54% rename from api/global/global.go rename to api/global/metric.go index c58976e27..4de85180f 100644 --- a/api/global/global.go +++ b/api/global/metric.go @@ -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) -} diff --git a/api/global/metric_test.go b/api/global/metric_test.go new file mode 100644 index 000000000..e5b77befa --- /dev/null +++ b/api/global/metric_test.go @@ -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) + } +} diff --git a/api/global/propagation.go b/api/global/propagation.go new file mode 100644 index 000000000..e3090293d --- /dev/null +++ b/api/global/propagation.go @@ -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) +} diff --git a/api/global/trace.go b/api/global/trace.go new file mode 100644 index 000000000..5c23325b7 --- /dev/null +++ b/api/global/trace.go @@ -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) +} diff --git a/api/global/global_test.go b/api/global/trace_test.go similarity index 65% rename from api/global/global_test.go rename to api/global/trace_test.go index 974077aa6..a6961b353 100644 --- a/api/global/global_test.go +++ b/api/global/trace_test.go @@ -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) - } -}