Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

testing(bigquery): fix legacy trace test #10411

Merged
merged 2 commits into from
Jun 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 22 additions & 10 deletions bigquery/trace_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"testing"
"time"

traceinternal "cloud.google.com/go/internal/trace"
"go.opencensus.io/trace"
)

Expand Down Expand Up @@ -49,11 +50,20 @@ func (te *testExporter) hasSpans(names []string) []string {
return unmatched
}

func TestIntegration_Tracing(t *testing.T) {
func TestIntegration_OpenCensusTracing(t *testing.T) {
if client == nil {
t.Skip("Integration tests skipped")
}

if !traceinternal.IsOpenCensusTracingEnabled() {
t.Logf("enabling opencensus tracing")
traceinternal.SetOpenTelemetryTracingEnabledField(false)
defer func() {
t.Logf("enabling otel tracing")
traceinternal.SetOpenTelemetryTracingEnabledField(true)
}()
}

ctx := context.Background()

for _, tc := range []struct {
Expand Down Expand Up @@ -85,15 +95,17 @@ func TestIntegration_Tracing(t *testing.T) {
wantSpans: []string{"bigquery.tables.get", "cloud.google.com/go/bigquery.Table.Metadata"},
},
} {
exporter := &testExporter{}
trace.RegisterExporter(exporter)
traceCtx, span := trace.StartSpan(ctx, "testspan", trace.WithSampler(trace.AlwaysSample()))
tc.callF(traceCtx)
span.End()
trace.UnregisterExporter(exporter)
t.Run(tc.description, func(t *testing.T) {
exporter := &testExporter{}
trace.RegisterExporter(exporter)
traceCtx, span := trace.StartSpan(ctx, "testspan", trace.WithSampler(trace.AlwaysSample()))
tc.callF(traceCtx)
span.End()
trace.UnregisterExporter(exporter)

if unmatched := exporter.hasSpans(tc.wantSpans); len(unmatched) > 0 {
t.Errorf("case (%s): unmatched spans: %s", tc.description, strings.Join(unmatched, ","))
}
if unmatched := exporter.hasSpans(tc.wantSpans); len(unmatched) > 0 {
t.Errorf("case (%s): unmatched spans: %s", tc.description, strings.Join(unmatched, ","))
}
})
}
}
Loading