diff --git a/.chloggen/rabbitmq-connection-name.yaml b/.chloggen/rabbitmq-connection-name.yaml new file mode 100644 index 000000000000..f57495292b61 --- /dev/null +++ b/.chloggen/rabbitmq-connection-name.yaml @@ -0,0 +1,27 @@ +# Use this changelog template to create an entry for release notes. + +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: enhancement + +# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) +component: rabbitmqexporter + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Allow to configure the name of the AMQP connection in the rabbitmqexporter + +# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. +issues: [34681] + +# (Optional) One or more lines of additional information to render under the primary note. +# These lines will be padded with 2 spaces and then inserted directly into the document. +# Use pipe (|) for multiline entries. +subtext: + +# If your change doesn't affect end users or the exported elements of any package, +# you should instead start your pull request title with [chore] or use the "Skip Changelog" label. +# Optional: The change log or logs in which this entry should be included. +# e.g. '[user]' or '[user, api]' +# Include 'user' if the change is relevant to end users. +# Include 'api' if there is a change to a library API. +# Default: '[user]' +change_logs: [user] diff --git a/exporter/rabbitmqexporter/README.md b/exporter/rabbitmqexporter/README.md index 72c774ffb8d3..147f0eab31d0 100644 --- a/exporter/rabbitmqexporter/README.md +++ b/exporter/rabbitmqexporter/README.md @@ -21,35 +21,36 @@ This component expects that exchanges, queues, and bindings already exist - they The following settings can be configured: - `connection`: - - `endpoint` (required, ex = amqp://localhost:5672): Endpoint to connect to RabbitMQ - - `vhost` (optional): The RabbitMQ [virtual host](https://www.rabbitmq.com/docs/vhosts) to connect to - - `auth`: - - `plain`: Configuration if using SASL PLAIN authentication - - `username` (required): username for authentication - - `password`: password for authentication - - `tls` (optional): [TLS configuration](https://github.com/open-telemetry/opentelemetry-collector/blob/main/config/configtls/configtls.go#L32) - - `routing`: - - `routing_key` (default = otlp_spans for traces, otlp_metrics for metrics, otlp_logs for logs): Routing key used to route exported messages to RabbitMQ consumers - - `exchange`: Name of the exchange used to route messages. If omitted, the [default exchange](https://www.rabbitmq.com/tutorials/amqp-concepts#exchange-default) is used which routes to a queue with the same as the routing key. Only [direct exchanges](https://www.rabbitmq.com/tutorials/amqp-concepts#exchange-direct) are currently supported. Note that this component does not handle queue creation or binding. - - `durable` (default = true): Whether to instruct RabbitMQ to make messages [durable](https://www.rabbitmq.com/docs/queues#durability) by writing to disk - - `encoding_extension`: (defaults to OTLP protobuf format): ID of the [encoding extension](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/extension/encoding) to use to marshal data - - `retry_on_failure`: - - `enabled` (default = false) + - `endpoint` (required, ex = amqp://localhost:5672): Endpoint to connect to RabbitMQ + - `vhost` (optional): The RabbitMQ [virtual host](https://www.rabbitmq.com/docs/vhosts) to connect to + - `auth`: + - `plain`: Configuration if using SASL PLAIN authentication + - `username` (required): username for authentication + - `password`: password for authentication + - `tls` (optional): [TLS configuration](https://github.com/open-telemetry/opentelemetry-collector/blob/main/config/configtls/configtls.go#L32) + - `name` (optional): The name of the connection, visible in in RabbitMQ management interface +- `routing`: + - `routing_key` (default = otlp_spans for traces, otlp_metrics for metrics, otlp_logs for logs): Routing key used to route exported messages to RabbitMQ consumers + - `exchange`: Name of the exchange used to route messages. If omitted, the [default exchange](https://www.rabbitmq.com/tutorials/amqp-concepts#exchange-default) is used which routes to a queue with the same as the routing key. Only [direct exchanges](https://www.rabbitmq.com/tutorials/amqp-concepts#exchange-direct) are currently supported. Note that this component does not handle queue creation or binding. +- `durable` (default = true): Whether to instruct RabbitMQ to make messages [durable](https://www.rabbitmq.com/docs/queues#durability) by writing to disk +- `encoding_extension`: (defaults to OTLP protobuf format): ID of the [encoding extension](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/extension/encoding) to use to marshal data +- `retry_on_failure`: + - `enabled` (default = false) Example config: ```yaml exporters: rabbitmq: - connection: - endpoint: amqp://localhost:5672 - auth: - plain: - username: user - password: pass - encoding_extension: otlp_encoding/rabbitmq + connection: + endpoint: amqp://localhost:5672 + auth: + plain: + username: user + password: pass + encoding_extension: otlp_encoding/rabbitmq extensions: otlp_encoding/rabbitmq: protocol: otlp_json -``` \ No newline at end of file +``` diff --git a/exporter/rabbitmqexporter/config.go b/exporter/rabbitmqexporter/config.go index f3bd7cdee175..6bc095037caa 100644 --- a/exporter/rabbitmqexporter/config.go +++ b/exporter/rabbitmqexporter/config.go @@ -28,6 +28,7 @@ type ConnectionConfig struct { ConnectionTimeout time.Duration `mapstructure:"connection_timeout"` Heartbeat time.Duration `mapstructure:"heartbeat"` PublishConfirmationTimeout time.Duration `mapstructure:"publish_confirmation_timeout"` + Name string `mapstructure:"name"` } type RoutingConfig struct { diff --git a/exporter/rabbitmqexporter/factory.go b/exporter/rabbitmqexporter/factory.go index 2c08f98aaf3e..24f8d28f0f8c 100644 --- a/exporter/rabbitmqexporter/factory.go +++ b/exporter/rabbitmqexporter/factory.go @@ -28,9 +28,9 @@ const ( metricsRoutingKey = "otlp_metrics" logsRoutingKey = "otlp_logs" - spansConnectionName = "otel-collector-spans" - metricsConnectionName = "otel-collector-metrics" - logsConnectionName = "otel-collector-logs" + defaultSpansConnectionName = "otel-collector-spans" + defaultMetricsConnectionName = "otel-collector-metrics" + defaultLogsConnectionName = "otel-collector-logs" ) func NewFactory() exporter.Factory { @@ -66,7 +66,11 @@ func createTracesExporter( config := cfg.(*Config) routingKey := getRoutingKeyOrDefault(config, spansRoutingKey) - r := newRabbitmqExporter(config, set.TelemetrySettings, newPublisherFactory(set), newTLSFactory(config), routingKey, spansConnectionName) + connectionName := defaultSpansConnectionName + if config.Connection.Name != "" { + connectionName = config.Connection.Name + } + r := newRabbitmqExporter(config, set.TelemetrySettings, newPublisherFactory(set), newTLSFactory(config), routingKey, connectionName) return exporterhelper.NewTracesExporter( ctx, @@ -88,7 +92,12 @@ func createMetricsExporter( config := (cfg.(*Config)) routingKey := getRoutingKeyOrDefault(config, metricsRoutingKey) - r := newRabbitmqExporter(config, set.TelemetrySettings, newPublisherFactory(set), newTLSFactory(config), routingKey, metricsConnectionName) + + connectionName := defaultMetricsConnectionName + if config.Connection.Name != "" { + connectionName = config.Connection.Name + } + r := newRabbitmqExporter(config, set.TelemetrySettings, newPublisherFactory(set), newTLSFactory(config), routingKey, connectionName) return exporterhelper.NewMetricsExporter( ctx, @@ -110,7 +119,11 @@ func createLogsExporter( config := (cfg.(*Config)) routingKey := getRoutingKeyOrDefault(config, logsRoutingKey) - r := newRabbitmqExporter(config, set.TelemetrySettings, newPublisherFactory(set), newTLSFactory(config), routingKey, logsConnectionName) + connectionName := defaultLogsConnectionName + if config.Connection.Name != "" { + connectionName = config.Connection.Name + } + r := newRabbitmqExporter(config, set.TelemetrySettings, newPublisherFactory(set), newTLSFactory(config), routingKey, connectionName) return exporterhelper.NewLogsExporter( ctx, diff --git a/exporter/rabbitmqexporter/factory_test.go b/exporter/rabbitmqexporter/factory_test.go index 41a6cc71ef06..ac2afc326cf3 100644 --- a/exporter/rabbitmqexporter/factory_test.go +++ b/exporter/rabbitmqexporter/factory_test.go @@ -47,6 +47,16 @@ func TestCreateLogsExporter(t *testing.T) { assert.NotNil(t, te) } +func TestCreateMetricsExporterWithConnectionName(t *testing.T) { + factory := NewFactory() + cfg := factory.CreateDefaultConfig().(*Config) + cfg.Connection.Name = "my-conn-name" + + te, err := factory.CreateMetricsExporter(context.Background(), exportertest.NewNopSettings(), cfg) + assert.NoError(t, err) + assert.NotNil(t, te) +} + func TestCreateExporterWithCustomRoutingKey(t *testing.T) { factory := NewFactory() cfg := factory.CreateDefaultConfig().(*Config) @@ -57,6 +67,16 @@ func TestCreateExporterWithCustomRoutingKey(t *testing.T) { assert.NotNil(t, te) } +func TestCreateExporterWithConnectionName(t *testing.T) { + factory := NewFactory() + cfg := factory.CreateDefaultConfig().(*Config) + cfg.Connection.Name = "my-conn-name" + + te, err := factory.CreateLogsExporter(context.Background(), exportertest.NewNopSettings(), cfg) + assert.NoError(t, err) + assert.NotNil(t, te) +} + func TestCreateExporterWithTLSSettings(t *testing.T) { factory := NewFactory() cfg := factory.CreateDefaultConfig().(*Config) @@ -66,3 +86,13 @@ func TestCreateExporterWithTLSSettings(t *testing.T) { assert.NoError(t, err) assert.NotNil(t, te) } + +func TestCreateTracesExporterWithConnectionName(t *testing.T) { + factory := NewFactory() + cfg := factory.CreateDefaultConfig().(*Config) + cfg.Connection.Name = "my-conn-name" + + te, err := factory.CreateTracesExporter(context.Background(), exportertest.NewNopSettings(), cfg) + assert.NoError(t, err) + assert.NotNil(t, te) +}