Skip to content

Commit

Permalink
fix: NoopSpan should be instance
Browse files Browse the repository at this point in the history
  • Loading branch information
tttoad committed Jun 3, 2024
1 parent cb5c7d4 commit 0232d39
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- Identify the `Meter` returned from the global `MeterProvider` in `go.opentelemetry.io/otel/global` with its schema URL. (#5426)
- Log a warning to the OpenTelemetry internal logger when a `Span` in `go.opentelemetry.io/otel/sdk/trace` drops an attribute, event, or link due to a limit being reached. (#5434)
- Document instrument name requirements in `go.opentelemetry.io/otel/metric`. (#5435)
- `Start` in `go.opentelemetry.io/otel/trace/noop` span no longer heap allocated when the parent span is zero SpanContext. (#5457)

## [1.27.0/0.49.0/0.3.0] 2024-05-21

Expand Down
4 changes: 3 additions & 1 deletion trace/noop/noop.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,13 @@ func (t Tracer) Start(ctx context.Context, _ string, _ ...trace.SpanStartOption)
span = Span{sc: sc}
} else {
// No parent, return a No-Op span with an empty span context.
span = Span{}
span = noopSpanInstance
}
return trace.ContextWithSpan(ctx, span), span
}

var noopSpanInstance trace.Span = Span{}

// Span is an OpenTelemetry No-Op Span.
type Span struct {
embedded.Span
Expand Down
13 changes: 13 additions & 0 deletions trace/noop/noop_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,19 @@ func TestTracerStartPropagatesSpanContext(t *testing.T) {
assert.False(t, span.IsRecording(), "recording span returned")
}

func BenchmarkNoopInstance(b *testing.B) {
tracer := NewTracerProvider().Tracer("")
ctx := trace.ContextWithSpanContext(context.Background(), trace.SpanContext{})

b.ReportAllocs()
b.ResetTimer()

for i := 0; i < b.N; i++ {
_, span := tracer.Start(ctx, "")
span.End()
}
}

type recordingSpan struct{ Span }

func (recordingSpan) IsRecording() bool { return true }

0 comments on commit 0232d39

Please sign in to comment.