@@ -6,6 +6,7 @@ package kafkaexporter // import "github.com/open-telemetry/opentelemetry-collect
6
6
import (
7
7
"go.opentelemetry.io/collector/component"
8
8
"go.opentelemetry.io/collector/config/configretry"
9
+ "go.opentelemetry.io/collector/confmap"
9
10
"go.opentelemetry.io/collector/exporter/exporterhelper"
10
11
11
12
"github.com/open-telemetry/opentelemetry-collector-contrib/internal/kafka/configkafka"
@@ -21,13 +22,32 @@ type Config struct {
21
22
configkafka.ClientConfig `mapstructure:",squash"`
22
23
Producer configkafka.ProducerConfig `mapstructure:"producer"`
23
24
24
- // The name of the kafka topic to export to (default otlp_spans for traces, otlp_metrics for metrics)
25
+ // Logs holds configuration about how logs should be sent to Kafka.
26
+ Logs SignalConfig `mapstructure:"logs"`
27
+
28
+ // Metrics holds configuration about how metrics should be sent to Kafka.
29
+ Metrics SignalConfig `mapstructure:"metrics"`
30
+
31
+ // Traces holds configuration about how traces should be sent to Kafka.
32
+ Traces SignalConfig `mapstructure:"traces"`
33
+
34
+ // Topic holds the name of the Kafka topic to which data should be exported.
35
+ //
36
+ // Topic has no default. If explicitly specified, it will take precedence over
37
+ // the default values of logs::topic, metrics::topic, and traces::topic.
38
+ //
39
+ // Deprecated [v0.124.0]: use logs::topic, metrics::topic, and traces::topic instead.
25
40
Topic string `mapstructure:"topic"`
26
41
27
42
// TopicFromAttribute is the name of the attribute to use as the topic name.
28
43
TopicFromAttribute string `mapstructure:"topic_from_attribute"`
29
44
30
- // Encoding of messages (default "otlp_proto")
45
+ // Encoding holds the encoding of Kafka message values.
46
+ //
47
+ // Encoding has no default. If explicitly specified, it will take precedence over
48
+ // the default values of logs::encoding, metrics::encoding, and traces::encoding.
49
+ //
50
+ // Deprecated [v0.124.0]: use logs::encoding, metrics::encoding, and traces::encoding instead.
31
51
Encoding string `mapstructure:"encoding"`
32
52
33
53
// PartitionTracesByID sets the message key of outgoing trace messages to the trace ID.
@@ -46,3 +66,56 @@ type Config struct {
46
66
// attributes.
47
67
PartitionLogsByResourceAttributes bool `mapstructure:"partition_logs_by_resource_attributes"`
48
68
}
69
+
70
+ func (c * Config ) Unmarshal (conf * confmap.Conf ) error {
71
+ if err := conf .Unmarshal (c ); err != nil {
72
+ return err
73
+ }
74
+ // Check if deprecated fields have been explicitly set,
75
+ // in which case they should be used instead of signal-
76
+ // specific defaults.
77
+ var zeroConfig Config
78
+ if err := conf .Unmarshal (& zeroConfig ); err != nil {
79
+ return err
80
+ }
81
+ if c .Topic != "" {
82
+ if zeroConfig .Logs .Topic == "" {
83
+ c .Logs .Topic = c .Topic
84
+ }
85
+ if zeroConfig .Metrics .Topic == "" {
86
+ c .Metrics .Topic = c .Topic
87
+ }
88
+ if zeroConfig .Traces .Topic == "" {
89
+ c .Traces .Topic = c .Topic
90
+ }
91
+ }
92
+ if c .Encoding != "" {
93
+ if zeroConfig .Logs .Encoding == "" {
94
+ c .Logs .Encoding = c .Encoding
95
+ }
96
+ if zeroConfig .Metrics .Encoding == "" {
97
+ c .Metrics .Encoding = c .Encoding
98
+ }
99
+ if zeroConfig .Traces .Encoding == "" {
100
+ c .Traces .Encoding = c .Encoding
101
+ }
102
+ }
103
+ return conf .Unmarshal (c )
104
+ }
105
+
106
+ // SignalConfig holds signal-specific configuration for the Kafka exporter.
107
+ type SignalConfig struct {
108
+ // Topic holds the name of the Kafka topic to which messages of the
109
+ // signal type should be produced.
110
+ //
111
+ // The default depends on the signal type:
112
+ // - "otlp_spans" for traces
113
+ // - "otlp_metrics" for metrics
114
+ // - "otlp_logs" for logs
115
+ Topic string `mapstructure:"topic"`
116
+
117
+ // Encoding holds the encoding of messages for the signal type.
118
+ //
119
+ // Defaults to "otlp_proto".
120
+ Encoding string `mapstructure:"encoding"`
121
+ }
0 commit comments