Skip to content

Commit ad6a19f

Browse files
authored
Allow specifying name on the connection to RabbitMQ (#34682)
1 parent 7d92d6a commit ad6a19f

File tree

5 files changed

+100
-28
lines changed

5 files changed

+100
-28
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: enhancement
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
7+
component: rabbitmqexporter
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Allow to configure the name of the AMQP connection in the rabbitmqexporter
11+
12+
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
13+
issues: [34681]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext:
19+
20+
# If your change doesn't affect end users or the exported elements of any package,
21+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
22+
# Optional: The change log or logs in which this entry should be included.
23+
# e.g. '[user]' or '[user, api]'
24+
# Include 'user' if the change is relevant to end users.
25+
# Include 'api' if there is a change to a library API.
26+
# Default: '[user]'
27+
change_logs: [user]

exporter/rabbitmqexporter/README.md

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,35 +21,36 @@ This component expects that exchanges, queues, and bindings already exist - they
2121

2222
The following settings can be configured:
2323
- `connection`:
24-
- `endpoint` (required, ex = amqp://localhost:5672): Endpoint to connect to RabbitMQ
25-
- `vhost` (optional): The RabbitMQ [virtual host](https://www.rabbitmq.com/docs/vhosts) to connect to
26-
- `auth`:
27-
- `plain`: Configuration if using SASL PLAIN authentication
28-
- `username` (required): username for authentication
29-
- `password`: password for authentication
30-
- `tls` (optional): [TLS configuration](https://github.com/open-telemetry/opentelemetry-collector/blob/main/config/configtls/configtls.go#L32)
31-
- `routing`:
32-
- `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
33-
- `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.
34-
- `durable` (default = true): Whether to instruct RabbitMQ to make messages [durable](https://www.rabbitmq.com/docs/queues#durability) by writing to disk
35-
- `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
36-
- `retry_on_failure`:
37-
- `enabled` (default = false)
24+
- `endpoint` (required, ex = amqp://localhost:5672): Endpoint to connect to RabbitMQ
25+
- `vhost` (optional): The RabbitMQ [virtual host](https://www.rabbitmq.com/docs/vhosts) to connect to
26+
- `auth`:
27+
- `plain`: Configuration if using SASL PLAIN authentication
28+
- `username` (required): username for authentication
29+
- `password`: password for authentication
30+
- `tls` (optional): [TLS configuration](https://github.com/open-telemetry/opentelemetry-collector/blob/main/config/configtls/configtls.go#L32)
31+
- `name` (optional): The name of the connection, visible in in RabbitMQ management interface
32+
- `routing`:
33+
- `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
34+
- `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.
35+
- `durable` (default = true): Whether to instruct RabbitMQ to make messages [durable](https://www.rabbitmq.com/docs/queues#durability) by writing to disk
36+
- `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
37+
- `retry_on_failure`:
38+
- `enabled` (default = false)
3839

3940
Example config:
4041

4142
```yaml
4243
exporters:
4344
rabbitmq:
44-
connection:
45-
endpoint: amqp://localhost:5672
46-
auth:
47-
plain:
48-
username: user
49-
password: pass
50-
encoding_extension: otlp_encoding/rabbitmq
45+
connection:
46+
endpoint: amqp://localhost:5672
47+
auth:
48+
plain:
49+
username: user
50+
password: pass
51+
encoding_extension: otlp_encoding/rabbitmq
5152

5253
extensions:
5354
otlp_encoding/rabbitmq:
5455
protocol: otlp_json
55-
```
56+
```

exporter/rabbitmqexporter/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ type ConnectionConfig struct {
2828
ConnectionTimeout time.Duration `mapstructure:"connection_timeout"`
2929
Heartbeat time.Duration `mapstructure:"heartbeat"`
3030
PublishConfirmationTimeout time.Duration `mapstructure:"publish_confirmation_timeout"`
31+
Name string `mapstructure:"name"`
3132
}
3233

3334
type RoutingConfig struct {

exporter/rabbitmqexporter/factory.go

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ const (
2828
metricsRoutingKey = "otlp_metrics"
2929
logsRoutingKey = "otlp_logs"
3030

31-
spansConnectionName = "otel-collector-spans"
32-
metricsConnectionName = "otel-collector-metrics"
33-
logsConnectionName = "otel-collector-logs"
31+
defaultSpansConnectionName = "otel-collector-spans"
32+
defaultMetricsConnectionName = "otel-collector-metrics"
33+
defaultLogsConnectionName = "otel-collector-logs"
3434
)
3535

3636
func NewFactory() exporter.Factory {
@@ -66,7 +66,11 @@ func createTracesExporter(
6666
config := cfg.(*Config)
6767

6868
routingKey := getRoutingKeyOrDefault(config, spansRoutingKey)
69-
r := newRabbitmqExporter(config, set.TelemetrySettings, newPublisherFactory(set), newTLSFactory(config), routingKey, spansConnectionName)
69+
connectionName := defaultSpansConnectionName
70+
if config.Connection.Name != "" {
71+
connectionName = config.Connection.Name
72+
}
73+
r := newRabbitmqExporter(config, set.TelemetrySettings, newPublisherFactory(set), newTLSFactory(config), routingKey, connectionName)
7074

7175
return exporterhelper.NewTracesExporter(
7276
ctx,
@@ -88,7 +92,12 @@ func createMetricsExporter(
8892
config := (cfg.(*Config))
8993

9094
routingKey := getRoutingKeyOrDefault(config, metricsRoutingKey)
91-
r := newRabbitmqExporter(config, set.TelemetrySettings, newPublisherFactory(set), newTLSFactory(config), routingKey, metricsConnectionName)
95+
96+
connectionName := defaultMetricsConnectionName
97+
if config.Connection.Name != "" {
98+
connectionName = config.Connection.Name
99+
}
100+
r := newRabbitmqExporter(config, set.TelemetrySettings, newPublisherFactory(set), newTLSFactory(config), routingKey, connectionName)
92101

93102
return exporterhelper.NewMetricsExporter(
94103
ctx,
@@ -110,7 +119,11 @@ func createLogsExporter(
110119
config := (cfg.(*Config))
111120

112121
routingKey := getRoutingKeyOrDefault(config, logsRoutingKey)
113-
r := newRabbitmqExporter(config, set.TelemetrySettings, newPublisherFactory(set), newTLSFactory(config), routingKey, logsConnectionName)
122+
connectionName := defaultLogsConnectionName
123+
if config.Connection.Name != "" {
124+
connectionName = config.Connection.Name
125+
}
126+
r := newRabbitmqExporter(config, set.TelemetrySettings, newPublisherFactory(set), newTLSFactory(config), routingKey, connectionName)
114127

115128
return exporterhelper.NewLogsExporter(
116129
ctx,

exporter/rabbitmqexporter/factory_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,16 @@ func TestCreateLogsExporter(t *testing.T) {
4747
assert.NotNil(t, te)
4848
}
4949

50+
func TestCreateMetricsExporterWithConnectionName(t *testing.T) {
51+
factory := NewFactory()
52+
cfg := factory.CreateDefaultConfig().(*Config)
53+
cfg.Connection.Name = "my-conn-name"
54+
55+
te, err := factory.CreateMetricsExporter(context.Background(), exportertest.NewNopSettings(), cfg)
56+
assert.NoError(t, err)
57+
assert.NotNil(t, te)
58+
}
59+
5060
func TestCreateExporterWithCustomRoutingKey(t *testing.T) {
5161
factory := NewFactory()
5262
cfg := factory.CreateDefaultConfig().(*Config)
@@ -57,6 +67,16 @@ func TestCreateExporterWithCustomRoutingKey(t *testing.T) {
5767
assert.NotNil(t, te)
5868
}
5969

70+
func TestCreateExporterWithConnectionName(t *testing.T) {
71+
factory := NewFactory()
72+
cfg := factory.CreateDefaultConfig().(*Config)
73+
cfg.Connection.Name = "my-conn-name"
74+
75+
te, err := factory.CreateLogsExporter(context.Background(), exportertest.NewNopSettings(), cfg)
76+
assert.NoError(t, err)
77+
assert.NotNil(t, te)
78+
}
79+
6080
func TestCreateExporterWithTLSSettings(t *testing.T) {
6181
factory := NewFactory()
6282
cfg := factory.CreateDefaultConfig().(*Config)
@@ -66,3 +86,13 @@ func TestCreateExporterWithTLSSettings(t *testing.T) {
6686
assert.NoError(t, err)
6787
assert.NotNil(t, te)
6888
}
89+
90+
func TestCreateTracesExporterWithConnectionName(t *testing.T) {
91+
factory := NewFactory()
92+
cfg := factory.CreateDefaultConfig().(*Config)
93+
cfg.Connection.Name = "my-conn-name"
94+
95+
te, err := factory.CreateTracesExporter(context.Background(), exportertest.NewNopSettings(), cfg)
96+
assert.NoError(t, err)
97+
assert.NotNil(t, te)
98+
}

0 commit comments

Comments
 (0)