Skip to content

Commit

Permalink
Fix examples for filter and transform processors (#2379)
Browse files Browse the repository at this point in the history
* fix examples filter and transform processors

* remove unecessary docs about escaping strings and backticks

(cherry picked from commit fbe872c)
  • Loading branch information
wildum authored and grafanabot committed Jan 10, 2025
1 parent 8383409 commit 48a6bf7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -197,15 +197,15 @@ information.

### Drop spans which contain a certain span attribute

This example sets the attribute `test` to `pass` if the attribute `test` does not exist.
This example drops the signals that have the attribute `container.name` set to the value `app_container_1`.

```alloy
otelcol.processor.filter "default" {
error_mode = "ignore"
traces {
span = [
"attributes[\"container.name\"] == \"app_container_1\"",
`attributes["container.name"] == "app_container_1"`,
]
}
Expand All @@ -217,8 +217,6 @@ otelcol.processor.filter "default" {
}
```

Each `"` is [escaped][] with `\"` inside the {{< param "PRODUCT_NAME" >}} syntax string.

### Drop metrics based on either of two criteria

This example drops metrics which satisfy at least one of two OTTL statements:
Expand All @@ -231,8 +229,8 @@ otelcol.processor.filter "default" {
metrics {
metric = [
"name == \"my.metric\" and resource.attributes[\"my_label\"] == \"abc123\"",
"type == METRIC_DATA_TYPE_HISTOGRAM",
`name == "my.metric" and resource.attributes["my_label"] == "abc123"`,
`type == METRIC_DATA_TYPE_HISTOGRAM`,
]
}
Expand All @@ -244,11 +242,6 @@ otelcol.processor.filter "default" {
}
```


Some values in the {{< param "PRODUCT_NAME" >}} syntax string are [escaped][]:
* `\` is escaped with `\\`
* `"` is escaped with `\"`

### Drop non-HTTP spans and sensitive logs

```alloy
Expand All @@ -257,14 +250,14 @@ otelcol.processor.filter "default" {
traces {
span = [
"attributes[\"http.request.method\"] == nil",
`attributes["http.request.method"] == nil`,
]
}
logs {
log_record = [
"IsMatch(body, \".*password.*\")",
"severity_number < SEVERITY_NUMBER_WARN",
`IsMatch(body, ".*password.*")`,
`severity_number < SEVERITY_NUMBER_WARN`,
]
}
Expand All @@ -276,13 +269,6 @@ otelcol.processor.filter "default" {
}
```

Each `"` is [escaped][] with `\"` inside the {{< param "PRODUCT_NAME" >}} syntax string.


Some values in the {{< param "PRODUCT_NAME" >}} syntax strings are [escaped][]:
* `\` is escaped with `\\`
* `"` is escaped with `\"`

[escaped]: ../../../../get-started/configuration-syntax/expressions/types_and_values/#strings


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,10 +304,6 @@ otelcol.processor.transform "default" {
}
```

Each statement is enclosed in backticks instead of quotation marks.
This constitutes a [raw string][raw-strings], and lets us avoid the need to escape
each `"` with a `\"` inside a [normal][strings] {{< param "PRODUCT_NAME" >}} syntax string.

### Rename a resource attribute

The are two ways to rename an attribute key.
Expand Down Expand Up @@ -354,10 +350,6 @@ otelcol.processor.transform "default" {
}
```

Each statement is enclosed in backticks instead of quotation marks.
This constitutes a [raw string][raw-strings], and lets us avoid the need to escape
each `"` with a `\"`, and each `\` with a `\\` inside a [normal][strings] {{< param "PRODUCT_NAME" >}} syntax string.

### Create an attribute from the contents of a log body

This example sets the attribute `body` to the value of the log body:
Expand All @@ -381,10 +373,6 @@ otelcol.processor.transform "default" {
}
```

Each statement is enclosed in backticks instead of quotation marks.
This constitutes a [raw string][raw-strings], and lets us avoid the need to escape
each `"` with a `\"` inside a [normal][strings] {{< param "PRODUCT_NAME" >}} syntax string.

### Combine two attributes

This example sets the attribute `test` to the value of attributes `service.name` and `service.version` combined.
Expand All @@ -397,7 +385,7 @@ otelcol.processor.transform "default" {
context = "resource"
statements = [
// The Concat function combines any number of strings, separated by a delimiter.
`set(attributes["test"], Concat([attributes["foo"], attributes["bar"]], " "))`,
`set(attributes["test"], Concat([attributes["service.name"], attributes["service.version"]], " "))`,
]
}
Expand All @@ -409,10 +397,6 @@ otelcol.processor.transform "default" {
}
```

Each statement is enclosed in backticks instead of quotation marks.
This constitutes a [raw string][raw-strings], and lets us avoid the need to escape
each `"` with a `\"` inside a [normal][strings] {{< param "PRODUCT_NAME" >}} syntax string.

### Parsing JSON logs

Given the following JSON body:
Expand Down Expand Up @@ -461,10 +445,6 @@ otelcol.processor.transform "default" {
}
```

Each statement is enclosed in backticks instead of quotation marks.
This constitutes a [raw string][raw-strings], and lets us avoid the need to escape
each `"` with a `\"`, and each `\` with a `\\` inside a [normal][strings] {{< param "PRODUCT_NAME" >}} syntax string.

### Various transformations of attributes and status codes

The example takes advantage of context efficiency by grouping transformations
Expand Down Expand Up @@ -563,10 +543,6 @@ otelcol.exporter.otlp "default" {
}
```

Each statement is enclosed in backticks instead of quotation marks.
This constitutes a [raw string][raw-strings], and lets us avoid the need to escape
each `"` with a `\"`, and each `\` with a `\\` inside a [normal][strings] {{< param "PRODUCT_NAME" >}} syntax string.

[strings]: ../../../../get-started/configuration-syntax/expressions/types_and_values/#strings
[raw-strings]: ../../../../get-started/configuration-syntax/expressions/types_and_values/#raw-strings

Expand Down

0 comments on commit 48a6bf7

Please sign in to comment.