You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In this exercise, you will configure the **Routing Connector** in the `gateway.yaml`. While the Routing Connector can route metrics, traces, and logs based on any attributes, we will focus exclusively on trace routing.
8
-
9
-
This setup enables the Gateway to route traces based on the `deployment.environment` attribute (though any span attribute can be used).
7
+
In this exercise, you will configure the **Routing Connector** in the `gateway.yaml`. The Routing Connector can route metrics, traces, and logs based on any attributes, we will focus exclusively on trace routing based on the `deployment.environment` attribute (though any span/log/metirc attribute can be used).
**Configure `file` exporters**: The `routing` connector requires separate targets for routing. Create two new file exporters, `file/traces/route1` and `file/traces/route2`, to ensure data is directed correctly in the `exporters` section of the `gateway.yaml`:
11
+
**Add new `file` exporters**: The `routing` connector requires different targets for routing. Create two new file exporters, `file/traces/route1-regular` and `file/traces/route2-security`, to ensure data is directed correctly in the `exporters` section of the `gateway.yaml`:
14
12
15
13
```yaml
16
-
file/traces/route1:# Exporter for regular traces
17
-
path: "./gateway-traces-route1.out"# Path for saving trace data
18
-
append: false # Overwrite the file each time
19
-
file/traces/route2: # Exporter for security traces
20
-
path: "./gateway-traces-route2.out"# Path for saving trace data
21
-
append: false # Overwrite the file each time
14
+
file/traces/route1-regular: # Exporter for regular traces
15
+
path: "./gateway-traces-route1-regular.out"# Path for saving trace data
16
+
append: false # Overwrite the file each time
17
+
file/traces/route2-security: # Exporter for security traces
18
+
path: "./gateway-traces-route2-security.out"# Path for saving trace data
19
+
append: false # Overwrite the file each time
22
20
```
23
21
24
-
In OpenTelemetry configuration files, `connectors` have their own dedicated section, similar to receivers and processors.
22
+
**Enable Routing** by adding the `routing` connector. In OpenTelemetry configuration files, `connectors` have their own dedicated section, similar to receivers and processors.
25
23
26
-
**Add the `routing` connector**:
27
-
In the **Gateway terminal** window, edit `gateway.yaml` and uncomment the `#connectors:` section. Then, add the following below the `connectors:` section:
24
+
In the **Gateway terminal** window, edit `gateway.yaml` and find and uncomment the `#connectors:` section. Then, add the following below the `connectors:` section:
28
25
29
26
```yaml
30
27
routing:
31
-
default_pipelines: [traces/route1] # Default pipeline if no rule matches
32
-
error_mode: ignore # Ignore errors in routing
33
-
table: # Define routing rules
28
+
default_pipelines: [traces/route1-regular] # Default pipeline if no rule matches
29
+
error_mode: ignore # Ignore errors in routing
30
+
table: # Define routing rules
34
31
# Routes spans to a target pipeline if the resourceSpan attribute matches the rule
35
32
- statement: route() where attributes["deployment.environment"] == "security-applications"
The default pipeline in the configuration file works at a Catch all. It will be the routing target for any data (spans in our case) that does match a rule in the routing rules table, In this table you find the pipeline that is the target for any span that matches the following rule: "[deployment.environment"] == "security-applications"
39
+
40
+
41
41
With the `routing` configuration complete, the next step is to configure the `pipelines` to apply these routing rules.
**Update the original `traces` pipeline to use routing**:
10
10
11
-
1. To enable `routing`, update the original `traces:` pipeline by using`routing` as the only exporter. This ensures all span data is sent through the **Routing Connector** for evaluation. Also, remove **all** processors and replace it with an empty array (`[]`) as these are now defined in the `traces/route1` and `traces/route2` pipelines.
11
+
1. To enable `routing`, update the original `traces:` pipeline to use`routing` as the only exporter. This ensures all span data is sent through the **Routing Connector** for evaluation and then onwards to connected pipelines. Also, remove **all** processors and replace it with an empty array (`[]`) as this will now behandeld in the `traces/route1-regular` and `traces/route2-security` pipelines, allowing for custom behaviour for each route. Your `traces:` configuration should look like this:
12
12
13
13
```yaml
14
14
traces: # Traces pipeline
@@ -19,38 +19,37 @@ weight: 2
19
19
- routing
20
20
```
21
21
22
-
**Add both the `route1` and `route2` traces pipelines**:
22
+
**Add both the `route1-regular` and `route2-security` traces pipelines** below the existing `traces:` pipeline:
23
23
24
-
1. **Configure Route1 pipeline**: This pipeline will handle all spans that matchthe routing rule for `route1`.
25
-
This uses `routing` as its receiver. Place it below the existing `traces:` pipeline:
24
+
1. **Configure Route1-regular pipeline**: This pipeline will handle all spans that have **no match** in the routing table in the connector.
25
+
Notice this uses `routing` as its only receiver and will recieve data thought its `connection` from the original traces pipeline.
26
26
27
27
```yaml
28
-
traces/route1: # Default pipeline for unmatched spans
28
+
traces/route1-regular: # Default pipeline for unmatched spans
29
29
receivers:
30
-
- routing # Receive data from the routing connector
30
+
- routing # Receive data from the routing connector
- file/traces/route1 # File Exporter for unmatched spans
36
+
- debug # Debug Exporter
37
+
- file/traces/route1-regular # File Exporter for unmatched spans
38
38
```
39
39
40
-
2. **Add the Standard pipeline**: This pipeline processes all spans that do not match the routing rule.
41
-
This pipeline is also using `routing` as its receiver. Add this below the `traces/security` one:
40
+
2. **Add the route2-security pipeline**: This pipeline processes all spans that do match our rule "[deployment.environment"] == "security-applications" in the the routing rule. This pipeline is also using `routing` as its receiver. Add this pipline below the `traces/route1-regular` one.
42
41
43
42
```yaml
44
-
traces/standard: # Default pipeline for unmatched spans
43
+
traces/route2-security: # Default pipeline for unmatched spans
45
44
receivers:
46
-
- routing # Receive data from the routing connector
45
+
- routing # Receive data from the routing connector
In this section, we will test the `routing` rule configured for the **Gateway**. The expected result is that the`span` generated by the `loadgen` will be sent to the `gateway-traces-security.out` file.
9
+
In this section, we will test the `routing` rule configured for the **Gateway**. The expected result is that the`span` generated by the `loadgen` that match the “[deployment.environment”] == “security-applications” rule will be sent to the `gateway-traces-route2-security.out` file.
10
10
11
11
**Start the Gateway**: In your **Gateway terminal** window start the **Gateway**.
12
12
@@ -26,10 +26,10 @@ In this section, we will test the `routing` rule configured for the **Gateway**.
26
26
../loadgen -count 1
27
27
```
28
28
29
-
Both the **Agent** and **Gateway** will display debug information. The gateway will also generate a new `gateway-traces-standard.out` file, as this is now the designated destination for regular spans.
29
+
Both the **Agent** and **Gateway** will display debug information. The gateway will also generate a new `gateway-traces-route1-regular.out` file, as this is now the designated destination for regular spans.
If you check `gateway-traces-standard.out`, it will contain the `span` sent by `loadgen`. You will also see an empty `gateway-traces-security.out` file, as the routing configuration creates output files immediately, even if no matching spans have been processed yet.
32
+
If you check `gateway-traces-route1-regular.out`, it will contain the `span` sent by `loadgen`. You will also see an empty `gateway-traces-route2-security..out` file, as the routing configuration creates output files immediately, even if no matching spans have been processed yet.
33
33
{{% /notice %}}
34
34
35
35
**Send a Security Span**: In the **Loadgen terminal** window send a security span using the `security` flag:
@@ -38,14 +38,14 @@ If you check `gateway-traces-standard.out`, it will contain the `span` sent by `
38
38
../loadgen -security -count 1
39
39
```
40
40
41
-
Again, both the **Agent** and **Gateway** should display debug information, including the span you just sent. This time, the **Gateway** will write a line to the `gateway-traces-security.out` file, which is designated for spans where the `deployment.environment` resource attribute matches `"security-applications"`.
42
-
The `gateway-traces-standard.out` should be unchanged.
41
+
Again, both the **Agent** and **Gateway** should display debug information, including the span you just sent. This time, the **Gateway** will write a line to the `gateway-traces-route2-security.out` file, which is designated for spans where the `deployment.environment` resource attribute matches `"security-applications"`.
42
+
The `gateway-traces-route1-regular.out` should be unchanged.
@@ -69,9 +69,9 @@ You can repeat this scenario multiple times, and each trace will be written to i
69
69
70
70
In this section, we successfully tested the routing connector in the gateway by sending different spans and verifying their destinations.
71
71
72
-
-**Regular spans** were correctly routed to `gateway-traces-standard.out`, confirming that spans without a matching `deployment.environment` attribute follow the default pipeline.
72
+
-**Regular spans** were correctly routed to `gateway-traces-route1-regular.out`, confirming that spans without a matching `deployment.environment` attribute follow the default pipeline.
73
73
74
-
-**Security-related spans** were routed to `gateway-traces-security.out`, demonstrating that the routing rule based on `"deployment.environment": "security-applications"` works as expected.
74
+
-**Security-related spans** were routed to `gateway-traces-route2-security.out`, demonstrating that the routing rule based on `"deployment.environment": "security-applications"` works as expected.
75
75
76
76
By inspecting the output files, we confirmed that the OpenTelemetry Collector *correctly evaluates span attributes and routes them to the appropriate destinations*. This validates that routing rules can effectively separate and direct telemetry data for different use cases.
Copy file name to clipboardExpand all lines: content/en/conf/1-advanced-collector/6-routing-data/_index.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,7 @@ time: 10 minutes
5
5
weight: 8
6
6
---
7
7
8
-
The [**Routing Connector**](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/connector/routingconnector) in OpenTelemetry is a powerful feature that allows you to direct data (`traces`, `metrics`, or `logs`) to different pipelines based on specific criteria. This is especially useful in scenarios where you want to apply different processing or exporting logic to subsets of your telemetry data.
8
+
The [**Routing Connector**](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/connector/routingconnector) in OpenTelemetry is a powerful feature that allows you to direct data (`traces`, `metrics`, or `logs`) to different pipelines/destinations based on specific criteria. This is especially useful in scenarios where you want to apply different processing or exporting logic to subsets of your telemetry data.
9
9
10
10
For example, you might want to send *production* data to one exporter while directing *test* or *development* data to another. Similarly, you could route certain spans based on their attributes, such as service name, environment, or span name, to apply custom processing or storage logic.
0 commit comments