swift-otel
swift-otel copied to clipboard
Add buffering policies to OTelBatchSpanProcessor sequences to prevent memleaks
I hope this can be considered as a general improvement for the library.
After testing with Heaptrack when trying to track down a memleak in my application, I found an issue in OTelBatchSpanProcessor. With how the async sequences are implemented, it is possible for events to pile up if the export() function gets stuck trying to export a batch and failing to export to the OTel endpoint, causing a memleak.
To fix this, I added buffering policies to all the stream sequence producers to avoid this pileup. Only the last event is used in each sequence and all piled up events are discarded.
With this fix at least this portion of the application did not memleak anymore. There was another memleak in grpc-swift that I found, but that may be a more difficult fix and may even be resolved in V2.