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

test(storage): fix trace span test #11272

Merged
merged 2 commits into from
Dec 11, 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
41 changes: 38 additions & 3 deletions storage/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ import (
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/googleapis/gax-go/v2/apierror"
"go.opentelemetry.io/contrib/detectors/gcp"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/sdk/resource"
sdktrace "go.opentelemetry.io/otel/sdk/trace"
"go.opentelemetry.io/otel/sdk/trace/tracetest"
"golang.org/x/oauth2/google"
"google.golang.org/api/googleapi"
"google.golang.org/api/iterator"
Expand Down Expand Up @@ -5859,10 +5862,10 @@ func TestIntegration_PostPolicyV4_SignedURL_WithSignBytes(t *testing.T) {
})
}

func TestIntegration_OCTracing(t *testing.T) {
func TestIntegration_OTelTracing(t *testing.T) {
multiTransportTest(context.Background(), t, func(t *testing.T, ctx context.Context, bucket string, _ string, client *Client) {
te := testutil.NewTestExporter()
defer te.Unregister()
te := newOpenTelemetryTestExporter()
defer te.Unregister(ctx)

bkt := client.Bucket(bucket)
bkt.Attrs(ctx)
Expand All @@ -5873,6 +5876,38 @@ func TestIntegration_OCTracing(t *testing.T) {
})
}

// openTelemetryTestExporter is a test utility exporter. It should be created
// with NewopenTelemetryTestExporter.
type openTelemetryTestExporter struct {
exporter *tracetest.InMemoryExporter
tp *sdktrace.TracerProvider
}

// newOpenTelemetryTestExporter creates a openTelemetryTestExporter with
// underlying InMemoryExporter and TracerProvider from OpenTelemetry.
func newOpenTelemetryTestExporter() *openTelemetryTestExporter {
exporter := tracetest.NewInMemoryExporter()
tp := sdktrace.NewTracerProvider(
sdktrace.WithSyncer(exporter),
sdktrace.WithSampler(sdktrace.AlwaysSample()),
)
otel.SetTracerProvider(tp)
return &openTelemetryTestExporter{
exporter: exporter,
tp: tp,
}
}

// Spans returns the current in-memory stored spans.
func (te *openTelemetryTestExporter) Spans() tracetest.SpanStubs {
return te.exporter.GetSpans()
}

// Unregister shuts down the underlying OpenTelemetry TracerProvider.
func (te *openTelemetryTestExporter) Unregister(ctx context.Context) {
te.tp.Shutdown(ctx)
}

// verifySignedURL gets the bytes at the provided url and verifies them against the
// expectedFileBody. Make sure the SignedURLOptions set the method as "GET".
func verifySignedURL(url string, headers map[string][]string, expectedFileBody []byte) error {
Expand Down
Loading