Skip to content

Commit

Permalink
Fix race conditions in otelsarama.WrapAsyncProducer (#755)
Browse files Browse the repository at this point in the history
* Fix possible race condition in WrapAsyncProducer

* Add changelog

Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
  • Loading branch information
pellared and MrAlias committed Jun 24, 2021
1 parent 077af5a commit 6d226af
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

## [Unreleased]

### Fixed

- Fix race conditions in `otelsarama.WrapAsyncProducer`.
The `messaging.message_id` and `messaging.kafka.partition` attributes are now not set if a message was not processed. (#755)

## [0.21.0] - 2021-06-18

### Fixed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func WrapAsyncProducer(saramaConfig *sarama.Config, p sarama.AsyncProducer, opts
// cannot be closed.
defer func() {
for _, mc := range producerMessageContexts {
finishProducerSpan(mc.span, 0, 0, nil)
mc.span.End()
}
}()
defer close(wrapped.successes)
Expand Down Expand Up @@ -194,7 +194,7 @@ func WrapAsyncProducer(saramaConfig *sarama.Config, p sarama.AsyncProducer, opts
// If returning successes isn't enabled, we just finish the
// span right away because there's no way to know when it will
// be done.
finishProducerSpan(span, msg.Partition, msg.Offset, nil)
span.End()
}
case msg, ok := <-p.Successes():
if !ok {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,6 @@ func TestWrapAsyncProducer(t *testing.T) {
semconv.MessagingSystemKey.String("kafka"),
semconv.MessagingDestinationKindTopic,
semconv.MessagingDestinationKey.String(topic),
semconv.MessagingMessageIDKey.String("0"),
kafkaPartitionKey.Int64(0),
},
parentSpanID: oteltrace.SpanID{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x2},
kind: oteltrace.SpanKindProducer,
Expand All @@ -199,8 +197,6 @@ func TestWrapAsyncProducer(t *testing.T) {
semconv.MessagingSystemKey.String("kafka"),
semconv.MessagingDestinationKindTopic,
semconv.MessagingDestinationKey.String(topic),
semconv.MessagingMessageIDKey.String("0"),
kafkaPartitionKey.Int64(0),
},
kind: oteltrace.SpanKindProducer,
},
Expand Down

0 comments on commit 6d226af

Please sign in to comment.