Debian Codegraph @

exporter/exporterhelper/internal/queue_sender.go

raw symbols SCIP
1 // Copyright The OpenTelemetry Authors
2 // SPDX-License-Identifier: Apache-2.0
3
4 package internal // import "go.opentelemetry.io/collector/exporter/exporterhelper/internal"
5
6 import (
7 "context"
8 "time"
9
10 "go.uber.org/zap"
11
12 "go.opentelemetry.io/collector/config/configoptional"
13 "go.opentelemetry.io/collector/exporter/exporterhelper/internal/queuebatch"
14 "go.opentelemetry.io/collector/exporter/exporterhelper/internal/request"
15 "go.opentelemetry.io/collector/exporter/exporterhelper/internal/sender"
16 )
17
18 // NewDefaultQueueConfig returns the default config for queuebatch.Config.
19 // By default, the queue stores 1000 requests of telemetry and is non-blocking when full.
20 func NewDefaultQueueConfig() queuebatch.Config {
21 return queuebatch.Config{
22 Enabled: true,
23 Sizer: request.SizerTypeRequests,
24 NumConsumers: 10,
25 // By default, batches are 8192 spans, for a total of up to 8 million spans in the queue
26 // This can be estimated at 1-4 GB worth of maximum memory usage
27 // This default is probably still too high, and may be adjusted further down in a future release
28 QueueSize: 1_000,
29 BlockOnOverflow: false,
30 Batch: configoptional.Default(queuebatch.BatchConfig{
31 FlushTimeout: 200 * time.Millisecond,
32 Sizer: request.SizerTypeItems,
33 MinSize: 8192,
34 }),
35 }
36 }
37
38 func NewQueueSender(
39 qSet queuebatch.AllSettings[request.Request],
40 qCfg queuebatch.Config,
41 exportFailureMessage string,
42 next sender.Sender[request.Request],
43 ) (sender.Sender[request.Request], error) {
44 exportFunc := func(ctx context.Context, req request.Request) error {
45 // Have to read the number of items before sending the request since the request can
46 // be modified by the downstream components like the batcher.
47 itemsCount := req.ItemsCount()
48 if errSend := next.Send(ctx, req); errSend != nil {
49 qSet.Telemetry.Logger.Error("Exporting failed. Dropping data."+exportFailureMessage,
50 zap.Error(errSend), zap.Int("dropped_items", itemsCount))
51 return errSend
52 }
53 return nil
54 }
55
56 return queuebatch.NewQueueBatch(qSet, qCfg, exportFunc)
57 }