How to customize the Astra Traffic collector
Customizing Traffic Collector Configuration
Sensor can be customized to filter, templatize and redact the traces generated from traffic. These customization are present to give flexibility to the customer to define a rule to choose a trace to be monitored. Similarly, personally identified information in the trace can be redacted before it reaches Astra's server. This way it can be ensured that no sensitive data leaves customers environment. Lets look at configuring each of them in detail.
Filtering
Filtering can be achieved based on a trace attribute: `url.host`or url.template. Primarily, filtering can be divided into AllowListing and ExcludeListing.
AllowListing refers to allowing the traces orginated from the specfifc host/pattern.
ExcludeListing refers to excluding the traces matching specific host/pattern.
Locate the custom_config.yaml under installation directory of astra-traffic-collector. Edit the custom_config.yaml
processors:
filter/custom:
error_mode: ignore
traces:
span:
## allowing traces based on hostname regex pattern. Following will drop all traces originated from host other than: localhost*
- IsMatch(attributes["url.host"], "localhost*") == false
## excluding traces based on hostname regex pattern. Following will drop all traces originated from host: localhost*
- IsMatch(attributes["url.host"], "localhost*")
## excluding traces based on template regex pattern. Following will drop all traces having url_template: _wdt*
- IsMatch(attributes["url.template"], "_wdt*")
Restart the astra-traffic-collector
Depending on linux, mac or windows, restart astra-traffic-collector docker container
For Kubernetes based, refer here to know how to restart astra-traffic-collector
Templatizing
Templatizing is a useful way to templatize the API Path. Although Astra takes care of templatizing integer, UUID, ULID, Timestamp etc, still there is a flexibility for the customers to write their own templates for the pattern that they are aware of.
Scenario: Imagine you’re running an online marketplace where sellers create unique product pages. Your API receives URLs like:
/api/v1/products/details/prod-12r4ty
/api/v1/products/details/prod-qw34tg
/api/v1/products/details/prod-gy78fg
These dynamic values (prod-12r4ty, prod-qw34tg , etc.) represent product IDs. To replace dynamic segments with a template (e.g., {{product_id}}).
Edit the custom_config.yaml as shown below
processors:
transform/custom:
error_mode: ignore
trace_statements:
- context: span
statements:
## Templatize url path regex pattern by keyword: "slug". Following will templatize the url Path: /api/v1/products/details/prod-12r4ty -> /api/v1/products/details/{{product_id}}
- replace_pattern(attributes["url.template"], "prod-*", "{{product_id}}")
Restart the astra-traffic-collector
Depending on linux, mac or windows, restart astra-traffic-collector docker container
For Kubernetes based, refer here to know how to restart astra-traffic-collector
Redacting
Redacting can be achieved by finding the right regex pattern to be redacted. Redaction ensures that sensitive information are not leaving customers environment. Let's see how to redact a PII such as CreditCard number
Edit the custom_config.yaml as shown below
processors:
transform/custom:
error_mode: ignore
trace_statements:
- context: span
statements:
## Redact MasterCard credit card number
- replace_all_patterns(attributes, "value", "^5[1-5][0-9]{14}$", "{{CreditCard}}")
Restart the astra-traffic-collector
Depending on linux, mac or windows, restart astra-traffic-collector docker container
For Kubernetes based, refer here to know how to restart astra-traffic-collector
Redaction will be applied to every part of the trace including request body/header, response body/header, query parameters etc
Verify the traces before sending them to Astra
It's essential to verify the required redaction and filtering is working before opting to send the traces to Astra backend. To do so, follow the below mentioned steps
Edit the custom_config.yaml to restrict the exporting only to logs
processors:
#your custom processing including redacting, filtering and templatizing....
service:
pipelines:
traces:
exporters: [debug]
Restart the astra-traffic-collector
Depending on linux, mac or windows, restart astra-traffic-collector docker container
For Kubernetes based, refer here to know how to restart astra-traffic-collector
Verify the traces by inspecting astra-traffic-collector logs
docker logs astra-traffic-collector
After the verification is over, please remove exporter added
processors:
#your custom processing including redacting, filtering and templatizing....
Restart the astra-traffic-collector
Depending on linux, mac or windows, restart astra-traffic-collector docker container
For Kubernetes based, refer here to know how to restart astra-traffic-collector
Updated on: 25/02/2025
Thank you!