@@ -214,3 +214,37 @@ sense as a user experience.
214
214
215
215
An implementation of the query language would likely parse expressions into this sort of structure so given an SQL-like
216
216
implementation, it would likely be little overhead to support a YAML approach in addition.
217
+
218
+ ## Implementing a processor function
219
+
220
+ The ` replace_wildcards` function may look like this.
221
+
222
+ ` ` ` go
223
+
224
+ package replacewildcards
225
+
226
+ import "regexp"
227
+
228
+ import "github.com/open-telemetry/opentelemetry/processors"
229
+
230
+ // Assuming this is not in "core"
231
+ processors.register("replace_wildcards", replace_wildcards)
232
+
233
+ func replace_wildcards(pattern regexp.Regexp, replacement string, path processors.TelemetryPath) processors.Result {
234
+ val := path.Get()
235
+ if val == nil {
236
+ return processors.CONTINUE
237
+ }
238
+
239
+ // replace finds placeholders in "replacement" and swaps them in for regex matched substrings.
240
+ replaced := replace(val, pattern, replacement)
241
+ path.Set(replaced)
242
+ return processors.CONTINUE
243
+ }
244
+ ` ` `
245
+
246
+ Here, the processor framework recognizes the first parameter of the function is `regexp.Regexp` so will compile the string
247
+ provided by the user in the config when processing it. Similarly for `path`, it recognizes properties of type `TelemetryPath`
248
+ and will resolve it to the path within a matched telemetry during execution and pass it to the function. The path allows
249
+ scalar operations on the field within the telemetry. The processor does not need to be aware of telemetry filtering,
250
+ the `where ...` clause as that will be handled by the framework before passing to the function.
0 commit comments