File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed
design-docs/otel-collector-processors Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -214,3 +214,36 @@ sense as a user experience.
214214
215215An implementation of the query language would likely parse expressions into this sort of structure so given an SQL-like
216216implementation, 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+ processors.register("replace_wildcards", replace_wildcards)
231+
232+ func replace_wildcards(pattern regexp.Regexp, replacement string, path processors.TelemetryPath) processors.Result {
233+ val := path.Get()
234+ if val == nil {
235+ return processors.CONTINUE
236+ }
237+
238+ // replace finds placeholders in "replacement" and swaps them in for regex matched substrings.
239+ replaced := replace(val, pattern, replacement)
240+ path.Set(replaced)
241+ return processors.CONTINUE
242+ }
243+ ` ` `
244+
245+ Here, the processor framework recognizes the first parameter of the function is `regexp.Regexp` so will compile the string
246+ provided by the user in the config when processing it. Similarly for `path`, it recognizes properties of type `TelemetryPath`
247+ and will resolve it to the path within a matched telemetry during execution and pass it to the function. The path allows
248+ scalar operations on the field within the telemetry. The processor does not need to be aware of telemetry filtering,
249+ the `where ...` clause as that will be handled by the framework before passing to the function.
You can’t perform that action at this time.
0 commit comments