feat: add async-await APIs for exporters#46
feat: add async-await APIs for exporters#46gmoraleda wants to merge 6 commits intoopen-telemetry:mainfrom
Conversation
b0006b3 to
9b09eb6
Compare
90ddf33 to
495deb8
Compare
|
We are not sure this is the preferred approach for adding asynchronous support to export methods, we would prefer to have async variants of the existing methods and protocols not new classes. Default no-op implementations should be provided in the extension of the protocol until everything is migrated. |
|
Thanks for the feedback! Will push the updated PR shortly. |
|
hmm, thinking about it: with no-op as default implementation, an exporter calling the async method would silently succeed without exporting anything. Should we bridge to the existing methods instead? @nachoBonafonte |
Replace separate AsyncSpanExporter, AsyncLogRecordExporter, and AsyncMetricExporter protocols with async extension methods on the existing SpanExporter, LogRecordExporter, and MetricExporter protocols. Default implementations bridge to sync methods. Multi-exporters use withTaskGroup for SpanExporter (Sendable) and sequential dispatch for LogRecordExporter (not Sendable). No runtime type-checking needed. Addresses review feedback on open-telemetry#46.
495deb8 to
2c000d3
Compare
|
Another option is adding something like assert(false) which would make it fail in Debug while development to be sure that misuse is detected during development |
|
Also regarding the methods, they don't need a new name, the compiler should select the appropriate one just with the async in the definition, and use the async method when called with await |
Add new async protocols (AsyncSpanExporter, AsyncLogRecordExporter, AsyncMetricExporter) that refine the existing sync exporter protocols, enabling truly non-blocking exports for network-based exporters. Default implementations bridge to sync methods via base protocol cast, so existing exporters work unchanged. MultiSpanExporter and MultiLogRecordExporter gain concurrent export via withTaskGroup. Multi-exporters partition children into async (Sendable, concurrent via TaskGroup) and sync (sequential, never cross concurrency boundaries), avoiding @unchecked Sendable wrappers. Also adds Sendable conformance to ExportResult and SpanExporterResultCode, marks MultiLogRecordExporter as @unchecked Sendable with immutable storage. Closes open-telemetry#34
…tioning logic Add Sendable conformance to AsyncSpanExporter for consistency with AsyncLogRecordExporter and AsyncMetricExporter. Extract repeated async/sync exporter partitioning in MultiLogRecordExporter into a private helper method.
Replace separate AsyncSpanExporter, AsyncLogRecordExporter, and AsyncMetricExporter protocols with async extension methods on the existing SpanExporter, LogRecordExporter, and MetricExporter protocols. Default implementations bridge to sync methods. Multi-exporters use withTaskGroup for SpanExporter (Sendable) and sequential dispatch for LogRecordExporter (not Sendable). No runtime type-checking needed. Addresses review feedback on open-telemetry#46.
…rtionFailure defaults Promote async methods from extension-only to protocol requirements on SpanExporter, LogRecordExporter, and MetricExporter. Default implementations use assertionFailure() to catch misuse during development. This ensures proper dynamic dispatch through protocol-typed references and convenience overload chains—extension-only methods use static dispatch, which silently resolves to the wrong implementation. Existing conformers compile without changes since the defaults satisfy the new requirements.
Swift disambiguates sync/async overloads by the `async` keyword, so the methods can share names with their sync counterparts.
054ec3c to
8f39c19
Compare
|
/rerun |
Summary
Adds async overloads to the three exporter protocols (
SpanExporter,LogRecordExporter,MetricExporter) so callers can useawait exporter.export(...)in async contexts.asynckeywordassertionFailureto surface unimplemented async methods during developmentexplicitTimeoutdelegate to the primary async methodsMultiSpanExporterruns child exporters concurrently viaTaskGroup;MultiLogRecordExportercalls children sequentiallyExportResultandSpanExporterResultCodeare nowSendableMultiLogRecordExportergains@unchecked Sendableconformance (immutable stored property)Test plan
AsyncSpanExporterTests,AsyncLogRecordExporterTests,AsyncMetricExporterTestscovering: