You've already forked opentelemetry-go
							
							
				mirror of
				https://github.com/open-telemetry/opentelemetry-go.git
				synced 2025-10-31 00:07:40 +02:00 
			
		
		
		
	Move Version function and code from global to toplevel (#1330)
* Move global code to toplevel package * Move version function to toplevel package * Update changelog Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
This commit is contained in:
		| @@ -39,7 +39,8 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm | ||||
| - Move the `Number` type (together with related functions) from `go.opentelemetry.io/otel/api/metric` package into `go.opentelemetry.io/otel/metric/number` as a part of #1303. (#1316) | ||||
| - The function signature of the Span `AddEvent` method in `go.opentelemetry.io/otel` is updated to no longer take an unused context and instead take a required name and a variable number of `EventOption`s. (#1254) | ||||
| - The function signature of the Span `RecordError` method in `go.opentelemetry.io/otel` is updated to no longer take an unused context and instead take a required error value and a variable number of `EventOption`s. (#1254) | ||||
| - Move the `go.opentelemetry.io/otel/api/global` package to `go.opentelemetry.io/otel/global`. (#1262) | ||||
| - Move the `go.opentelemetry.io/otel/api/global` package to `go.opentelemetry.io/otel`. (#1262) (#1330) | ||||
| - Move the `Version` function from `go.opentelemetry.io/otel/sdk` to `go.opentelemetry.io/otel`. (#1330) | ||||
| - Rename correlation context header from `"otcorrelations"` to `"baggage"` to match the OpenTelemetry specification. (#1267) | ||||
| - Fix `Code.UnmarshalJSON` to work with valid json only. (#1276) | ||||
| - The `resource.New()` method changes signature to support builtin attributes and functional options, including `telemetry.sdk.*` and | ||||
|   | ||||
| @@ -20,8 +20,8 @@ import ( | ||||
|  | ||||
| 	octrace "go.opencensus.io/trace" | ||||
|  | ||||
| 	"go.opentelemetry.io/otel" | ||||
| 	"go.opentelemetry.io/otel/codes" | ||||
| 	"go.opentelemetry.io/otel/global" | ||||
| 	"go.opentelemetry.io/otel/label" | ||||
| 	"go.opentelemetry.io/otel/trace" | ||||
| ) | ||||
| @@ -60,7 +60,7 @@ func convertStartOptions(optFns []octrace.StartOption, name string) []trace.Span | ||||
| 	} | ||||
|  | ||||
| 	if ocOpts.Sampler != nil { | ||||
| 		global.Handle(fmt.Errorf("ignoring custom sampler for span %q created by OpenCensus because OpenTelemetry does not support creating a span with a custom sampler", name)) | ||||
| 		otel.Handle(fmt.Errorf("ignoring custom sampler for span %q created by OpenCensus because OpenTelemetry does not support creating a span with a custom sampler", name)) | ||||
| 	} | ||||
| 	return otOpts | ||||
| } | ||||
| @@ -81,7 +81,7 @@ func (o *otelTracer) NewContext(parent context.Context, s *octrace.Span) context | ||||
| 	if otSpan, ok := s.Internal().(*span); ok { | ||||
| 		return trace.ContextWithSpan(parent, otSpan.otSpan) | ||||
| 	} | ||||
| 	global.Handle(fmt.Errorf("unable to create context with span %q, since it was created using a different tracer", s.String())) | ||||
| 	otel.Handle(fmt.Errorf("unable to create context with span %q, since it was created using a different tracer", s.String())) | ||||
| 	return parent | ||||
| } | ||||
|  | ||||
| @@ -181,7 +181,7 @@ func (s *span) AddMessageReceiveEvent(messageID, uncompressedByteSize, compresse | ||||
| } | ||||
|  | ||||
| func (s *span) AddLink(l octrace.Link) { | ||||
| 	global.Handle(fmt.Errorf("ignoring OpenCensus link %+v for span %q because OpenTelemetry doesn't support setting links after creation", l, s.String())) | ||||
| 	otel.Handle(fmt.Errorf("ignoring OpenCensus link %+v for span %q because OpenTelemetry doesn't support setting links after creation", l, s.String())) | ||||
| } | ||||
|  | ||||
| func (s *span) String() string { | ||||
| @@ -190,7 +190,7 @@ func (s *span) String() string { | ||||
|  | ||||
| func otelSpanContextToOc(sc trace.SpanContext) octrace.SpanContext { | ||||
| 	if sc.IsDebug() || sc.IsDeferred() { | ||||
| 		global.Handle(fmt.Errorf("ignoring OpenTelemetry Debug or Deferred trace flags for span %q because they are not supported by OpenCensus", sc.SpanID)) | ||||
| 		otel.Handle(fmt.Errorf("ignoring OpenTelemetry Debug or Deferred trace flags for span %q because they are not supported by OpenCensus", sc.SpanID)) | ||||
| 	} | ||||
| 	var to octrace.TraceOptions | ||||
| 	if sc.IsSampled() { | ||||
|   | ||||
| @@ -25,9 +25,9 @@ import ( | ||||
| 	otext "github.com/opentracing/opentracing-go/ext" | ||||
| 	otlog "github.com/opentracing/opentracing-go/log" | ||||
|  | ||||
| 	"go.opentelemetry.io/otel" | ||||
| 	"go.opentelemetry.io/otel/bridge/opentracing/migration" | ||||
| 	"go.opentelemetry.io/otel/codes" | ||||
| 	otelglobal "go.opentelemetry.io/otel/global" | ||||
| 	"go.opentelemetry.io/otel/internal/baggage" | ||||
| 	"go.opentelemetry.io/otel/internal/trace/noop" | ||||
| 	otelparent "go.opentelemetry.io/otel/internal/trace/parent" | ||||
| @@ -654,5 +654,5 @@ func (t *BridgeTracer) getPropagator() propagation.TextMapPropagator { | ||||
| 	if t.propagator != nil { | ||||
| 		return t.propagator | ||||
| 	} | ||||
| 	return otelglobal.TextMapPropagator() | ||||
| 	return otel.GetTextMapPropagator() | ||||
| } | ||||
|   | ||||
| @@ -21,7 +21,7 @@ import ( | ||||
|  | ||||
| 	ot "github.com/opentracing/opentracing-go" | ||||
|  | ||||
| 	otelglobal "go.opentelemetry.io/otel/global" | ||||
| 	"go.opentelemetry.io/otel" | ||||
| 	otelbaggage "go.opentelemetry.io/otel/internal/baggage" | ||||
| 	"go.opentelemetry.io/otel/label" | ||||
| 	"go.opentelemetry.io/otel/trace" | ||||
| @@ -130,7 +130,7 @@ func TestMixedAPIs(t *testing.T) { | ||||
| 			t.Log(msg) | ||||
| 		}) | ||||
|  | ||||
| 		otelglobal.SetTracerProvider(otelProvider) | ||||
| 		otel.SetTracerProvider(otelProvider) | ||||
| 		ot.SetGlobalTracer(otTracer) | ||||
|  | ||||
| 		tc.setup(t, mockOtelTracer) | ||||
| @@ -440,7 +440,7 @@ func (tm *tracerMessTest) setup(t *testing.T, tracer *internal.MockTracer) { | ||||
|  | ||||
| func (tm *tracerMessTest) check(t *testing.T, tracer *internal.MockTracer) { | ||||
| 	globalOtTracer := ot.GlobalTracer() | ||||
| 	globalOtelTracer := otelglobal.Tracer("") | ||||
| 	globalOtelTracer := otel.Tracer("") | ||||
| 	if len(tm.recordedOTSpanTracers) != 3 { | ||||
| 		t.Errorf("Expected 3 recorded OpenTracing tracers from spans, got %d", len(tm.recordedOTSpanTracers)) | ||||
| 	} | ||||
| @@ -684,7 +684,7 @@ func min(a, b int) int { | ||||
| } | ||||
|  | ||||
| func runOtelOTOtel(t *testing.T, ctx context.Context, name string, callback func(*testing.T, context.Context) context.Context) { | ||||
| 	tr := otelglobal.Tracer("") | ||||
| 	tr := otel.Tracer("") | ||||
| 	ctx, span := tr.Start(ctx, fmt.Sprintf("%s_Otel_OTOtel", name), trace.WithSpanKind(trace.SpanKindClient)) | ||||
| 	defer span.End() | ||||
| 	ctx = callback(t, ctx) | ||||
| @@ -701,7 +701,7 @@ func runOtelOTOtel(t *testing.T, ctx context.Context, name string, callback func | ||||
| } | ||||
|  | ||||
| func runOTOtelOT(t *testing.T, ctx context.Context, name string, callback func(*testing.T, context.Context) context.Context) { | ||||
| 	tr := otelglobal.Tracer("") | ||||
| 	tr := otel.Tracer("") | ||||
| 	span, ctx := ot.StartSpanFromContext(ctx, fmt.Sprintf("%s_OT_OtelOT", name), ot.Tag{Key: "span.kind", Value: "client"}) | ||||
| 	defer span.Finish() | ||||
| 	ctx = callback(t, ctx) | ||||
|   | ||||
							
								
								
									
										113
									
								
								doc.go
									
									
									
									
									
								
							
							
						
						
									
										113
									
								
								doc.go
									
									
									
									
									
								
							| @@ -12,112 +12,9 @@ | ||||
| // See the License for the specific language governing permissions and | ||||
| // limitations under the License. | ||||
|  | ||||
| /* | ||||
| Package otel provides an implementation of the OpenTelemetry API. | ||||
|  | ||||
| This package is currently in a pre-GA phase. Backwards incompatible changes | ||||
| may be introduced in subsequent minor version releases as we work to track the | ||||
| evolving OpenTelemetry specification and user feedback. | ||||
|  | ||||
| The provided API is used to instrument code and measure data about that code's | ||||
| performance and operation. The measured data, by default, is not processed or | ||||
| transmitted anywhere. An implementation of the OpenTelemetry SDK, like the | ||||
| default SDK implementation (go.opentelemetry.io/otel/sdk), and associated | ||||
| exporters are used to process and transport this data. | ||||
|  | ||||
| Tracing | ||||
|  | ||||
| To participate in distributed traces a Span needs to be created for the | ||||
| operation being performed as part of a traced workflow. It its simplest form: | ||||
|  | ||||
| 	var tracer otel.Tracer | ||||
|  | ||||
| 	func init() { | ||||
| 		tracer = global.Tracer("instrumentation/package/name") | ||||
| 	} | ||||
|  | ||||
| 	func operation(ctx context.Context) { | ||||
| 		var span trace.Span | ||||
| 		ctx, span = tracer.Start(ctx, "operation") | ||||
| 		defer span.End() | ||||
| 		// ... | ||||
| 	} | ||||
|  | ||||
| A Tracer is unique to the instrumentation and is used to create Spans. | ||||
| Instrumentation should be designed to accept a TracerProvider from which it | ||||
| can create its own unique Tracer. Alternatively, the registered global | ||||
| TracerProvider from the go.opentelemetry.io/otel/global package can be used as | ||||
| a default. | ||||
|  | ||||
| 	const ( | ||||
| 		name    = "instrumentation/package/name" | ||||
| 		version = "0.1.0" | ||||
| 	) | ||||
|  | ||||
| 	type Instrumentation struct { | ||||
| 		tracer otel.Tracer | ||||
| 	} | ||||
|  | ||||
| 	func NewInstrumentation(tp otel.TracerProvider) *Instrumentation { | ||||
| 		if tp == nil { | ||||
| 			tp := global.TracerProvider() | ||||
| 		} | ||||
| 		return &Instrumentation{ | ||||
| 			tracer: tp.Tracer(name, otel.WithTracerVersion(version)), | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	func operation(ctx context.Context, inst *Instrumentation) { | ||||
| 		var span trace.Span | ||||
| 		ctx, span = inst.tracer.Start(ctx, "operation") | ||||
| 		defer span.End() | ||||
| 		// ... | ||||
| 	} | ||||
|  | ||||
| Metric Measurements | ||||
|  | ||||
| Measurements can be made about an operation being performed or the state of a | ||||
| system in general. These measurements can be crucial to the reliable operation | ||||
| of code and provide valuable insights about the inner workings of a system. | ||||
|  | ||||
| Measurements are made using instruments provided by this package. The type of | ||||
| instrument used will depend on the type of measurement being made and of what | ||||
| part of a system is being measured. | ||||
|  | ||||
| Instruments are categorized as Synchronous or Asynchronous and independently | ||||
| as Adding or Grouping. Synchronous instruments are called by the user with a | ||||
| Context. Asynchronous instruments are called by the SDK during collection. | ||||
| Additive instruments are semantically intended for capturing a sum. Grouping | ||||
| instruments are intended for capturing a distribution. | ||||
|  | ||||
| Additive instruments may be monotonic, in which case they are non-decreasing | ||||
| and naturally define a rate. | ||||
|  | ||||
| The synchronous instrument names are: | ||||
|  | ||||
|   Counter:           additive, monotonic | ||||
|   UpDownCounter:     additive | ||||
|   ValueRecorder:     grouping | ||||
|  | ||||
| and the asynchronous instruments are: | ||||
|  | ||||
|   SumObserver:       additive, monotonic | ||||
|   UpDownSumObserver: additive | ||||
|   ValueObserver:     grouping | ||||
|  | ||||
| All instruments are provided with support for either float64 or int64 input | ||||
| values. | ||||
|  | ||||
| An instrument is created using a Meter. Additionally, a Meter is used to | ||||
| record batches of synchronous measurements or asynchronous observations. A | ||||
| Meter is obtained using a MeterProvider. A Meter, like a Tracer, is unique to | ||||
| the instrumentation it instruments and must be named and versioned when | ||||
| created with a MeterProvider with the name and version of the instrumentation | ||||
| library. | ||||
|  | ||||
| Instrumentation should be designed to accept a MeterProvider from which it can | ||||
| create its own unique Meter. Alternatively, the registered global | ||||
| MeterProvider from the go.opentelemetry.io/otel/api/global package can be used | ||||
| as a default. | ||||
| */ | ||||
| // Package global provides global providers, propagators and more. | ||||
| // | ||||
| // This package is currently in a pre-GA phase. Backwards incompatible changes | ||||
| // may be introduced in subsequent minor version releases as we work to track | ||||
| // the evolving OpenTelemetry specification and user feedback. | ||||
| package otel // import "go.opentelemetry.io/otel" | ||||
|   | ||||
| @@ -18,9 +18,9 @@ import ( | ||||
| 	"context" | ||||
| 	"log" | ||||
|  | ||||
| 	"go.opentelemetry.io/otel" | ||||
| 	"go.opentelemetry.io/otel/baggage" | ||||
| 	"go.opentelemetry.io/otel/exporters/stdout" | ||||
| 	"go.opentelemetry.io/otel/global" | ||||
| 	"go.opentelemetry.io/otel/label" | ||||
| 	"go.opentelemetry.io/otel/metric" | ||||
| 	"go.opentelemetry.io/otel/propagation" | ||||
| @@ -59,13 +59,13 @@ func main() { | ||||
| 	) | ||||
| 	pusher.Start() | ||||
| 	defer pusher.Stop() | ||||
| 	global.SetTracerProvider(tp) | ||||
| 	global.SetMeterProvider(pusher.MeterProvider()) | ||||
| 	otel.SetTracerProvider(tp) | ||||
| 	otel.SetMeterProvider(pusher.MeterProvider()) | ||||
|  | ||||
| 	// set global propagator to baggage (the default is no-op). | ||||
| 	global.SetTextMapPropagator(propagation.Baggage{}) | ||||
| 	tracer := global.Tracer("ex.com/basic") | ||||
| 	meter := global.Meter("ex.com/basic") | ||||
| 	otel.SetTextMapPropagator(propagation.Baggage{}) | ||||
| 	tracer := otel.Tracer("ex.com/basic") | ||||
| 	meter := otel.Meter("ex.com/basic") | ||||
|  | ||||
| 	commonLabels := []label.KeyValue{lemonsKey.Int(10), label.String("A", "1"), label.String("B", "2"), label.String("C", "3")} | ||||
|  | ||||
|   | ||||
| @@ -20,7 +20,7 @@ import ( | ||||
| 	"context" | ||||
| 	"log" | ||||
|  | ||||
| 	"go.opentelemetry.io/otel/global" | ||||
| 	"go.opentelemetry.io/otel" | ||||
| 	"go.opentelemetry.io/otel/label" | ||||
|  | ||||
| 	"go.opentelemetry.io/otel/exporters/trace/jaeger" | ||||
| @@ -53,7 +53,7 @@ func main() { | ||||
| 	flush := initTracer() | ||||
| 	defer flush() | ||||
|  | ||||
| 	tr := global.Tracer("component-main") | ||||
| 	tr := otel.Tracer("component-main") | ||||
| 	ctx, span := tr.Start(ctx, "foo") | ||||
| 	defer span.End() | ||||
|  | ||||
| @@ -61,7 +61,7 @@ func main() { | ||||
| } | ||||
|  | ||||
| func bar(ctx context.Context) { | ||||
| 	tr := global.Tracer("component-bar") | ||||
| 	tr := otel.Tracer("component-bar") | ||||
| 	_, span := tr.Start(ctx, "bar") | ||||
| 	defer span.End() | ||||
|  | ||||
|   | ||||
| @@ -17,7 +17,7 @@ package foo // import "go.opentelemetry.io/otel/example/namedtracer/foo" | ||||
| import ( | ||||
| 	"context" | ||||
|  | ||||
| 	"go.opentelemetry.io/otel/global" | ||||
| 	"go.opentelemetry.io/otel" | ||||
| 	"go.opentelemetry.io/otel/label" | ||||
| 	"go.opentelemetry.io/otel/trace" | ||||
| ) | ||||
| @@ -31,7 +31,7 @@ var ( | ||||
| func SubOperation(ctx context.Context) error { | ||||
| 	// Using global provider. Alternative is to have application provide a getter | ||||
| 	// for its component to get the instance of the provider. | ||||
| 	tr := global.Tracer("example/namedtracer/foo") | ||||
| 	tr := otel.Tracer("example/namedtracer/foo") | ||||
|  | ||||
| 	var span trace.Span | ||||
| 	_, span = tr.Start(ctx, "Sub operation...") | ||||
|   | ||||
| @@ -18,10 +18,10 @@ import ( | ||||
| 	"context" | ||||
| 	"log" | ||||
|  | ||||
| 	"go.opentelemetry.io/otel" | ||||
| 	"go.opentelemetry.io/otel/baggage" | ||||
| 	"go.opentelemetry.io/otel/example/namedtracer/foo" | ||||
| 	"go.opentelemetry.io/otel/exporters/stdout" | ||||
| 	"go.opentelemetry.io/otel/global" | ||||
| 	"go.opentelemetry.io/otel/label" | ||||
| 	sdktrace "go.opentelemetry.io/otel/sdk/trace" | ||||
| 	"go.opentelemetry.io/otel/trace" | ||||
| @@ -52,7 +52,7 @@ func initTracer() { | ||||
| 		), | ||||
| 		sdktrace.WithSpanProcessor(bsp), | ||||
| 	) | ||||
| 	global.SetTracerProvider(tp) | ||||
| 	otel.SetTracerProvider(tp) | ||||
| } | ||||
|  | ||||
| func main() { | ||||
|   | ||||
| @@ -25,8 +25,8 @@ import ( | ||||
|  | ||||
| 	"google.golang.org/grpc" | ||||
|  | ||||
| 	"go.opentelemetry.io/otel" | ||||
| 	"go.opentelemetry.io/otel/exporters/otlp" | ||||
| 	"go.opentelemetry.io/otel/global" | ||||
| 	"go.opentelemetry.io/otel/label" | ||||
| 	"go.opentelemetry.io/otel/metric" | ||||
| 	"go.opentelemetry.io/otel/propagation" | ||||
| @@ -81,9 +81,9 @@ func initProvider() func() { | ||||
| 	) | ||||
|  | ||||
| 	// set global propagator to tracecontext (the default is no-op). | ||||
| 	global.SetTextMapPropagator(propagation.TraceContext{}) | ||||
| 	global.SetTracerProvider(tracerProvider) | ||||
| 	global.SetMeterProvider(pusher.MeterProvider()) | ||||
| 	otel.SetTextMapPropagator(propagation.TraceContext{}) | ||||
| 	otel.SetTracerProvider(tracerProvider) | ||||
| 	otel.SetMeterProvider(pusher.MeterProvider()) | ||||
| 	pusher.Start() | ||||
|  | ||||
| 	return func() { | ||||
| @@ -99,8 +99,8 @@ func main() { | ||||
| 	shutdown := initProvider() | ||||
| 	defer shutdown() | ||||
|  | ||||
| 	tracer := global.Tracer("test-tracer") | ||||
| 	meter := global.Meter("test-meter") | ||||
| 	tracer := otel.Tracer("test-tracer") | ||||
| 	meter := otel.Meter("test-meter") | ||||
|  | ||||
| 	// labels represent additional key-value descriptors that can be bound to a | ||||
| 	// metric observer or recorder. | ||||
|   | ||||
| @@ -22,8 +22,8 @@ import ( | ||||
| 	"sync" | ||||
| 	"time" | ||||
|  | ||||
| 	"go.opentelemetry.io/otel" | ||||
| 	"go.opentelemetry.io/otel/exporters/metric/prometheus" | ||||
| 	"go.opentelemetry.io/otel/global" | ||||
| 	"go.opentelemetry.io/otel/label" | ||||
| 	"go.opentelemetry.io/otel/metric" | ||||
| ) | ||||
| @@ -48,7 +48,7 @@ func initMeter() { | ||||
| func main() { | ||||
| 	initMeter() | ||||
|  | ||||
| 	meter := global.Meter("ex.com/basic") | ||||
| 	meter := otel.Meter("ex.com/basic") | ||||
| 	observerLock := new(sync.RWMutex) | ||||
| 	observerValueToReport := new(float64) | ||||
| 	observerLabelsToReport := new([]label.KeyValue) | ||||
|   | ||||
| @@ -23,8 +23,7 @@ import ( | ||||
| 	"os" | ||||
| 	"time" | ||||
|  | ||||
| 	"go.opentelemetry.io/otel/global" | ||||
|  | ||||
| 	"go.opentelemetry.io/otel" | ||||
| 	"go.opentelemetry.io/otel/exporters/trace/zipkin" | ||||
| 	sdktrace "go.opentelemetry.io/otel/sdk/trace" | ||||
| ) | ||||
| @@ -57,7 +56,7 @@ func main() { | ||||
|  | ||||
| 	ctx := context.Background() | ||||
|  | ||||
| 	tr := global.TracerProvider().Tracer("component-main") | ||||
| 	tr := otel.GetTracerProvider().Tracer("component-main") | ||||
| 	ctx, span := tr.Start(ctx, "foo") | ||||
| 	<-time.After(6 * time.Millisecond) | ||||
| 	bar(ctx) | ||||
| @@ -69,7 +68,7 @@ func main() { | ||||
| } | ||||
|  | ||||
| func bar(ctx context.Context) { | ||||
| 	tr := global.TracerProvider().Tracer("component-bar") | ||||
| 	tr := otel.GetTracerProvider().Tracer("component-bar") | ||||
| 	_, span := tr.Start(ctx, "bar") | ||||
| 	<-time.After(6 * time.Millisecond) | ||||
| 	span.End() | ||||
|   | ||||
| @@ -23,7 +23,7 @@ import ( | ||||
| 	"github.com/prometheus/client_golang/prometheus" | ||||
| 	"github.com/prometheus/client_golang/prometheus/promhttp" | ||||
|  | ||||
| 	"go.opentelemetry.io/otel/global" | ||||
| 	"go.opentelemetry.io/otel" | ||||
| 	"go.opentelemetry.io/otel/label" | ||||
| 	"go.opentelemetry.io/otel/metric" | ||||
| 	"go.opentelemetry.io/otel/metric/number" | ||||
| @@ -135,7 +135,7 @@ func InstallNewPipeline(config Config, options ...pull.Option) (*Exporter, error | ||||
| 	if err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
| 	global.SetMeterProvider(exp.MeterProvider()) | ||||
| 	otel.SetMeterProvider(exp.MeterProvider()) | ||||
| 	return exp, nil | ||||
| } | ||||
|  | ||||
| @@ -209,7 +209,7 @@ func (c *collector) Collect(ch chan<- prometheus.Metric) { | ||||
|  | ||||
| 	ctrl := c.exp.Controller() | ||||
| 	if err := ctrl.Collect(context.Background()); err != nil { | ||||
| 		global.Handle(err) | ||||
| 		otel.Handle(err) | ||||
| 	} | ||||
|  | ||||
| 	err := ctrl.ForEach(c.exp, func(record export.Record) error { | ||||
| @@ -254,7 +254,7 @@ func (c *collector) Collect(ch chan<- prometheus.Metric) { | ||||
| 		return nil | ||||
| 	}) | ||||
| 	if err != nil { | ||||
| 		global.Handle(err) | ||||
| 		otel.Handle(err) | ||||
| 	} | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -22,8 +22,8 @@ import ( | ||||
|  | ||||
| 	"google.golang.org/grpc/credentials" | ||||
|  | ||||
| 	"go.opentelemetry.io/otel" | ||||
| 	"go.opentelemetry.io/otel/exporters/otlp" | ||||
| 	"go.opentelemetry.io/otel/global" | ||||
| 	sdktrace "go.opentelemetry.io/otel/sdk/trace" | ||||
| ) | ||||
|  | ||||
| @@ -36,7 +36,7 @@ func Example_insecure() { | ||||
| 		ctx, cancel := context.WithTimeout(context.Background(), time.Second) | ||||
| 		defer cancel() | ||||
| 		if err := exp.Shutdown(ctx); err != nil { | ||||
| 			global.Handle(err) | ||||
| 			otel.Handle(err) | ||||
| 		} | ||||
| 	}() | ||||
|  | ||||
| @@ -49,9 +49,9 @@ func Example_insecure() { | ||||
| 			sdktrace.WithMaxExportBatchSize(10), | ||||
| 		), | ||||
| 	) | ||||
| 	global.SetTracerProvider(tp) | ||||
| 	otel.SetTracerProvider(tp) | ||||
|  | ||||
| 	tracer := global.Tracer("test-tracer") | ||||
| 	tracer := otel.Tracer("test-tracer") | ||||
|  | ||||
| 	// Then use the OpenTelemetry tracing library, like we normally would. | ||||
| 	ctx, span := tracer.Start(context.Background(), "CollectorExporter-Example") | ||||
| @@ -80,7 +80,7 @@ func Example_withTLS() { | ||||
| 		ctx, cancel := context.WithTimeout(context.Background(), time.Second) | ||||
| 		defer cancel() | ||||
| 		if err := exp.Shutdown(ctx); err != nil { | ||||
| 			global.Handle(err) | ||||
| 			otel.Handle(err) | ||||
| 		} | ||||
| 	}() | ||||
|  | ||||
| @@ -93,9 +93,9 @@ func Example_withTLS() { | ||||
| 			sdktrace.WithMaxExportBatchSize(10), | ||||
| 		), | ||||
| 	) | ||||
| 	global.SetTracerProvider(tp) | ||||
| 	otel.SetTracerProvider(tp) | ||||
|  | ||||
| 	tracer := global.Tracer("test-tracer") | ||||
| 	tracer := otel.Tracer("test-tracer") | ||||
|  | ||||
| 	// Then use the OpenTelemetry tracing library, like we normally would. | ||||
| 	ctx, span := tracer.Start(context.Background(), "Securely-Talking-To-Collector-Span") | ||||
|   | ||||
| @@ -18,8 +18,8 @@ import ( | ||||
| 	"context" | ||||
| 	"log" | ||||
|  | ||||
| 	"go.opentelemetry.io/otel" | ||||
| 	"go.opentelemetry.io/otel/exporters/stdout" | ||||
| 	"go.opentelemetry.io/otel/global" | ||||
| 	"go.opentelemetry.io/otel/label" | ||||
| 	"go.opentelemetry.io/otel/metric" | ||||
| 	"go.opentelemetry.io/otel/trace" | ||||
| @@ -31,12 +31,12 @@ const ( | ||||
| ) | ||||
|  | ||||
| var ( | ||||
| 	tracer = global.TracerProvider().Tracer( | ||||
| 	tracer = otel.GetTracerProvider().Tracer( | ||||
| 		instrumentationName, | ||||
| 		trace.WithInstrumentationVersion(instrumentationVersion), | ||||
| 	) | ||||
|  | ||||
| 	meter = global.MeterProvider().Meter( | ||||
| 	meter = otel.GetMeterProvider().Meter( | ||||
| 		instrumentationName, | ||||
| 		metric.WithInstrumentationVersion(instrumentationVersion), | ||||
| 	) | ||||
|   | ||||
| @@ -15,7 +15,7 @@ | ||||
| package stdout // import "go.opentelemetry.io/otel/exporters/stdout" | ||||
|  | ||||
| import ( | ||||
| 	"go.opentelemetry.io/otel/global" | ||||
| 	"go.opentelemetry.io/otel" | ||||
| 	"go.opentelemetry.io/otel/sdk/export/metric" | ||||
| 	exporttrace "go.opentelemetry.io/otel/sdk/export/trace" | ||||
| 	"go.opentelemetry.io/otel/sdk/metric/controller/push" | ||||
| @@ -87,7 +87,7 @@ func InstallNewPipeline(exportOpts []Option, pushOpts []push.Option) (*push.Cont | ||||
| 	if err != nil { | ||||
| 		return controller, err | ||||
| 	} | ||||
| 	global.SetTracerProvider(tracerProvider) | ||||
| 	global.SetMeterProvider(controller.MeterProvider()) | ||||
| 	otel.SetTracerProvider(tracerProvider) | ||||
| 	otel.SetMeterProvider(controller.MeterProvider()) | ||||
| 	return controller, err | ||||
| } | ||||
|   | ||||
| @@ -20,7 +20,7 @@ import ( | ||||
| 	"strconv" | ||||
| 	"strings" | ||||
|  | ||||
| 	"go.opentelemetry.io/otel/global" | ||||
| 	"go.opentelemetry.io/otel" | ||||
| 	"go.opentelemetry.io/otel/label" | ||||
| ) | ||||
|  | ||||
| @@ -81,7 +81,7 @@ func ProcessFromEnv() Process { | ||||
| 	if e := os.Getenv(envTags); e != "" { | ||||
| 		tags, err := parseTags(e) | ||||
| 		if err != nil { | ||||
| 			global.Handle(err) | ||||
| 			otel.Handle(err) | ||||
| 		} else { | ||||
| 			p.Tags = tags | ||||
| 		} | ||||
|   | ||||
| @@ -22,9 +22,9 @@ import ( | ||||
|  | ||||
| 	"google.golang.org/api/support/bundler" | ||||
|  | ||||
| 	"go.opentelemetry.io/otel" | ||||
| 	"go.opentelemetry.io/otel/codes" | ||||
| 	gen "go.opentelemetry.io/otel/exporters/trace/jaeger/internal/gen-go/jaeger" | ||||
| 	"go.opentelemetry.io/otel/global" | ||||
| 	"go.opentelemetry.io/otel/label" | ||||
| 	export "go.opentelemetry.io/otel/sdk/export/trace" | ||||
| 	sdktrace "go.opentelemetry.io/otel/sdk/trace" | ||||
| @@ -129,7 +129,7 @@ func NewRawExporter(endpointOption EndpointOption, opts ...Option) (*Exporter, e | ||||
| 	} | ||||
| 	bundler := bundler.NewBundler((*gen.Span)(nil), func(bundle interface{}) { | ||||
| 		if err := e.upload(bundle.([]*gen.Span)); err != nil { | ||||
| 			global.Handle(err) | ||||
| 			otel.Handle(err) | ||||
| 		} | ||||
| 	}) | ||||
|  | ||||
| @@ -182,7 +182,7 @@ func InstallNewPipeline(endpointOption EndpointOption, opts ...Option) (func(), | ||||
| 		return nil, err | ||||
| 	} | ||||
|  | ||||
| 	global.SetTracerProvider(tp) | ||||
| 	otel.SetTracerProvider(tp) | ||||
| 	return flushFn, nil | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -28,9 +28,9 @@ import ( | ||||
| 	"github.com/stretchr/testify/require" | ||||
| 	"google.golang.org/api/support/bundler" | ||||
|  | ||||
| 	"go.opentelemetry.io/otel" | ||||
| 	"go.opentelemetry.io/otel/codes" | ||||
| 	gen "go.opentelemetry.io/otel/exporters/trace/jaeger/internal/gen-go/jaeger" | ||||
| 	"go.opentelemetry.io/otel/global" | ||||
| 	ottest "go.opentelemetry.io/otel/internal/testing" | ||||
| 	"go.opentelemetry.io/otel/label" | ||||
| 	export "go.opentelemetry.io/otel/sdk/export/trace" | ||||
| @@ -81,9 +81,9 @@ func TestInstallNewPipeline(t *testing.T) { | ||||
| 			defer fn() | ||||
|  | ||||
| 			assert.NoError(t, err) | ||||
| 			assert.IsType(t, tc.expectedProvider, global.TracerProvider()) | ||||
| 			assert.IsType(t, tc.expectedProvider, otel.GetTracerProvider()) | ||||
|  | ||||
| 			global.SetTracerProvider(nil) | ||||
| 			otel.SetTracerProvider(nil) | ||||
| 		}) | ||||
| 	} | ||||
| } | ||||
| @@ -144,7 +144,7 @@ func TestNewExportPipeline(t *testing.T) { | ||||
| 			defer fn() | ||||
|  | ||||
| 			assert.NoError(t, err) | ||||
| 			assert.NotEqual(t, tp, global.TracerProvider()) | ||||
| 			assert.NotEqual(t, tp, otel.GetTracerProvider()) | ||||
| 			assert.IsType(t, tc.expectedProviderType, tp) | ||||
|  | ||||
| 			if tc.testSpanSampling { | ||||
| @@ -342,8 +342,8 @@ func TestExporter_ExportSpan(t *testing.T) { | ||||
| 		sdktrace.WithConfig(sdktrace.Config{DefaultSampler: sdktrace.AlwaysSample()}), | ||||
| 		sdktrace.WithSyncer(exp), | ||||
| 	) | ||||
| 	global.SetTracerProvider(tp) | ||||
| 	_, span := global.Tracer("test-tracer").Start(context.Background(), "test-span") | ||||
| 	otel.SetTracerProvider(tp) | ||||
| 	_, span := otel.Tracer("test-tracer").Start(context.Background(), "test-span") | ||||
| 	span.End() | ||||
|  | ||||
| 	assert.True(t, span.SpanContext().IsValid()) | ||||
|   | ||||
| @@ -26,7 +26,7 @@ import ( | ||||
| 	"net/url" | ||||
| 	"sync" | ||||
|  | ||||
| 	"go.opentelemetry.io/otel/global" | ||||
| 	"go.opentelemetry.io/otel" | ||||
| 	export "go.opentelemetry.io/otel/sdk/export/trace" | ||||
| 	sdktrace "go.opentelemetry.io/otel/sdk/trace" | ||||
| ) | ||||
| @@ -133,7 +133,7 @@ func InstallNewPipeline(collectorURL, serviceName string, opts ...Option) error | ||||
| 		return err | ||||
| 	} | ||||
|  | ||||
| 	global.SetTracerProvider(tp) | ||||
| 	otel.SetTracerProvider(tp) | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -30,8 +30,8 @@ import ( | ||||
| 	"github.com/stretchr/testify/assert" | ||||
| 	"github.com/stretchr/testify/require" | ||||
|  | ||||
| 	"go.opentelemetry.io/otel" | ||||
| 	"go.opentelemetry.io/otel/codes" | ||||
| 	"go.opentelemetry.io/otel/global" | ||||
| 	export "go.opentelemetry.io/otel/sdk/export/trace" | ||||
| 	sdktrace "go.opentelemetry.io/otel/sdk/trace" | ||||
| 	"go.opentelemetry.io/otel/trace" | ||||
| @@ -48,7 +48,7 @@ func TestInstallNewPipeline(t *testing.T) { | ||||
| 		serviceName, | ||||
| 	) | ||||
| 	assert.NoError(t, err) | ||||
| 	assert.IsType(t, &sdktrace.TracerProvider{}, global.TracerProvider()) | ||||
| 	assert.IsType(t, &sdktrace.TracerProvider{}, otel.GetTracerProvider()) | ||||
| } | ||||
|  | ||||
| func TestNewExportPipeline(t *testing.T) { | ||||
| @@ -90,7 +90,7 @@ func TestNewExportPipeline(t *testing.T) { | ||||
| 				tc.options..., | ||||
| 			) | ||||
| 			assert.NoError(t, err) | ||||
| 			assert.NotEqual(t, tp, global.TracerProvider()) | ||||
| 			assert.NotEqual(t, tp, otel.GetTracerProvider()) | ||||
|  | ||||
| 			if tc.testSpanSampling { | ||||
| 				_, span := tp.Tracer("zipkin test").Start(context.Background(), tc.name) | ||||
|   | ||||
| @@ -1,20 +0,0 @@ | ||||
| // 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 provides global providers, propagators and more. | ||||
| // | ||||
| // This package is currently in a pre-GA phase. Backwards incompatible changes | ||||
| // may be introduced in subsequent minor version releases as we work to track | ||||
| // the evolving OpenTelemetry specification and user feedback. | ||||
| package global // import "go.opentelemetry.io/otel/global" | ||||
| @@ -12,15 +12,13 @@ | ||||
| // See the License for the specific language governing permissions and | ||||
| // limitations under the License. | ||||
| 
 | ||||
| package global // import "go.opentelemetry.io/otel/global" | ||||
| package otel // import "go.opentelemetry.io/otel" | ||||
| 
 | ||||
| import ( | ||||
| 	"log" | ||||
| 	"os" | ||||
| 	"sync" | ||||
| 	"sync/atomic" | ||||
| 
 | ||||
| 	"go.opentelemetry.io/otel" | ||||
| ) | ||||
| 
 | ||||
| var ( | ||||
| @@ -37,7 +35,7 @@ var ( | ||||
| 	delegateErrorHandlerOnce sync.Once | ||||
| 
 | ||||
| 	// Comiple time check that loggingErrorHandler implements ErrorHandler. | ||||
| 	_ otel.ErrorHandler = (*loggingErrorHandler)(nil) | ||||
| 	_ ErrorHandler = (*loggingErrorHandler)(nil) | ||||
| ) | ||||
| 
 | ||||
| // loggingErrorHandler logs all errors to STDERR. | ||||
| @@ -48,7 +46,7 @@ type loggingErrorHandler struct { | ||||
| } | ||||
| 
 | ||||
| // setDelegate sets the ErrorHandler delegate if one is not already set. | ||||
| func (h *loggingErrorHandler) setDelegate(d otel.ErrorHandler) { | ||||
| func (h *loggingErrorHandler) setDelegate(d ErrorHandler) { | ||||
| 	if h.delegate.Load() != nil { | ||||
| 		// Delegate already registered | ||||
| 		return | ||||
| @@ -56,26 +54,26 @@ func (h *loggingErrorHandler) setDelegate(d otel.ErrorHandler) { | ||||
| 	h.delegate.Store(d) | ||||
| } | ||||
| 
 | ||||
| // Handle implements otel.ErrorHandler. | ||||
| // Handle implements ErrorHandler. | ||||
| func (h *loggingErrorHandler) Handle(err error) { | ||||
| 	if d := h.delegate.Load(); d != nil { | ||||
| 		d.(otel.ErrorHandler).Handle(err) | ||||
| 		d.(ErrorHandler).Handle(err) | ||||
| 		return | ||||
| 	} | ||||
| 	h.l.Print(err) | ||||
| } | ||||
| 
 | ||||
| // ErrorHandler returns the global ErrorHandler instance. If no ErrorHandler | ||||
| // GetErrorHandler returns the global ErrorHandler instance. If no ErrorHandler | ||||
| // instance has been set (`SetErrorHandler`), the default ErrorHandler which | ||||
| // logs errors to STDERR is returned. | ||||
| func ErrorHandler() otel.ErrorHandler { | ||||
| func GetErrorHandler() ErrorHandler { | ||||
| 	return globalErrorHandler | ||||
| } | ||||
| 
 | ||||
| // SetErrorHandler sets the global ErrorHandler to be h. | ||||
| func SetErrorHandler(h otel.ErrorHandler) { | ||||
| func SetErrorHandler(h ErrorHandler) { | ||||
| 	delegateErrorHandlerOnce.Do(func() { | ||||
| 		current := ErrorHandler() | ||||
| 		current := GetErrorHandler() | ||||
| 		if current == h { | ||||
| 			return | ||||
| 		} | ||||
| @@ -87,5 +85,5 @@ func SetErrorHandler(h otel.ErrorHandler) { | ||||
| 
 | ||||
| // Handle is a convience function for ErrorHandler().Handle(err) | ||||
| func Handle(err error) { | ||||
| 	ErrorHandler().Handle(err) | ||||
| 	GetErrorHandler().Handle(err) | ||||
| } | ||||
| @@ -12,7 +12,7 @@ | ||||
| // See the License for the specific language governing permissions and | ||||
| // limitations under the License. | ||||
| 
 | ||||
| package global | ||||
| package otel | ||||
| 
 | ||||
| import ( | ||||
| 	"bytes" | ||||
| @@ -66,7 +66,7 @@ func (s *HandlerTestSuite) SetupTest() { | ||||
| 
 | ||||
| func (s *HandlerTestSuite) TestGlobalHandler() { | ||||
| 	errs := []string{"one", "two"} | ||||
| 	ErrorHandler().Handle(errors.New(errs[0])) | ||||
| 	GetErrorHandler().Handle(errors.New(errs[0])) | ||||
| 	Handle(errors.New(errs[1])) | ||||
| 	s.Assert().Equal(errs, s.errLogger.Got()) | ||||
| } | ||||
| @@ -12,24 +12,24 @@ | ||||
| // See the License for the specific language governing permissions and | ||||
| // limitations under the License. | ||||
| 
 | ||||
| package internal_test | ||||
| package global_test | ||||
| 
 | ||||
| import ( | ||||
| 	"context" | ||||
| 	"testing" | ||||
| 
 | ||||
| 	"go.opentelemetry.io/otel/global" | ||||
| 	"go.opentelemetry.io/otel/global/internal" | ||||
| 	"go.opentelemetry.io/otel" | ||||
| 	"go.opentelemetry.io/otel/internal/global" | ||||
| 	"go.opentelemetry.io/otel/label" | ||||
| ) | ||||
| 
 | ||||
| func BenchmarkGlobalInt64CounterAddNoSDK(b *testing.B) { | ||||
| 	// Compare with BenchmarkGlobalInt64CounterAddWithSDK() in | ||||
| 	// ../../../sdk/metric/benchmark_test.go to see the overhead of the | ||||
| 	// ../../sdk/metric/benchmark_test.go to see the overhead of the | ||||
| 	// global no-op system against a registered SDK. | ||||
| 	internal.ResetForTest() | ||||
| 	global.ResetForTest() | ||||
| 	ctx := context.Background() | ||||
| 	sdk := global.Meter("test") | ||||
| 	sdk := otel.Meter("test") | ||||
| 	labs := []label.KeyValue{label.String("A", "B")} | ||||
| 	cnt := Must(sdk).NewInt64Counter("int64.counter") | ||||
| 
 | ||||
| @@ -42,9 +42,9 @@ func BenchmarkGlobalInt64CounterAddNoSDK(b *testing.B) { | ||||
| 
 | ||||
| func BenchmarkStartEndSpanNoSDK(b *testing.B) { | ||||
| 	// Compare with BenchmarkStartEndSpan() in | ||||
| 	// ../../../sdk/trace/benchmark_test.go. | ||||
| 	internal.ResetForTest() | ||||
| 	t := global.Tracer("Benchmark StartEndSpan") | ||||
| 	// ../../sdk/trace/benchmark_test.go. | ||||
| 	global.ResetForTest() | ||||
| 	t := otel.Tracer("Benchmark StartEndSpan") | ||||
| 	ctx := context.Background() | ||||
| 	b.ResetTimer() | ||||
| 	for i := 0; i < b.N; i++ { | ||||
| @@ -12,19 +12,19 @@ | ||||
| // See the License for the specific language governing permissions and | ||||
| // limitations under the License. | ||||
| 
 | ||||
| package internal_test | ||||
| package global_test | ||||
| 
 | ||||
| import ( | ||||
| 	"os" | ||||
| 	"testing" | ||||
| 
 | ||||
| 	"go.opentelemetry.io/otel/global/internal" | ||||
| 	"go.opentelemetry.io/otel/internal/global" | ||||
| 	ottest "go.opentelemetry.io/otel/internal/testing" | ||||
| ) | ||||
| 
 | ||||
| // Ensure struct alignment prior to running tests. | ||||
| func TestMain(m *testing.M) { | ||||
| 	fieldsMap := internal.AtomicFieldOffsets() | ||||
| 	fieldsMap := global.AtomicFieldOffsets() | ||||
| 	fields := make([]ottest.FieldOffset, 0, len(fieldsMap)) | ||||
| 	for name, offset := range fieldsMap { | ||||
| 		fields = append(fields, ottest.FieldOffset{ | ||||
| @@ -12,7 +12,7 @@ | ||||
| // See the License for the specific language governing permissions and | ||||
| // limitations under the License. | ||||
| 
 | ||||
| package internal | ||||
| package global | ||||
| 
 | ||||
| import ( | ||||
| 	"context" | ||||
| @@ -12,7 +12,7 @@ | ||||
| // See the License for the specific language governing permissions and | ||||
| // limitations under the License. | ||||
| 
 | ||||
| package internal_test | ||||
| package global_test | ||||
| 
 | ||||
| import ( | ||||
| 	"context" | ||||
| @@ -21,8 +21,8 @@ import ( | ||||
| 
 | ||||
| 	"github.com/stretchr/testify/require" | ||||
| 
 | ||||
| 	"go.opentelemetry.io/otel/global" | ||||
| 	"go.opentelemetry.io/otel/global/internal" | ||||
| 	"go.opentelemetry.io/otel" | ||||
| 	"go.opentelemetry.io/otel/internal/global" | ||||
| 	"go.opentelemetry.io/otel/label" | ||||
| 	"go.opentelemetry.io/otel/metric" | ||||
| 	"go.opentelemetry.io/otel/metric/number" | ||||
| @@ -35,11 +35,11 @@ var asInt = number.NewInt64Number | ||||
| var asFloat = number.NewFloat64Number | ||||
| 
 | ||||
| func TestDirect(t *testing.T) { | ||||
| 	internal.ResetForTest() | ||||
| 	global.ResetForTest() | ||||
| 
 | ||||
| 	ctx := context.Background() | ||||
| 	meter1 := global.Meter("test1", metric.WithInstrumentationVersion("semver:v1.0.0")) | ||||
| 	meter2 := global.Meter("test2") | ||||
| 	meter1 := otel.Meter("test1", metric.WithInstrumentationVersion("semver:v1.0.0")) | ||||
| 	meter2 := otel.Meter("test2") | ||||
| 	labels1 := []label.KeyValue{label.String("A", "B")} | ||||
| 	labels2 := []label.KeyValue{label.String("C", "D")} | ||||
| 	labels3 := []label.KeyValue{label.String("E", "F")} | ||||
| @@ -67,7 +67,7 @@ func TestDirect(t *testing.T) { | ||||
| 	second.Record(ctx, 2, labels3...) | ||||
| 
 | ||||
| 	mock, provider := oteltest.NewMeterProvider() | ||||
| 	global.SetMeterProvider(provider) | ||||
| 	otel.SetMeterProvider(provider) | ||||
| 
 | ||||
| 	counter.Add(ctx, 1, labels1...) | ||||
| 	valuerecorder.Record(ctx, 3, labels1...) | ||||
| @@ -133,12 +133,12 @@ func TestDirect(t *testing.T) { | ||||
| } | ||||
| 
 | ||||
| func TestBound(t *testing.T) { | ||||
| 	internal.ResetForTest() | ||||
| 	global.ResetForTest() | ||||
| 
 | ||||
| 	// Note: this test uses opposite Float64/Int64 number kinds | ||||
| 	// vs. the above, to cover all the instruments. | ||||
| 	ctx := context.Background() | ||||
| 	glob := global.Meter("test") | ||||
| 	glob := otel.Meter("test") | ||||
| 	labels1 := []label.KeyValue{label.String("A", "B")} | ||||
| 
 | ||||
| 	counter := Must(glob).NewFloat64Counter("test.counter") | ||||
| @@ -152,7 +152,7 @@ func TestBound(t *testing.T) { | ||||
| 	boundM.Record(ctx, 2) | ||||
| 
 | ||||
| 	mock, provider := oteltest.NewMeterProvider() | ||||
| 	global.SetMeterProvider(provider) | ||||
| 	otel.SetMeterProvider(provider) | ||||
| 
 | ||||
| 	boundC.Add(ctx, 1) | ||||
| 	boundM.Record(ctx, 3) | ||||
| @@ -180,9 +180,9 @@ func TestBound(t *testing.T) { | ||||
| 
 | ||||
| func TestUnbind(t *testing.T) { | ||||
| 	// Tests Unbind with SDK never installed. | ||||
| 	internal.ResetForTest() | ||||
| 	global.ResetForTest() | ||||
| 
 | ||||
| 	glob := global.Meter("test") | ||||
| 	glob := otel.Meter("test") | ||||
| 	labels1 := []label.KeyValue{label.String("A", "B")} | ||||
| 
 | ||||
| 	counter := Must(glob).NewFloat64Counter("test.counter") | ||||
| @@ -196,15 +196,15 @@ func TestUnbind(t *testing.T) { | ||||
| } | ||||
| 
 | ||||
| func TestUnbindThenRecordOne(t *testing.T) { | ||||
| 	internal.ResetForTest() | ||||
| 	global.ResetForTest() | ||||
| 
 | ||||
| 	ctx := context.Background() | ||||
| 	mock, provider := oteltest.NewMeterProvider() | ||||
| 
 | ||||
| 	meter := global.Meter("test") | ||||
| 	meter := otel.Meter("test") | ||||
| 	counter := Must(meter).NewInt64Counter("test.counter") | ||||
| 	boundC := counter.Bind() | ||||
| 	global.SetMeterProvider(provider) | ||||
| 	otel.SetMeterProvider(provider) | ||||
| 	boundC.Unbind() | ||||
| 
 | ||||
| 	require.NotPanics(t, func() { | ||||
| @@ -230,10 +230,10 @@ func (m *meterWithConstructorError) NewSyncInstrument(_ metric.Descriptor) (metr | ||||
| } | ||||
| 
 | ||||
| func TestErrorInDeferredConstructor(t *testing.T) { | ||||
| 	internal.ResetForTest() | ||||
| 	global.ResetForTest() | ||||
| 
 | ||||
| 	ctx := context.Background() | ||||
| 	meter := global.MeterProvider().Meter("builtin") | ||||
| 	meter := otel.GetMeterProvider().Meter("builtin") | ||||
| 
 | ||||
| 	c1 := Must(meter).NewInt64Counter("test") | ||||
| 	c2 := Must(meter).NewInt64Counter("test") | ||||
| @@ -242,7 +242,7 @@ func TestErrorInDeferredConstructor(t *testing.T) { | ||||
| 	sdk := &meterProviderWithConstructorError{provider} | ||||
| 
 | ||||
| 	require.Panics(t, func() { | ||||
| 		global.SetMeterProvider(sdk) | ||||
| 		otel.SetMeterProvider(sdk) | ||||
| 	}) | ||||
| 
 | ||||
| 	c1.Add(ctx, 1) | ||||
| @@ -250,13 +250,13 @@ func TestErrorInDeferredConstructor(t *testing.T) { | ||||
| } | ||||
| 
 | ||||
| func TestImplementationIndirection(t *testing.T) { | ||||
| 	internal.ResetForTest() | ||||
| 	global.ResetForTest() | ||||
| 
 | ||||
| 	// Test that Implementation() does the proper indirection, i.e., | ||||
| 	// returns the implementation interface not the global, after | ||||
| 	// registered. | ||||
| 
 | ||||
| 	meter1 := global.Meter("test1") | ||||
| 	meter1 := otel.Meter("test1") | ||||
| 
 | ||||
| 	// Sync: no SDK yet | ||||
| 	counter := Must(meter1).NewInt64Counter("interface.counter") | ||||
| @@ -281,7 +281,7 @@ func TestImplementationIndirection(t *testing.T) { | ||||
| 
 | ||||
| 	// Register the SDK | ||||
| 	_, provider := oteltest.NewMeterProvider() | ||||
| 	global.SetMeterProvider(provider) | ||||
| 	otel.SetMeterProvider(provider) | ||||
| 
 | ||||
| 	// Repeat the above tests | ||||
| 
 | ||||
| @@ -301,16 +301,16 @@ func TestImplementationIndirection(t *testing.T) { | ||||
| } | ||||
| 
 | ||||
| func TestRecordBatchMock(t *testing.T) { | ||||
| 	internal.ResetForTest() | ||||
| 	global.ResetForTest() | ||||
| 
 | ||||
| 	meter := global.MeterProvider().Meter("builtin") | ||||
| 	meter := otel.GetMeterProvider().Meter("builtin") | ||||
| 
 | ||||
| 	counter := Must(meter).NewInt64Counter("test.counter") | ||||
| 
 | ||||
| 	meter.RecordBatch(context.Background(), nil, counter.Measurement(1)) | ||||
| 
 | ||||
| 	mock, provider := oteltest.NewMeterProvider() | ||||
| 	global.SetMeterProvider(provider) | ||||
| 	otel.SetMeterProvider(provider) | ||||
| 
 | ||||
| 	meter.RecordBatch(context.Background(), nil, counter.Measurement(1)) | ||||
| 
 | ||||
| @@ -12,7 +12,7 @@ | ||||
| // See the License for the specific language governing permissions and | ||||
| // limitations under the License. | ||||
| 
 | ||||
| package internal | ||||
| package global | ||||
| 
 | ||||
| import ( | ||||
| 	"context" | ||||
| @@ -12,23 +12,23 @@ | ||||
| // See the License for the specific language governing permissions and | ||||
| // limitations under the License. | ||||
| 
 | ||||
| package internal_test | ||||
| package global_test | ||||
| 
 | ||||
| import ( | ||||
| 	"context" | ||||
| 	"testing" | ||||
| 
 | ||||
| 	"go.opentelemetry.io/otel/global/internal" | ||||
| 	"go.opentelemetry.io/otel/internal/global" | ||||
| 	"go.opentelemetry.io/otel/oteltest" | ||||
| ) | ||||
| 
 | ||||
| func TestTextMapPropagatorDelegation(t *testing.T) { | ||||
| 	internal.ResetForTest() | ||||
| 	global.ResetForTest() | ||||
| 	ctx := context.Background() | ||||
| 	carrier := oteltest.NewTextMapCarrier(nil) | ||||
| 
 | ||||
| 	// The default should be a noop. | ||||
| 	initial := internal.TextMapPropagator() | ||||
| 	initial := global.TextMapPropagator() | ||||
| 	initial.Inject(ctx, carrier) | ||||
| 	ctx = initial.Extract(ctx, carrier) | ||||
| 	if !carrier.GotN(t, 0) || !carrier.SetN(t, 0) { | ||||
| @@ -45,7 +45,7 @@ func TestTextMapPropagatorDelegation(t *testing.T) { | ||||
| 
 | ||||
| 	// The initial propagator should use the delegate after it is set as the | ||||
| 	// global. | ||||
| 	internal.SetTextMapPropagator(delegate) | ||||
| 	global.SetTextMapPropagator(delegate) | ||||
| 	initial.Inject(ctx, carrier) | ||||
| 	ctx = initial.Extract(ctx, carrier) | ||||
| 	delegate.InjectedN(t, carrier, 2) | ||||
| @@ -53,12 +53,12 @@ func TestTextMapPropagatorDelegation(t *testing.T) { | ||||
| } | ||||
| 
 | ||||
| func TestTextMapPropagatorDelegationNil(t *testing.T) { | ||||
| 	internal.ResetForTest() | ||||
| 	global.ResetForTest() | ||||
| 	ctx := context.Background() | ||||
| 	carrier := oteltest.NewTextMapCarrier(nil) | ||||
| 
 | ||||
| 	// The default should be a noop. | ||||
| 	initial := internal.TextMapPropagator() | ||||
| 	initial := global.TextMapPropagator() | ||||
| 	initial.Inject(ctx, carrier) | ||||
| 	ctx = initial.Extract(ctx, carrier) | ||||
| 	if !carrier.GotN(t, 0) || !carrier.SetN(t, 0) { | ||||
| @@ -66,7 +66,7 @@ func TestTextMapPropagatorDelegationNil(t *testing.T) { | ||||
| 	} | ||||
| 
 | ||||
| 	// Delegation to nil should not make a change. | ||||
| 	internal.SetTextMapPropagator(nil) | ||||
| 	global.SetTextMapPropagator(nil) | ||||
| 	initial.Inject(ctx, carrier) | ||||
| 	initial.Extract(ctx, carrier) | ||||
| 	if !carrier.GotN(t, 0) || !carrier.SetN(t, 0) { | ||||
| @@ -75,8 +75,8 @@ func TestTextMapPropagatorDelegationNil(t *testing.T) { | ||||
| } | ||||
| 
 | ||||
| func TestTextMapPropagatorFields(t *testing.T) { | ||||
| 	internal.ResetForTest() | ||||
| 	initial := internal.TextMapPropagator() | ||||
| 	global.ResetForTest() | ||||
| 	initial := global.TextMapPropagator() | ||||
| 	delegate := oteltest.NewTextMapPropagator("test") | ||||
| 	delegateFields := delegate.Fields() | ||||
| 
 | ||||
| @@ -84,13 +84,13 @@ func TestTextMapPropagatorFields(t *testing.T) { | ||||
| 	if got := initial.Fields(); fieldsEqual(got, delegateFields) { | ||||
| 		t.Fatalf("testing fields (%v) matched Noop fields (%v)", delegateFields, got) | ||||
| 	} | ||||
| 	internal.SetTextMapPropagator(delegate) | ||||
| 	global.SetTextMapPropagator(delegate) | ||||
| 	// Check previous returns from global not correctly delegate. | ||||
| 	if got := initial.Fields(); !fieldsEqual(got, delegateFields) { | ||||
| 		t.Errorf("global TextMapPropagator.Fields returned %v instead of delegating, want (%v)", got, delegateFields) | ||||
| 	} | ||||
| 	// Check new calls to global. | ||||
| 	if got := internal.TextMapPropagator().Fields(); !fieldsEqual(got, delegateFields) { | ||||
| 	if got := global.TextMapPropagator().Fields(); !fieldsEqual(got, delegateFields) { | ||||
| 		t.Errorf("global TextMapPropagator.Fields returned %v, want (%v)", got, delegateFields) | ||||
| 	} | ||||
| } | ||||
| @@ -12,7 +12,7 @@ | ||||
| // See the License for the specific language governing permissions and | ||||
| // limitations under the License. | ||||
| 
 | ||||
| package internal | ||||
| package global | ||||
| 
 | ||||
| import ( | ||||
| 	"context" | ||||
| @@ -12,7 +12,7 @@ | ||||
| // See the License for the specific language governing permissions and | ||||
| // limitations under the License. | ||||
| 
 | ||||
| package internal | ||||
| package global | ||||
| 
 | ||||
| import ( | ||||
| 	"sync" | ||||
| @@ -12,25 +12,25 @@ | ||||
| // See the License for the specific language governing permissions and | ||||
| // limitations under the License. | ||||
| 
 | ||||
| package internal_test | ||||
| package global_test | ||||
| 
 | ||||
| import ( | ||||
| 	"testing" | ||||
| 
 | ||||
| 	"go.opentelemetry.io/otel/global/internal" | ||||
| 	"go.opentelemetry.io/otel/internal/global" | ||||
| ) | ||||
| 
 | ||||
| func TestResetsOfGlobalsPanic(t *testing.T) { | ||||
| 	internal.ResetForTest() | ||||
| 	global.ResetForTest() | ||||
| 	tests := map[string]func(){ | ||||
| 		"SetTextMapPropagator": func() { | ||||
| 			internal.SetTextMapPropagator(internal.TextMapPropagator()) | ||||
| 			global.SetTextMapPropagator(global.TextMapPropagator()) | ||||
| 		}, | ||||
| 		"SetTracerProvider": func() { | ||||
| 			internal.SetTracerProvider(internal.TracerProvider()) | ||||
| 			global.SetTracerProvider(global.TracerProvider()) | ||||
| 		}, | ||||
| 		"SetMeterProvider": func() { | ||||
| 			internal.SetMeterProvider(internal.MeterProvider()) | ||||
| 			global.SetMeterProvider(global.MeterProvider()) | ||||
| 		}, | ||||
| 	} | ||||
| 
 | ||||
| @@ -12,7 +12,7 @@ | ||||
| // See the License for the specific language governing permissions and | ||||
| // limitations under the License. | ||||
| 
 | ||||
| package internal | ||||
| package global | ||||
| 
 | ||||
| /* | ||||
| This file contains the forwarding implementation of the TracerProvider used as | ||||
| @@ -12,7 +12,7 @@ | ||||
| // See the License for the specific language governing permissions and | ||||
| // limitations under the License. | ||||
| 
 | ||||
| package internal_test | ||||
| package global_test | ||||
| 
 | ||||
| import ( | ||||
| 	"context" | ||||
| @@ -20,23 +20,23 @@ import ( | ||||
| 
 | ||||
| 	"github.com/stretchr/testify/assert" | ||||
| 
 | ||||
| 	"go.opentelemetry.io/otel/global" | ||||
| 	"go.opentelemetry.io/otel/global/internal" | ||||
| 	"go.opentelemetry.io/otel" | ||||
| 	"go.opentelemetry.io/otel/internal/global" | ||||
| 	"go.opentelemetry.io/otel/oteltest" | ||||
| ) | ||||
| 
 | ||||
| func TestTraceWithSDK(t *testing.T) { | ||||
| 	internal.ResetForTest() | ||||
| 	global.ResetForTest() | ||||
| 
 | ||||
| 	ctx := context.Background() | ||||
| 	gtp := global.TracerProvider() | ||||
| 	gtp := otel.GetTracerProvider() | ||||
| 	tracer1 := gtp.Tracer("pre") | ||||
| 	// This is started before an SDK was registered and should be dropped. | ||||
| 	_, span1 := tracer1.Start(ctx, "span1") | ||||
| 
 | ||||
| 	sr := new(oteltest.StandardSpanRecorder) | ||||
| 	tp := oteltest.NewTracerProvider(oteltest.WithSpanRecorder(sr)) | ||||
| 	global.SetTracerProvider(tp) | ||||
| 	otel.SetTracerProvider(tp) | ||||
| 
 | ||||
| 	// This span was started before initialization, it is expected to be dropped. | ||||
| 	span1.End() | ||||
| @@ -20,7 +20,7 @@ import ( | ||||
| 	"fmt" | ||||
| 	"sync" | ||||
|  | ||||
| 	"go.opentelemetry.io/otel/global" | ||||
| 	"go.opentelemetry.io/otel" | ||||
| 	"go.opentelemetry.io/otel/label" | ||||
| 	"go.opentelemetry.io/otel/metric" | ||||
| ) | ||||
| @@ -41,7 +41,7 @@ type AsyncCollector interface { | ||||
| type AsyncInstrumentState struct { | ||||
| 	lock sync.Mutex | ||||
|  | ||||
| 	// errorOnce will use the global.Handler to report an error | ||||
| 	// errorOnce will use the otel.Handler to report an error | ||||
| 	// once in case of an invalid runner attempting to run. | ||||
| 	errorOnce sync.Once | ||||
|  | ||||
| @@ -142,7 +142,7 @@ func (a *AsyncInstrumentState) Run(ctx context.Context, collector AsyncCollector | ||||
| 		} | ||||
|  | ||||
| 		a.errorOnce.Do(func() { | ||||
| 			global.Handle(fmt.Errorf("%w: type %T (reported once)", ErrInvalidAsyncRunner, rp)) | ||||
| 			otel.Handle(fmt.Errorf("%w: type %T (reported once)", ErrInvalidAsyncRunner, rp)) | ||||
| 		}) | ||||
| 	} | ||||
| } | ||||
|   | ||||
| @@ -12,10 +12,10 @@ | ||||
| // See the License for the specific language governing permissions and | ||||
| // limitations under the License. | ||||
| 
 | ||||
| package global // import "go.opentelemetry.io/otel/global" | ||||
| package otel // import "go.opentelemetry.io/otel" | ||||
| 
 | ||||
| import ( | ||||
| 	"go.opentelemetry.io/otel/global/internal" | ||||
| 	"go.opentelemetry.io/otel/internal/global" | ||||
| 	"go.opentelemetry.io/otel/metric" | ||||
| ) | ||||
| 
 | ||||
| @@ -28,10 +28,10 @@ import ( | ||||
| // | ||||
| // This is short for MeterProvider().Meter(name) | ||||
| func Meter(instrumentationName string, opts ...metric.MeterOption) metric.Meter { | ||||
| 	return MeterProvider().Meter(instrumentationName, opts...) | ||||
| 	return GetMeterProvider().Meter(instrumentationName, opts...) | ||||
| } | ||||
| 
 | ||||
| // MeterProvider returns the registered global meter provider.  If | ||||
| // GetMeterProvider returns the registered global meter provider.  If | ||||
| // none is registered then a default meter provider is returned that | ||||
| // forwards the Meter interface to the first registered Meter. | ||||
| // | ||||
| @@ -39,11 +39,11 @@ func Meter(instrumentationName string, opts ...metric.MeterOption) metric.Meter | ||||
| //     meter := global.MeterProvider().Meter("example.com/foo") | ||||
| // or | ||||
| //     meter := global.Meter("example.com/foo") | ||||
| func MeterProvider() metric.MeterProvider { | ||||
| 	return internal.MeterProvider() | ||||
| func GetMeterProvider() metric.MeterProvider { | ||||
| 	return global.MeterProvider() | ||||
| } | ||||
| 
 | ||||
| // SetMeterProvider registers `mp` as the global meter provider. | ||||
| func SetMeterProvider(mp metric.MeterProvider) { | ||||
| 	internal.SetMeterProvider(mp) | ||||
| 	global.SetMeterProvider(mp) | ||||
| } | ||||
| @@ -12,12 +12,11 @@ | ||||
| // See the License for the specific language governing permissions and | ||||
| // limitations under the License. | ||||
| 
 | ||||
| package global_test | ||||
| package otel | ||||
| 
 | ||||
| import ( | ||||
| 	"testing" | ||||
| 
 | ||||
| 	"go.opentelemetry.io/otel/global" | ||||
| 	"go.opentelemetry.io/otel/metric" | ||||
| ) | ||||
| 
 | ||||
| @@ -32,10 +31,10 @@ func (*testMeterProvider) Meter(_ string, _ ...metric.MeterOption) metric.Meter | ||||
| func TestMultipleGlobalMeterProvider(t *testing.T) { | ||||
| 	p1 := testMeterProvider{} | ||||
| 	p2 := metric.NoopMeterProvider{} | ||||
| 	global.SetMeterProvider(&p1) | ||||
| 	global.SetMeterProvider(&p2) | ||||
| 	SetMeterProvider(&p1) | ||||
| 	SetMeterProvider(&p2) | ||||
| 
 | ||||
| 	got := global.MeterProvider() | ||||
| 	got := GetMeterProvider() | ||||
| 	want := &p2 | ||||
| 	if got != want { | ||||
| 		t.Fatalf("MeterProvider: got %p, want %p\n", got, want) | ||||
| @@ -54,7 +54,7 @@ if [[ ${TAG_FOUND} = ${TAG} ]] ; then | ||||
|         exit -1 | ||||
| fi | ||||
|  | ||||
| # Get version for sdk/opentelemetry.go | ||||
| # Get version for version.go | ||||
| OTEL_VERSION=$(echo "${TAG}" | grep -o '^v[0-9]\+\.[0-9]\+\.[0-9]\+') | ||||
| # Strip leading v | ||||
| OTEL_VERSION="${OTEL_VERSION#v}" | ||||
| @@ -68,10 +68,10 @@ if ! git diff --quiet; then \ | ||||
| 	exit 1 | ||||
| fi | ||||
|  | ||||
| # Update sdk/opentelemetry.go | ||||
| cp ./sdk/opentelemetry.go ./sdk/opentelemetry.go.bak | ||||
| sed "s/\(return \"\)[0-9]*\.[0-9]*\.[0-9]*\"/\1${OTEL_VERSION}\"/" ./sdk/opentelemetry.go.bak >./sdk/opentelemetry.go | ||||
| rm -f ./sdk/opentelemetry.go.bak | ||||
| # Update version.go | ||||
| cp ./version.go ./version.go.bak | ||||
| sed "s/\(return \"\)[0-9]*\.[0-9]*\.[0-9]*\"/\1${OTEL_VERSION}\"/" ./version.go.bak >./version.go | ||||
| rm -f ./version.go.bak | ||||
|  | ||||
| # Update go.mod | ||||
| git checkout -b pre_release_${TAG} master | ||||
|   | ||||
| @@ -12,20 +12,20 @@ | ||||
| // See the License for the specific language governing permissions and | ||||
| // limitations under the License. | ||||
| 
 | ||||
| package global // import "go.opentelemetry.io/otel/global" | ||||
| package otel // import "go.opentelemetry.io/otel" | ||||
| 
 | ||||
| import ( | ||||
| 	"go.opentelemetry.io/otel/global/internal" | ||||
| 	"go.opentelemetry.io/otel/internal/global" | ||||
| 	"go.opentelemetry.io/otel/propagation" | ||||
| ) | ||||
| 
 | ||||
| // TextMapPropagator returns the global TextMapPropagator. If none has been | ||||
| // GetTextMapPropagator returns the global TextMapPropagator. If none has been | ||||
| // set, a No-Op TextMapPropagator is returned. | ||||
| func TextMapPropagator() propagation.TextMapPropagator { | ||||
| 	return internal.TextMapPropagator() | ||||
| func GetTextMapPropagator() propagation.TextMapPropagator { | ||||
| 	return global.TextMapPropagator() | ||||
| } | ||||
| 
 | ||||
| // SetTextMapPropagator sets propagator as the global TSetTextMapPropagator. | ||||
| func SetTextMapPropagator(propagator propagation.TextMapPropagator) { | ||||
| 	internal.SetTextMapPropagator(propagator) | ||||
| 	global.SetTextMapPropagator(propagator) | ||||
| } | ||||
| @@ -15,12 +15,12 @@ | ||||
| package propagation_test | ||||
|  | ||||
| import ( | ||||
| 	"go.opentelemetry.io/otel/global" | ||||
| 	"go.opentelemetry.io/otel" | ||||
| 	"go.opentelemetry.io/otel/propagation" | ||||
| ) | ||||
|  | ||||
| func ExampleTraceContext() { | ||||
| 	tc := propagation.TraceContext{} | ||||
| 	// Register the TraceContext propagator globally. | ||||
| 	global.SetTextMapPropagator(tc) | ||||
| 	otel.SetTextMapPropagator(tc) | ||||
| } | ||||
|   | ||||
| @@ -18,12 +18,12 @@ import ( | ||||
| 	"fmt" | ||||
| 	"time" | ||||
|  | ||||
| 	opentelemetry "go.opentelemetry.io/otel/sdk" | ||||
| 	"go.opentelemetry.io/otel" | ||||
| ) | ||||
|  | ||||
| // UserAgent is the user agent to be added to the outgoing | ||||
| // requests from the exporters. | ||||
| var UserAgent = fmt.Sprintf("opentelemetry-go/%s", opentelemetry.Version()) | ||||
| var UserAgent = fmt.Sprintf("opentelemetry-go/%s", otel.Version()) | ||||
|  | ||||
| // MonotonicEndTime returns the end time at present | ||||
| // but offset from start, monotonically. | ||||
|   | ||||
| @@ -20,7 +20,7 @@ import ( | ||||
| 	"math/rand" | ||||
| 	"testing" | ||||
|  | ||||
| 	"go.opentelemetry.io/otel/global" | ||||
| 	"go.opentelemetry.io/otel" | ||||
| 	"go.opentelemetry.io/otel/label" | ||||
| 	"go.opentelemetry.io/otel/metric" | ||||
| 	export "go.opentelemetry.io/otel/sdk/export/metric" | ||||
| @@ -214,8 +214,8 @@ func BenchmarkGlobalInt64CounterAddWithSDK(b *testing.B) { | ||||
| 	ctx := context.Background() | ||||
| 	fix := newFixture(b) | ||||
|  | ||||
| 	sdk := global.Meter("test") | ||||
| 	global.SetMeterProvider(fix) | ||||
| 	sdk := otel.Meter("test") | ||||
| 	otel.SetMeterProvider(fix) | ||||
|  | ||||
| 	labs := []label.KeyValue{label.String("A", "B")} | ||||
| 	cnt := Must(sdk).NewInt64Counter("int64.sum") | ||||
|   | ||||
| @@ -19,7 +19,7 @@ import ( | ||||
| 	"sync" | ||||
| 	"time" | ||||
|  | ||||
| 	"go.opentelemetry.io/otel/global" | ||||
| 	"go.opentelemetry.io/otel" | ||||
| 	"go.opentelemetry.io/otel/metric" | ||||
| 	"go.opentelemetry.io/otel/metric/registry" | ||||
| 	export "go.opentelemetry.io/otel/sdk/export/metric" | ||||
| @@ -144,10 +144,10 @@ func (c *Controller) tick() { | ||||
| 	c.checkpointer.StartCollection() | ||||
| 	c.accumulator.Collect(ctx) | ||||
| 	if err := c.checkpointer.FinishCollection(); err != nil { | ||||
| 		global.Handle(err) | ||||
| 		otel.Handle(err) | ||||
| 	} | ||||
|  | ||||
| 	if err := c.exporter.Export(ctx, ckpt); err != nil { | ||||
| 		global.Handle(err) | ||||
| 		otel.Handle(err) | ||||
| 	} | ||||
| } | ||||
|   | ||||
| @@ -24,7 +24,7 @@ import ( | ||||
|  | ||||
| 	"github.com/stretchr/testify/require" | ||||
|  | ||||
| 	"go.opentelemetry.io/otel/global" | ||||
| 	"go.opentelemetry.io/otel" | ||||
| 	"go.opentelemetry.io/otel/label" | ||||
| 	"go.opentelemetry.io/otel/metric" | ||||
| 	export "go.opentelemetry.io/otel/sdk/export/metric" | ||||
| @@ -61,7 +61,7 @@ var testHandler *handler | ||||
|  | ||||
| func init() { | ||||
| 	testHandler = new(handler) | ||||
| 	global.SetErrorHandler(testHandler) | ||||
| 	otel.SetErrorHandler(testHandler) | ||||
| } | ||||
|  | ||||
| func newExporter() *processorTest.Exporter { | ||||
|   | ||||
| @@ -23,7 +23,7 @@ import ( | ||||
|  | ||||
| 	"github.com/stretchr/testify/require" | ||||
|  | ||||
| 	"go.opentelemetry.io/otel/global" | ||||
| 	"go.opentelemetry.io/otel" | ||||
| 	"go.opentelemetry.io/otel/label" | ||||
| 	"go.opentelemetry.io/otel/metric" | ||||
| 	"go.opentelemetry.io/otel/metric/number" | ||||
| @@ -66,7 +66,7 @@ var testHandler *handler | ||||
|  | ||||
| func init() { | ||||
| 	testHandler = new(handler) | ||||
| 	global.SetErrorHandler(testHandler) | ||||
| 	otel.SetErrorHandler(testHandler) | ||||
| } | ||||
|  | ||||
| // correctnessProcessor could be replaced with processortest.Processor | ||||
|   | ||||
| @@ -21,7 +21,7 @@ import ( | ||||
| 	"sync" | ||||
| 	"sync/atomic" | ||||
|  | ||||
| 	"go.opentelemetry.io/otel/global" | ||||
| 	"go.opentelemetry.io/otel" | ||||
| 	internal "go.opentelemetry.io/otel/internal/metric" | ||||
| 	"go.opentelemetry.io/otel/label" | ||||
| 	"go.opentelemetry.io/otel/metric" | ||||
| @@ -164,7 +164,7 @@ func (s *syncInstrument) Implementation() interface{} { | ||||
|  | ||||
| func (a *asyncInstrument) observe(num number.Number, labels *label.Set) { | ||||
| 	if err := aggregator.RangeTest(num, &a.descriptor); err != nil { | ||||
| 		global.Handle(err) | ||||
| 		otel.Handle(err) | ||||
| 		return | ||||
| 	} | ||||
| 	recorder := a.getRecorder(labels) | ||||
| @@ -174,7 +174,7 @@ func (a *asyncInstrument) observe(num number.Number, labels *label.Set) { | ||||
| 		return | ||||
| 	} | ||||
| 	if err := recorder.Update(context.Background(), num, &a.descriptor); err != nil { | ||||
| 		global.Handle(err) | ||||
| 		otel.Handle(err) | ||||
| 		return | ||||
| 	} | ||||
| } | ||||
| @@ -434,14 +434,14 @@ func (m *Accumulator) checkpointRecord(r *record) int { | ||||
| 	} | ||||
| 	err := r.current.SynchronizedMove(r.checkpoint, &r.inst.descriptor) | ||||
| 	if err != nil { | ||||
| 		global.Handle(err) | ||||
| 		otel.Handle(err) | ||||
| 		return 0 | ||||
| 	} | ||||
|  | ||||
| 	a := export.NewAccumulation(&r.inst.descriptor, r.labels, m.resource, r.checkpoint) | ||||
| 	err = m.processor.Process(a) | ||||
| 	if err != nil { | ||||
| 		global.Handle(err) | ||||
| 		otel.Handle(err) | ||||
| 	} | ||||
| 	return 1 | ||||
| } | ||||
| @@ -459,7 +459,7 @@ func (m *Accumulator) checkpointAsync(a *asyncInstrument) int { | ||||
| 				a := export.NewAccumulation(&a.descriptor, lrec.labels, m.resource, lrec.observed) | ||||
| 				err := m.processor.Process(a) | ||||
| 				if err != nil { | ||||
| 					global.Handle(err) | ||||
| 					otel.Handle(err) | ||||
| 				} | ||||
| 				checkpointed++ | ||||
| 			} | ||||
| @@ -507,11 +507,11 @@ func (r *record) RecordOne(ctx context.Context, num number.Number) { | ||||
| 		return | ||||
| 	} | ||||
| 	if err := aggregator.RangeTest(num, &r.inst.descriptor); err != nil { | ||||
| 		global.Handle(err) | ||||
| 		otel.Handle(err) | ||||
| 		return | ||||
| 	} | ||||
| 	if err := r.current.Update(ctx, num, &r.inst.descriptor); err != nil { | ||||
| 		global.Handle(err) | ||||
| 		otel.Handle(err) | ||||
| 		return | ||||
| 	} | ||||
| 	// Record was modified, inform the Collect() that things need | ||||
| @@ -539,7 +539,7 @@ func (m *Accumulator) fromSync(sync metric.SyncImpl) *syncInstrument { | ||||
| 			return inst | ||||
| 		} | ||||
| 	} | ||||
| 	global.Handle(ErrUninitializedInstrument) | ||||
| 	otel.Handle(ErrUninitializedInstrument) | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| @@ -551,6 +551,6 @@ func (m *Accumulator) fromAsync(async metric.AsyncImpl) *asyncInstrument { | ||||
| 			return inst | ||||
| 		} | ||||
| 	} | ||||
| 	global.Handle(ErrUninitializedInstrument) | ||||
| 	otel.Handle(ErrUninitializedInstrument) | ||||
| 	return nil | ||||
| } | ||||
|   | ||||
| @@ -19,8 +19,8 @@ import ( | ||||
| 	"fmt" | ||||
| 	"os" | ||||
|  | ||||
| 	"go.opentelemetry.io/otel" | ||||
| 	"go.opentelemetry.io/otel/label" | ||||
| 	opentelemetry "go.opentelemetry.io/otel/sdk" | ||||
| 	"go.opentelemetry.io/otel/semconv" | ||||
| ) | ||||
|  | ||||
| @@ -56,7 +56,7 @@ func (TelemetrySDK) Detect(context.Context) (*Resource, error) { | ||||
| 	return NewWithAttributes( | ||||
| 		semconv.TelemetrySDKNameKey.String("opentelemetry-go"), | ||||
| 		semconv.TelemetrySDKLanguageKey.String("go"), | ||||
| 		semconv.TelemetrySDKVersionKey.String(opentelemetry.Version()), | ||||
| 		semconv.TelemetrySDKVersionKey.String(otel.Version()), | ||||
| 	), nil | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -22,9 +22,9 @@ import ( | ||||
|  | ||||
| 	"github.com/stretchr/testify/require" | ||||
|  | ||||
| 	"go.opentelemetry.io/otel" | ||||
| 	ottest "go.opentelemetry.io/otel/internal/testing" | ||||
| 	"go.opentelemetry.io/otel/label" | ||||
| 	opentelemetry "go.opentelemetry.io/otel/sdk" | ||||
| 	"go.opentelemetry.io/otel/sdk/resource" | ||||
| ) | ||||
|  | ||||
| @@ -44,7 +44,7 @@ func TestDefaultConfig(t *testing.T) { | ||||
| 		"host.name":              hostname(), | ||||
| 		"telemetry.sdk.name":     "opentelemetry-go", | ||||
| 		"telemetry.sdk.language": "go", | ||||
| 		"telemetry.sdk.version":  opentelemetry.Version(), | ||||
| 		"telemetry.sdk.version":  otel.Version(), | ||||
| 	}, toMap(res)) | ||||
| } | ||||
|  | ||||
| @@ -61,7 +61,7 @@ func TestDefaultConfigNoHost(t *testing.T) { | ||||
| 	require.EqualValues(t, map[string]string{ | ||||
| 		"telemetry.sdk.name":     "opentelemetry-go", | ||||
| 		"telemetry.sdk.language": "go", | ||||
| 		"telemetry.sdk.version":  opentelemetry.Version(), | ||||
| 		"telemetry.sdk.version":  otel.Version(), | ||||
| 	}, toMap(res)) | ||||
| } | ||||
|  | ||||
| @@ -79,7 +79,7 @@ func TestDefaultConfigNoEnv(t *testing.T) { | ||||
| 		"host.name":              hostname(), | ||||
| 		"telemetry.sdk.name":     "opentelemetry-go", | ||||
| 		"telemetry.sdk.language": "go", | ||||
| 		"telemetry.sdk.version":  opentelemetry.Version(), | ||||
| 		"telemetry.sdk.version":  otel.Version(), | ||||
| 	}, toMap(res)) | ||||
| } | ||||
|  | ||||
| @@ -99,7 +99,7 @@ func TestDefaultConfigWithEnv(t *testing.T) { | ||||
| 		"host.name":              hostname(), | ||||
| 		"telemetry.sdk.name":     "opentelemetry-go", | ||||
| 		"telemetry.sdk.language": "go", | ||||
| 		"telemetry.sdk.version":  opentelemetry.Version(), | ||||
| 		"telemetry.sdk.version":  otel.Version(), | ||||
| 	}, toMap(res)) | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -21,7 +21,7 @@ import ( | ||||
| 	"sync/atomic" | ||||
| 	"time" | ||||
|  | ||||
| 	"go.opentelemetry.io/otel/global" | ||||
| 	"go.opentelemetry.io/otel" | ||||
| 	export "go.opentelemetry.io/otel/sdk/export/trace" | ||||
| ) | ||||
|  | ||||
| @@ -182,7 +182,7 @@ func (bsp *BatchSpanProcessor) exportSpans() { | ||||
|  | ||||
| 	if len(bsp.batch) > 0 { | ||||
| 		if err := bsp.e.ExportSpans(context.Background(), bsp.batch); err != nil { | ||||
| 			global.Handle(err) | ||||
| 			otel.Handle(err) | ||||
| 		} | ||||
| 		bsp.batch = bsp.batch[:0] | ||||
| 	} | ||||
|   | ||||
| @@ -19,7 +19,7 @@ import ( | ||||
| 	"sync" | ||||
| 	"sync/atomic" | ||||
|  | ||||
| 	"go.opentelemetry.io/otel/global" | ||||
| 	"go.opentelemetry.io/otel" | ||||
| 	"go.opentelemetry.io/otel/trace" | ||||
|  | ||||
| 	export "go.opentelemetry.io/otel/sdk/export/trace" | ||||
| @@ -144,7 +144,7 @@ func (p *TracerProvider) UnregisterSpanProcessor(s SpanProcessor) { | ||||
| 	} | ||||
| 	if stopOnce != nil { | ||||
| 		stopOnce.state.Do(func() { | ||||
| 			global.Handle(s.Shutdown(context.Background())) | ||||
| 			otel.Handle(s.Shutdown(context.Background())) | ||||
| 		}) | ||||
| 	} | ||||
| 	if len(new) > 1 { | ||||
| @@ -192,7 +192,7 @@ func (p *TracerProvider) Shutdown(ctx context.Context) error { | ||||
|  | ||||
| 	for _, sps := range spss { | ||||
| 		sps.state.Do(func() { | ||||
| 			global.Handle(sps.sp.Shutdown(ctx)) | ||||
| 			otel.Handle(sps.sp.Shutdown(ctx)) | ||||
| 		}) | ||||
| 	} | ||||
| 	return nil | ||||
|   | ||||
| @@ -17,7 +17,7 @@ package trace // import "go.opentelemetry.io/otel/sdk/trace" | ||||
| import ( | ||||
| 	"context" | ||||
|  | ||||
| 	"go.opentelemetry.io/otel/global" | ||||
| 	"go.opentelemetry.io/otel" | ||||
| 	export "go.opentelemetry.io/otel/sdk/export/trace" | ||||
| ) | ||||
|  | ||||
| @@ -46,7 +46,7 @@ func (ssp *SimpleSpanProcessor) OnStart(parent context.Context, sd *export.SpanD | ||||
| func (ssp *SimpleSpanProcessor) OnEnd(sd *export.SpanData) { | ||||
| 	if ssp.e != nil && sd.SpanContext.IsSampled() { | ||||
| 		if err := ssp.e.ExportSpans(context.Background(), []*export.SpanData{sd}); err != nil { | ||||
| 			global.Handle(err) | ||||
| 			otel.Handle(err) | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
|   | ||||
| @@ -21,8 +21,8 @@ import ( | ||||
| 	"sync" | ||||
| 	"time" | ||||
|  | ||||
| 	"go.opentelemetry.io/otel" | ||||
| 	"go.opentelemetry.io/otel/codes" | ||||
| 	"go.opentelemetry.io/otel/global" | ||||
| 	"go.opentelemetry.io/otel/label" | ||||
| 	"go.opentelemetry.io/otel/trace" | ||||
|  | ||||
| @@ -208,7 +208,7 @@ func (s *span) SetName(name string) { | ||||
| 	defer s.mu.Unlock() | ||||
|  | ||||
| 	if s.data == nil { | ||||
| 		global.Handle(errUninitializedSpan) | ||||
| 		otel.Handle(errUninitializedSpan) | ||||
| 		return | ||||
| 	} | ||||
| 	s.data.Name = name | ||||
|   | ||||
| @@ -25,8 +25,8 @@ import ( | ||||
| 	"testing" | ||||
| 	"time" | ||||
|  | ||||
| 	"go.opentelemetry.io/otel" | ||||
| 	"go.opentelemetry.io/otel/codes" | ||||
| 	"go.opentelemetry.io/otel/global" | ||||
| 	"go.opentelemetry.io/otel/label" | ||||
| 	"go.opentelemetry.io/otel/oteltest" | ||||
| 	"go.opentelemetry.io/otel/trace" | ||||
| @@ -54,7 +54,7 @@ func init() { | ||||
| 	tid, _ = trace.TraceIDFromHex("01020304050607080102040810203040") | ||||
| 	sid, _ = trace.SpanIDFromHex("0102040810203040") | ||||
|  | ||||
| 	global.SetErrorHandler(new(discardHandler)) | ||||
| 	otel.SetErrorHandler(new(discardHandler)) | ||||
| } | ||||
|  | ||||
| func TestTracerFollowsExpectedAPIBehaviour(t *testing.T) { | ||||
|   | ||||
| @@ -12,10 +12,10 @@ | ||||
| // See the License for the specific language governing permissions and | ||||
| // limitations under the License. | ||||
| 
 | ||||
| package global // import "go.opentelemetry.io/otel/global" | ||||
| package otel // import "go.opentelemetry.io/otel" | ||||
| 
 | ||||
| import ( | ||||
| 	"go.opentelemetry.io/otel/global/internal" | ||||
| 	"go.opentelemetry.io/otel/internal/global" | ||||
| 	"go.opentelemetry.io/otel/trace" | ||||
| ) | ||||
| 
 | ||||
| @@ -24,21 +24,21 @@ import ( | ||||
| // | ||||
| // This is short for TracerProvider().Tracer(name) | ||||
| func Tracer(name string) trace.Tracer { | ||||
| 	return TracerProvider().Tracer(name) | ||||
| 	return GetTracerProvider().Tracer(name) | ||||
| } | ||||
| 
 | ||||
| // TracerProvider returns the registered global trace provider. | ||||
| // If none is registered then an instance of NoopTracerProvider is returned. | ||||
| // | ||||
| // Use the trace provider to create a named tracer. E.g. | ||||
| //     tracer := global.TracerProvider().Tracer("example.com/foo") | ||||
| //     tracer := global.GetTracerProvider().Tracer("example.com/foo") | ||||
| // or | ||||
| //     tracer := global.Tracer("example.com/foo") | ||||
| func TracerProvider() trace.TracerProvider { | ||||
| 	return internal.TracerProvider() | ||||
| func GetTracerProvider() trace.TracerProvider { | ||||
| 	return global.TracerProvider() | ||||
| } | ||||
| 
 | ||||
| // SetTracerProvider registers `tp` as the global trace provider. | ||||
| func SetTracerProvider(tp trace.TracerProvider) { | ||||
| 	internal.SetTracerProvider(tp) | ||||
| 	global.SetTracerProvider(tp) | ||||
| } | ||||
| @@ -12,12 +12,11 @@ | ||||
| // See the License for the specific language governing permissions and | ||||
| // limitations under the License. | ||||
| 
 | ||||
| package global_test | ||||
| package otel | ||||
| 
 | ||||
| import ( | ||||
| 	"testing" | ||||
| 
 | ||||
| 	"go.opentelemetry.io/otel/global" | ||||
| 	"go.opentelemetry.io/otel/internal/trace/noop" | ||||
| 	"go.opentelemetry.io/otel/trace" | ||||
| ) | ||||
| @@ -33,10 +32,10 @@ func (*testTracerProvider) Tracer(_ string, _ ...trace.TracerOption) trace.Trace | ||||
| func TestMultipleGlobalTracerProvider(t *testing.T) { | ||||
| 	p1 := testTracerProvider{} | ||||
| 	p2 := trace.NewNoopTracerProvider() | ||||
| 	global.SetTracerProvider(&p1) | ||||
| 	global.SetTracerProvider(p2) | ||||
| 	SetTracerProvider(&p1) | ||||
| 	SetTracerProvider(p2) | ||||
| 
 | ||||
| 	got := global.TracerProvider() | ||||
| 	got := GetTracerProvider() | ||||
| 	want := p2 | ||||
| 	if got != want { | ||||
| 		t.Fatalf("TracerProvider: got %p, want %p\n", got, want) | ||||
| @@ -12,12 +12,7 @@ | ||||
| // See the License for the specific language governing permissions and | ||||
| // limitations under the License. | ||||
| 
 | ||||
| // Package opentelemetry contains Go support for OpenTelemetry. | ||||
| // | ||||
| // This package is currently in a pre-GA phase. Backwards incompatible changes | ||||
| // may be introduced in subsequent minor version releases as we work to track | ||||
| // the evolving OpenTelemetry specification and user feedback. | ||||
| package opentelemetry // import "go.opentelemetry.io/otel/sdk" | ||||
| package otel // import "go.opentelemetry.io/otel" | ||||
| 
 | ||||
| // Version is the current release version of OpenTelemetry in use. | ||||
| func Version() string { | ||||
		Reference in New Issue
	
	Block a user