2020-03-24 07:41:10 +02:00
|
|
|
// Copyright The OpenTelemetry Authors
|
2019-09-25 08:12:22 +02:00
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
|
2020-11-04 19:10:58 +02:00
|
|
|
package opentracing // import "go.opentelemetry.io/otel/bridge/opentracing"
|
2019-09-25 08:12:22 +02:00
|
|
|
|
|
|
|
import (
|
2020-03-10 19:32:01 +02:00
|
|
|
"context"
|
|
|
|
|
2020-10-09 04:58:56 +02:00
|
|
|
"go.opentelemetry.io/otel"
|
2019-09-25 08:12:22 +02:00
|
|
|
)
|
|
|
|
|
2020-09-24 00:16:13 +02:00
|
|
|
// NewTracerPair is a utility function that creates a BridgeTracer and a
|
|
|
|
// WrapperTracerProvider. WrapperTracerProvider creates a single instance of
|
2019-10-22 22:19:11 +02:00
|
|
|
// WrapperTracer. The BridgeTracer forwards the calls to the WrapperTracer
|
2020-09-24 00:16:13 +02:00
|
|
|
// that wraps the passed tracer. BridgeTracer and WrapperTracerProvider are
|
|
|
|
// returned to the caller and the caller is expected to register BridgeTracer
|
|
|
|
// with opentracing and WrapperTracerProvider with opentelemetry.
|
2020-10-09 04:58:56 +02:00
|
|
|
func NewTracerPair(tracer otel.Tracer) (*BridgeTracer, *WrapperTracerProvider) {
|
2019-09-25 08:12:22 +02:00
|
|
|
bridgeTracer := NewBridgeTracer()
|
2020-09-24 00:16:13 +02:00
|
|
|
wrapperProvider := NewWrappedTracerProvider(bridgeTracer, tracer)
|
2019-11-25 19:46:07 +02:00
|
|
|
bridgeTracer.SetOpenTelemetryTracer(wrapperProvider.Tracer(""))
|
2019-10-22 22:19:11 +02:00
|
|
|
return bridgeTracer, wrapperProvider
|
2019-09-25 08:12:22 +02:00
|
|
|
}
|
2020-03-10 19:32:01 +02:00
|
|
|
|
2020-10-09 04:58:56 +02:00
|
|
|
func NewTracerPairWithContext(ctx context.Context, tracer otel.Tracer) (context.Context, *BridgeTracer, *WrapperTracerProvider) {
|
2020-03-10 19:32:01 +02:00
|
|
|
bridgeTracer, wrapperProvider := NewTracerPair(tracer)
|
|
|
|
ctx = bridgeTracer.NewHookedContext(ctx)
|
|
|
|
return ctx, bridgeTracer, wrapperProvider
|
|
|
|
}
|