Description
Component(s)
exporter/kafka
Is your feature request related to a problem? Please describe.
The kafkaexporter component can be configured in various ways to determine the topic to which messages are published:
- by default, messages are sent to a signal-specific topic: otlp_spans, otlp_metrics, etc.
- you can configure
topic
to explicitly specify the topic name - you can configure
topic_from_attribute
to extract the topic name from a resource attribute - you can programmatically inject the topic name into the context with https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/pkg/kafka/topic
This is complex, and there are problems with each of these options:
- You cannot explicitly configure
topic
in a way that matches the default, i.e. you cannot configure signal-specific topic names: [exporter/kafka] Replace "topic" setting by "traces_topic", "logs_topic" and "metrics_topic" #35432 - If multiple resources are combined into one batch, then
topic_from_attribute
may behave incorrectly: topic_from_attribute does not work as expected #37470 - Programmatic topic name injection is flexible but will only work for custom components. Nothing in-tree uses it.
Describe the solution you'd like
Replace all of these with a templated topic name, e.g. otlp_{signal_record_type}s
where "signal_type" expands to "log", "span", or "metric"; variable name is just for illustration. The {...}
bit would be treated as an expression, e.g. using OTTL. So you could for example include:
- client metadata (for multi-tenancy):
topic: {request["x-tenant-id"]}.whatever
- resource attributes:
topic: {resource.attributes["service.name"]}-logs
See also #35432 (comment)
Assuming we use OTTL for the template expressions, then we may be able to rely on OTTL context inference to decide when to determine the topic: per request, resource, scope, record, etc. Otherwise, we could limit determining the topic to the resource level.
We should also support a templated topic for kafkareceiver to resolve #32735, but in that case the only expression that would make sense is the signal type. We'll need to consider how the templating syntax interacts with support for topic regular expressions, which the receiver should also ideally support.
Describe alternatives you've considered
No response
Additional context
No response