Skip to content

Commit f7b3616

Browse files
refactor(tracing): Move propagate context method to traceHandle (#4319)
### Description Move propagate context method to traceHandle. ### Link to the issue in case of a bug fix. b/479039670 ### Testing details Existing unit tests & integration tests must pass. ### Any backward incompatible change? If so, please explain. N/A
1 parent f4d11fa commit f7b3616

File tree

6 files changed

+17
-34
lines changed

6 files changed

+17
-34
lines changed

internal/fs/fs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1757,7 +1757,7 @@ func (fs *fileSystem) getInterruptlessContext(ctx context.Context) context.Conte
17571757
// When ignore interrupts config is set, we are creating a new context not
17581758
// cancellable by parent context.
17591759
newCtx := context.Background()
1760-
return tracing.MaybePropagateTraceContext(newCtx, ctx, fs.isTracingEnabled)
1760+
return fs.traceHandle.PropagateTraceContext(newCtx, ctx)
17611761
}
17621762

17631763
return ctx

internal/fs/tracing_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ func createTestFileSystemWithTraces(ctx context.Context, t *testing.T, ignoreInt
8383
},
8484
},
8585
SequentialReadSizeMb: 200,
86+
TraceHandle: tracing.NewOTELTracer(),
8687
}
8788
server, err := fs.NewFileSystem(ctx, serverCfg)
8889
require.NoError(t, err, "NewFileSystem")

tracing/noop_tracer.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ func (*noopTracer) EndSpan(span trace.Span) {}
3535

3636
func (*noopTracer) RecordError(span trace.Span, err error) {}
3737

38+
// Return the new context as it is as this is a no-op implementation
39+
func (*noopTracer) PropagateTraceContext(newCtx context.Context, _ context.Context) context.Context {
40+
return newCtx
41+
}
42+
3843
func NewNoopTracer() TraceHandle {
3944
return new(noopTracer)
4045
}

tracing/otel_tracer.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ func (o *otelTracer) RecordError(span trace.Span, err error) {
4343
span.SetStatus(codes.Error, err.Error())
4444
}
4545

46+
func (o *otelTracer) PropagateTraceContext(newCtx context.Context, oldCtx context.Context) context.Context {
47+
span := trace.SpanFromContext(oldCtx)
48+
return trace.ContextWithSpan(newCtx, span)
49+
}
50+
4651
func NewOTELTracer() TraceHandle {
4752
return &otelTracer{
4853
tracer: otel.Tracer(name),

tracing/trace_handle.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import (
2020
"go.opentelemetry.io/otel/trace"
2121
)
2222

23+
const name = "cloud.google.com/gcsfuse"
24+
2325
// TraceHandle provides an interface for recording traces, trace links and everything related to tracing. This allows easier switching between various trace-implementations, especially with a custom no-op tracer.
2426
type TraceHandle interface {
2527
// Start a span with a given name & context
@@ -33,4 +35,7 @@ type TraceHandle interface {
3335

3436
// Record an error on the span for export in case of failure
3537
RecordError(span trace.Span, err error)
38+
39+
// A handle interface method to retain relevant span data in new context from the older context
40+
PropagateTraceContext(newCtx context.Context, oldCtx context.Context) context.Context
3641
}

tracing/util.go

Lines changed: 0 additions & 33 deletions
This file was deleted.

0 commit comments

Comments
 (0)