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-11-07 00:13:31 +02:00
|
|
|
"go.opentelemetry.io/otel/trace"
|
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-11-07 00:13:31 +02:00
|
|
|
func NewTracerPair(tracer trace.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
|
|
|
|
2023-04-12 02:28:13 +02:00
|
|
|
// NewTracerPairWithContext is a convenience function. It calls NewTracerPair
|
2022-05-19 22:15:07 +02:00
|
|
|
// and returns a hooked version of ctx with the created BridgeTracer along
|
|
|
|
// with the BridgeTracer and WrapperTracerProvider.
|
2020-11-07 00:13:31 +02:00
|
|
|
func NewTracerPairWithContext(ctx context.Context, tracer trace.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
|
|
|
|
}
|