2020-03-23 22:41:10 -07:00
|
|
|
// Copyright The OpenTelemetry Authors
|
2024-02-29 07:05:28 +01:00
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
2019-08-02 13:52:55 -07:00
|
|
|
|
2020-11-16 18:30:54 +01:00
|
|
|
package otel
|
2019-08-02 13:52:55 -07:00
|
|
|
|
|
|
|
import (
|
2019-10-22 13:19:11 -07:00
|
|
|
"testing"
|
2019-08-02 13:52:55 -07:00
|
|
|
|
2021-12-15 07:42:37 -08:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
2020-11-06 23:13:31 +01:00
|
|
|
"go.opentelemetry.io/otel/trace"
|
2023-10-19 10:16:24 -07:00
|
|
|
"go.opentelemetry.io/otel/trace/embedded"
|
|
|
|
"go.opentelemetry.io/otel/trace/noop"
|
2019-08-02 13:52:55 -07:00
|
|
|
)
|
|
|
|
|
2023-10-19 10:16:24 -07:00
|
|
|
type testTracerProvider struct{ embedded.TracerProvider }
|
2019-10-22 13:19:11 -07:00
|
|
|
|
2020-11-06 23:13:31 +01:00
|
|
|
var _ trace.TracerProvider = &testTracerProvider{}
|
2019-10-22 13:19:11 -07:00
|
|
|
|
2020-11-06 23:13:31 +01:00
|
|
|
func (*testTracerProvider) Tracer(_ string, _ ...trace.TracerOption) trace.Tracer {
|
2023-10-19 10:16:24 -07:00
|
|
|
return noop.NewTracerProvider().Tracer("")
|
2019-10-22 13:19:11 -07:00
|
|
|
}
|
|
|
|
|
2020-04-27 16:07:14 -07:00
|
|
|
func TestMultipleGlobalTracerProvider(t *testing.T) {
|
2020-08-31 10:02:04 -07:00
|
|
|
p1 := testTracerProvider{}
|
2023-10-19 10:16:24 -07:00
|
|
|
p2 := noop.NewTracerProvider()
|
2020-11-16 18:30:54 +01:00
|
|
|
SetTracerProvider(&p1)
|
|
|
|
SetTracerProvider(p2)
|
2019-10-22 13:19:11 -07:00
|
|
|
|
2020-11-16 18:30:54 +01:00
|
|
|
got := GetTracerProvider()
|
2021-12-15 07:42:37 -08:00
|
|
|
assert.Equal(t, p2, got)
|
2019-08-02 13:52:55 -07:00
|
|
|
}
|