@@ -27,8 +27,7 @@ type BaseExporter struct {
2727 component.StartFunc
2828 component.ShutdownFunc
2929
30- Marshaler exporterqueue.Marshaler [request.Request ]
31- Unmarshaler exporterqueue.Unmarshaler [request.Request ]
30+ encoding exporterqueue.Encoding [request.Request ]
3231
3332 Set exporter.Settings
3433
@@ -45,18 +44,16 @@ type BaseExporter struct {
4544
4645 ConsumerOptions []consumer.Option
4746
48- timeoutCfg TimeoutConfig
49- retryCfg configretry.BackOffConfig
50- queueFactory exporterqueue.Factory [request.Request ]
51- queueCfg exporterqueue.Config
52- batcherCfg exporterbatcher.Config
47+ timeoutCfg TimeoutConfig
48+ retryCfg configretry.BackOffConfig
49+ queueCfg exporterqueue.Config
50+ batcherCfg exporterbatcher.Config
5351}
5452
5553func NewBaseExporter (set exporter.Settings , signal pipeline.Signal , options ... Option ) (* BaseExporter , error ) {
5654 be := & BaseExporter {
57- Set : set ,
58- timeoutCfg : NewDefaultTimeoutConfig (),
59- queueFactory : exporterqueue .NewMemoryQueueFactory [request.Request ](),
55+ Set : set ,
56+ timeoutCfg : NewDefaultTimeoutConfig (),
6057 }
6158
6259 for _ , op := range options {
@@ -98,11 +95,12 @@ func NewBaseExporter(set exporter.Settings, signal pipeline.Signal, options ...O
9895 }
9996
10097 if be .queueCfg .Enabled || be .batcherCfg .Enabled {
101- qSet := exporterqueue.Settings {
98+ qSet := exporterqueue.Settings [request. Request ] {
10299 Signal : signal ,
103100 ExporterSettings : set ,
101+ Encoding : be .encoding ,
104102 }
105- be .QueueSender , err = NewQueueSender (be . queueFactory , qSet , be .queueCfg , be .batcherCfg , be .ExportFailureMessage , be .firstSender )
103+ be .QueueSender , err = NewQueueSender (qSet , be .queueCfg , be .batcherCfg , be .ExportFailureMessage , be .firstSender )
106104 if err != nil {
107105 return nil , err
108106 }
@@ -199,44 +197,30 @@ func WithRetry(config configretry.BackOffConfig) Option {
199197// WithQueue overrides the default QueueConfig for an exporter.
200198// The default QueueConfig is to disable queueing.
201199// This option cannot be used with the new exporter helpers New[Traces|Metrics|Logs]RequestExporter.
202- func WithQueue (config QueueConfig ) Option {
200+ func WithQueue (cfg exporterqueue. Config ) Option {
203201 return func (o * BaseExporter ) error {
204- if o .Marshaler == nil || o . Unmarshaler == nil {
202+ if o .encoding == nil {
205203 return errors .New ("WithQueue option is not available for the new request exporters, use WithRequestQueue instead" )
206204 }
207- if ! config .Enabled {
208- o .ExportFailureMessage += " Try enabling sending_queue to survive temporary failures."
209- return nil
210- }
211- o .queueCfg = exporterqueue.Config {
212- Enabled : config .Enabled ,
213- NumConsumers : config .NumConsumers ,
214- QueueSize : config .QueueSize ,
215- Blocking : config .Blocking ,
216- }
217- o .queueFactory = exporterqueue .NewPersistentQueueFactory [request.Request ](config .StorageID , exporterqueue.PersistentQueueSettings [request.Request ]{
218- Marshaler : o .Marshaler ,
219- Unmarshaler : o .Unmarshaler ,
220- })
221- return nil
205+ return WithRequestQueue (cfg , o .encoding )(o )
222206 }
223207}
224208
225209// WithRequestQueue enables queueing for an exporter.
226210// This option should be used with the new exporter helpers New[Traces|Metrics|Logs]RequestExporter.
227211// Experimental: This API is at the early stage of development and may change without backward compatibility
228212// until https://github.com/open-telemetry/opentelemetry-collector/issues/8122 is resolved.
229- func WithRequestQueue (cfg exporterqueue.Config , queueFactory exporterqueue.Factory [request.Request ]) Option {
213+ func WithRequestQueue (cfg exporterqueue.Config , encoding exporterqueue.Encoding [request.Request ]) Option {
230214 return func (o * BaseExporter ) error {
231- if o . Marshaler != nil || o . Unmarshaler ! = nil {
232- return errors .New ("WithRequestQueue option must be used with the new request exporters only, use WithQueue instead " )
215+ if cfg . Enabled && cfg . StorageID != nil && encoding = = nil {
216+ return errors .New ("`encoding` must not be nil when persistent queue is enabled " )
233217 }
218+ o .encoding = encoding
234219 if ! cfg .Enabled {
235220 o .ExportFailureMessage += " Try enabling sending_queue to survive temporary failures."
236221 return nil
237222 }
238223 o .queueCfg = cfg
239- o .queueFactory = queueFactory
240224 return nil
241225 }
242226}
@@ -263,20 +247,11 @@ func WithBatcher(cfg exporterbatcher.Config) Option {
263247 }
264248}
265249
266- // WithMarshaler is used to set the request marshaler for the new exporter helper.
267- // It must be provided as the first option when creating a new exporter helper.
268- func WithMarshaler (marshaler exporterqueue.Marshaler [request.Request ]) Option {
269- return func (o * BaseExporter ) error {
270- o .Marshaler = marshaler
271- return nil
272- }
273- }
274-
275- // WithUnmarshaler is used to set the request unmarshaler for the new exporter helper.
250+ // WithEncoding is used to set the request encoding for the new exporter helper.
276251// It must be provided as the first option when creating a new exporter helper.
277- func WithUnmarshaler ( unmarshaler exporterqueue.Unmarshaler [request.Request ]) Option {
252+ func WithEncoding ( encoding exporterqueue.Encoding [request.Request ]) Option {
278253 return func (o * BaseExporter ) error {
279- o .Unmarshaler = unmarshaler
254+ o .encoding = encoding
280255 return nil
281256 }
282257}
0 commit comments