Skip to content

Commit 2f94a82

Browse files
authored
test(storage): fix trace span test (#11272)
Fixes #11264
1 parent d448fbb commit 2f94a82

File tree

1 file changed

+38
-3
lines changed

1 file changed

+38
-3
lines changed

storage/integration_test.go

+38-3
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,10 @@ import (
5454
"github.com/google/go-cmp/cmp/cmpopts"
5555
"github.com/googleapis/gax-go/v2/apierror"
5656
"go.opentelemetry.io/contrib/detectors/gcp"
57+
"go.opentelemetry.io/otel"
5758
"go.opentelemetry.io/otel/sdk/resource"
59+
sdktrace "go.opentelemetry.io/otel/sdk/trace"
60+
"go.opentelemetry.io/otel/sdk/trace/tracetest"
5861
"golang.org/x/oauth2/google"
5962
"google.golang.org/api/googleapi"
6063
"google.golang.org/api/iterator"
@@ -5859,10 +5862,10 @@ func TestIntegration_PostPolicyV4_SignedURL_WithSignBytes(t *testing.T) {
58595862
})
58605863
}
58615864

5862-
func TestIntegration_OCTracing(t *testing.T) {
5865+
func TestIntegration_OTelTracing(t *testing.T) {
58635866
multiTransportTest(context.Background(), t, func(t *testing.T, ctx context.Context, bucket string, _ string, client *Client) {
5864-
te := testutil.NewTestExporter()
5865-
defer te.Unregister()
5867+
te := newOpenTelemetryTestExporter()
5868+
defer te.Unregister(ctx)
58665869

58675870
bkt := client.Bucket(bucket)
58685871
bkt.Attrs(ctx)
@@ -5873,6 +5876,38 @@ func TestIntegration_OCTracing(t *testing.T) {
58735876
})
58745877
}
58755878

5879+
// openTelemetryTestExporter is a test utility exporter. It should be created
5880+
// with NewopenTelemetryTestExporter.
5881+
type openTelemetryTestExporter struct {
5882+
exporter *tracetest.InMemoryExporter
5883+
tp *sdktrace.TracerProvider
5884+
}
5885+
5886+
// newOpenTelemetryTestExporter creates a openTelemetryTestExporter with
5887+
// underlying InMemoryExporter and TracerProvider from OpenTelemetry.
5888+
func newOpenTelemetryTestExporter() *openTelemetryTestExporter {
5889+
exporter := tracetest.NewInMemoryExporter()
5890+
tp := sdktrace.NewTracerProvider(
5891+
sdktrace.WithSyncer(exporter),
5892+
sdktrace.WithSampler(sdktrace.AlwaysSample()),
5893+
)
5894+
otel.SetTracerProvider(tp)
5895+
return &openTelemetryTestExporter{
5896+
exporter: exporter,
5897+
tp: tp,
5898+
}
5899+
}
5900+
5901+
// Spans returns the current in-memory stored spans.
5902+
func (te *openTelemetryTestExporter) Spans() tracetest.SpanStubs {
5903+
return te.exporter.GetSpans()
5904+
}
5905+
5906+
// Unregister shuts down the underlying OpenTelemetry TracerProvider.
5907+
func (te *openTelemetryTestExporter) Unregister(ctx context.Context) {
5908+
te.tp.Shutdown(ctx)
5909+
}
5910+
58765911
// verifySignedURL gets the bytes at the provided url and verifies them against the
58775912
// expectedFileBody. Make sure the SignedURLOptions set the method as "GET".
58785913
func verifySignedURL(url string, headers map[string][]string, expectedFileBody []byte) error {

0 commit comments

Comments
 (0)