Skip to content

Commit

Permalink
Merge branch 'main' into fix-attr-val-truncate
Browse files Browse the repository at this point in the history
  • Loading branch information
pellared authored Nov 25, 2024
2 parents b1e79c4 + 814a413 commit 02d307f
Show file tree
Hide file tree
Showing 10 changed files with 160 additions and 118 deletions.
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ linters:
- unconvert
- unused
- unparam
- usestdlibvars

issues:
# Maximum issues count per one linter.
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

## [Unreleased]

### Added

- Add `Reset` method to `SpanRecorder` in `go.opentelemetry.io/otel/sdk/trace/tracetest`. (#5994)

### Changed

- The default global API now supports full auto-instrumentation from the `go.opentelemetry.io/auto` package.
Expand Down
8 changes: 4 additions & 4 deletions propagation/baggage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func TestExtractValidBaggageFromHTTPReq(t *testing.T) {

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
req, _ := http.NewRequest("GET", "http://example.com", nil)
req, _ := http.NewRequest(http.MethodGet, "http://example.com", nil)
req.Header.Set("baggage", tt.header)

ctx := context.Background()
Expand Down Expand Up @@ -173,7 +173,7 @@ func TestExtractInvalidDistributedContextFromHTTPReq(t *testing.T) {

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
req, _ := http.NewRequest("GET", "http://example.com", nil)
req, _ := http.NewRequest(http.MethodGet, "http://example.com", nil)
req.Header.Set("baggage", tt.header)

expected := tt.has.Baggage(t)
Expand Down Expand Up @@ -226,7 +226,7 @@ func TestInjectBaggageToHTTPReq(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
req, _ := http.NewRequest("GET", "http://example.com", nil)
req, _ := http.NewRequest(http.MethodGet, "http://example.com", nil)
ctx := baggage.ContextWithBaggage(context.Background(), tt.mems.Baggage(t))
propagator.Inject(ctx, propagation.HeaderCarrier(req.Header))

Expand Down Expand Up @@ -273,7 +273,7 @@ func TestBaggageInjectExtractRoundtrip(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
b := tt.mems.Baggage(t)
req, _ := http.NewRequest("GET", "http://example.com", nil)
req, _ := http.NewRequest(http.MethodGet, "http://example.com", nil)
ctx := baggage.ContextWithBaggage(context.Background(), b)
propagator.Inject(ctx, propagation.HeaderCarrier(req.Header))

Expand Down
6 changes: 3 additions & 3 deletions propagation/trace_context_benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,22 +56,22 @@ func BenchmarkExtract(b *testing.B) {

func extractSubBenchmarks(b *testing.B, fn func(*testing.B, *http.Request)) {
b.Run("Sampled", func(b *testing.B) {
req, _ := http.NewRequest("GET", "http://example.com", nil)
req, _ := http.NewRequest(http.MethodGet, "http://example.com", nil)
req.Header.Set("traceparent", "00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01")
b.ReportAllocs()

fn(b, req)
})

b.Run("BogusVersion", func(b *testing.B) {
req, _ := http.NewRequest("GET", "http://example.com", nil)
req, _ := http.NewRequest(http.MethodGet, "http://example.com", nil)
req.Header.Set("traceparent", "qw-00000000000000000000000000000000-0000000000000000-01")
b.ReportAllocs()
fn(b, req)
})

b.Run("FutureAdditionalData", func(b *testing.B) {
req, _ := http.NewRequest("GET", "http://example.com", nil)
req, _ := http.NewRequest(http.MethodGet, "http://example.com", nil)
req.Header.Set("traceparent", "02-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-09-XYZxsf09")
b.ReportAllocs()
fn(b, req)
Expand Down
13 changes: 13 additions & 0 deletions sdk/trace/tracetest/recorder.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,19 @@ func (sr *SpanRecorder) Started() []sdktrace.ReadWriteSpan {
return dst
}

// Reset clears the recorded spans.
//
// This method is safe to be called concurrently.
func (sr *SpanRecorder) Reset() {
sr.startedMu.Lock()
sr.endedMu.Lock()
defer sr.startedMu.Unlock()
defer sr.endedMu.Unlock()

sr.started = nil
sr.ended = nil
}

// Ended returns a copy of all ended spans that have been recorded.
//
// This method is safe to be called concurrently.
Expand Down
24 changes: 24 additions & 0 deletions sdk/trace/tracetest/recorder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,27 @@ func TestStartingConcurrentSafe(t *testing.T) {

assert.Len(t, sr.Started(), 2)
}

func TestResetConcurrentSafe(t *testing.T) {
sr := NewSpanRecorder()
ctx := context.Background()

runConcurrently(
func() { sr.OnStart(ctx, new(rwSpan)) },
func() { sr.OnStart(ctx, new(rwSpan)) },
func() { sr.OnEnd(new(roSpan)) },
func() { sr.OnEnd(new(roSpan)) },
)

assert.Len(t, sr.Started(), 2)
assert.Len(t, sr.Ended(), 2)

runConcurrently(
func() { sr.Reset() },
func() { sr.Reset() },
func() { sr.Reset() },
)

assert.Empty(t, sr.Started())
assert.Empty(t, sr.Ended())
}
Loading

0 comments on commit 02d307f

Please sign in to comment.