Skip to content

Commit

Permalink
Merge branch 'main' into duplicate_total_fix
Browse files Browse the repository at this point in the history
  • Loading branch information
dashpole authored Jul 27, 2023
2 parents be61e38 + 4f0d73c commit 0fcb642
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- Log a suggested view that fixes instrument conflicts in `go.opentelemetry.io/otel/sdk/metric`. (#4349)
- Fix possible panic, deadlock and race condition in batch span processor in `go.opentelemetry.io/otel/sdk/trace`. (#4353)
- Do not append _total if the counter already ends in total in the `go.opentelemetry.io/otel/exporter/prometheus` exporter. (#4373)
- Improve context cancelation handling in batch span processor's `ForceFlush` in `go.opentelemetry.io/otel/sdk/trace`. (#4369)

## [1.16.0/0.39.0] 2023-05-18

Expand Down
5 changes: 5 additions & 0 deletions sdk/trace/batch_span_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,11 @@ func (f forceFlushSpan) SpanContext() trace.SpanContext {

// ForceFlush exports all ended spans that have not yet been exported.
func (bsp *batchSpanProcessor) ForceFlush(ctx context.Context) error {
// Interrupt if context is already canceled.
if err := ctx.Err(); err != nil {
return err
}

// Do nothing after Shutdown.
if bsp.stopped.Load() {
return nil
Expand Down
12 changes: 12 additions & 0 deletions sdk/trace/batch_span_processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,18 @@ func TestBatchSpanProcessorForceFlushCancellation(t *testing.T) {
}
}

func TestBatchSpanProcessorForceFlushTimeout(t *testing.T) {
// Add timeout to context to test deadline
ctx, cancel := context.WithTimeout(context.Background(), time.Nanosecond)
defer cancel()
<-ctx.Done()

bsp := sdktrace.NewBatchSpanProcessor(indefiniteExporter{})
if got, want := bsp.ForceFlush(ctx), context.DeadlineExceeded; !errors.Is(got, want) {
t.Errorf("expected %q error, got %v", want, got)
}
}

func TestBatchSpanProcessorForceFlushQueuedSpans(t *testing.T) {
ctx := context.Background()

Expand Down

0 comments on commit 0fcb642

Please sign in to comment.