-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(redisotel): ability to override TracerProvider (#1998)
- Loading branch information
Showing
4 changed files
with
112 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package redisotel_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/go-redis/redis/extra/redisotel/v8" | ||
"github.com/go-redis/redis/v8" | ||
"go.opentelemetry.io/otel" | ||
"go.opentelemetry.io/otel/trace" | ||
) | ||
|
||
func TestNew(t *testing.T) { | ||
// this also functions as a compile-time test that the | ||
// TracingHook conforms to the Hook interface | ||
var _ redis.Hook = redisotel.NewTracingHook() | ||
} | ||
|
||
type providerFunc func(name string, opts ...trace.TracerOption) trace.Tracer | ||
|
||
func (fn providerFunc) Tracer(name string, opts ...trace.TracerOption) trace.Tracer { | ||
return fn(name, opts...) | ||
} | ||
|
||
func TestNewWithTracerProvider(t *testing.T) { | ||
invoked := false | ||
|
||
tp := providerFunc(func(name string, opts ...trace.TracerOption) trace.Tracer { | ||
invoked = true | ||
return otel.GetTracerProvider().Tracer(name, opts...) | ||
}) | ||
|
||
_ = redisotel.NewTracingHook(redisotel.WithTracerProvider(tp)) | ||
|
||
if !invoked { | ||
t.Fatalf("did not call custom TraceProvider") | ||
} | ||
} |