otel test

This commit is contained in:
Rangel Reale 2023-02-14 10:04:31 -03:00
parent 095fb1c110
commit 140a1d26d7
1 changed files with 29 additions and 0 deletions

View File

@ -59,3 +59,32 @@ func TestWithDBStatement(t *testing.T) {
t.Fatal(err)
}
}
func TestWithSpanName(t *testing.T) {
provider := sdktrace.NewTracerProvider()
hook := newTracingHook(
"",
WithTracerProvider(provider),
WithSpanName(func(hook TracingHook, defaultName string) string {
if hook == TracingHookProcess {
return "redis." + defaultName
}
return defaultName
}),
)
ctx, span := provider.Tracer("redis-test").Start(context.TODO(), "redis-test")
cmd := redis.NewCmd(ctx, "ping")
defer span.End()
processHook := hook.ProcessHook(func(ctx context.Context, cmd redis.Cmder) error {
name := trace.SpanFromContext(ctx).(sdktrace.ReadOnlySpan).Name()
if name != "redis.ping" {
t.Fatal("Span name was not changed by the function")
}
return nil
})
err := processHook(ctx, cmd)
if err != nil {
t.Fatal(err)
}
}