Skip to content

Commit

Permalink
test(storage): fix trace span test (googleapis#11272)
Browse files Browse the repository at this point in the history
  • Loading branch information
tritone authored Dec 11, 2024
1 parent d448fbb commit 2f94a82
Showing 1 changed file with 38 additions and 3 deletions.
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

0 comments on commit 2f94a82

Please sign in to comment.