Skip to content

Commit 6961cde

Browse files
committed
Fix test
1 parent 49896f3 commit 6961cde

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

internal/fs/wrappers/monitoring.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,7 @@ func WithMonitoring(fs fuseutil.FileSystem) fuseutil.FileSystem {
320320

321321
type monitoring struct {
322322
wrapped fuseutil.FileSystem
323+
tracer trace.Tracer
323324
}
324325

325326
func (fs *monitoring) Destroy() {

internal/fs/wrappers/monitoring_test.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"syscall"
2121
"testing"
2222

23+
"github.com/googlecloudplatform/gcsfuse/v2/internal/monitor"
2324
"github.com/jacobsa/fuse/fuseops"
2425
"github.com/stretchr/testify/assert"
2526
"github.com/stretchr/testify/require"
@@ -113,6 +114,7 @@ func newInMemoryExporter(t *testing.T) *tracetest.InMemoryExporter {
113114
ex.Reset()
114115
})
115116
otel.SetTracerProvider(sdktrace.NewTracerProvider(sdktrace.WithSyncer(ex)))
117+
monitor.ResetTracer()
116118
return ex
117119
}
118120

@@ -236,8 +238,11 @@ func (d dummyFS) Fallocate(_ context.Context, _ *fuseops.FallocateOp) error {
236238

237239
func (d dummyFS) Destroy() {}
238240

239-
func TestSpan(t *testing.T) {
241+
func TestSpanCreation(t *testing.T) {
240242
ex := newInMemoryExporter(t)
243+
t.Cleanup(func() {
244+
ex.Reset()
245+
})
241246
m := monitoring{
242247
wrapped: dummyFS{},
243248
}

internal/monitor/trace.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,20 @@ import (
2626
// TODO: name is subject to change.
2727
const name = "cloud.google.com/gcsfuse"
2828

29-
var tracerProvider trace.TracerProvider = noop.NewTracerProvider()
30-
var once sync.Once
29+
var (
30+
tracer = noop.NewTracerProvider().Tracer("noop")
31+
once sync.Once
32+
)
3133

3234
// StartSpan creates a new span and returns it along with the context that's augmented with the newly-created span..
3335
func StartSpan(ctx context.Context, spanName string, opts ...trace.SpanStartOption) (context.Context, trace.Span) {
3436
once.Do(func() {
35-
tracerProvider = otel.GetTracerProvider()
37+
// Expect that the tracer provider has been configured by the SDK before the first call to StartSpan is made.
38+
ResetTracer()
3639
})
37-
return tracerProvider.Tracer(name).Start(ctx, spanName, opts...)
40+
return tracer.Start(ctx, spanName, opts...)
41+
}
42+
43+
func ResetTracer() {
44+
tracer = otel.GetTracerProvider().Tracer(name)
3845
}

0 commit comments

Comments
 (0)