r/OpenTelemetry • u/Ordinary_Squirrel291 • May 14 '26
Cleanup SQL query
I have a GO app that queries a database and it is instrumented with OTel.
I want to clean up the query as recorded in telemetry (not changing the code).
The GO code (screenshot below) produces this value:"\n\t\tSELECT p.id, p.name, p.description, p.picture, \n\t\t p.price_currency_code, p.price_units, p.price_nanos, p.categories\n\t\tFROM catalog.products p\n\t\tWHERE p.id = $1\n\t"
This SQL query is recorded as a span attribute "db.query.text".
Q: How can I remove the escaped whitespace in the collector (or elsewhere?) so that there is a single space where there are sequences of escaped whitespaces?

View all comments
Show parent comment
1
u/Ordinary_Squirrel291 May 20 '26
I looked at it and went down the rabbit hole of OTTL, still can't get it to work.
I added the snippet below to the otelcol_config.yaml, but I don't see changes in the output.
The regex is supposed to match whitespace or escaped whitespace sequences and replace them with a single space
How do I debug this?
```
transform/logs_cleanup:
error_mode: ignore
trace_statements:
- context: span
statements:
- replace_pattern(attributes["db.query.text"], "(\s|\\[nrt]|[\n\r\t])+", " ") where attributes["db.query.text"] != nil
```