diff --git a/receiver/receivercreator/README.md b/receiver/receivercreator/README.md index 915032382b6f..b378e11a98a1 100644 --- a/receiver/receivercreator/README.md +++ b/receiver/receivercreator/README.md @@ -558,7 +558,10 @@ io.opentelemetry.discovery.logs/config: | ``` Note that individual settings are overridden by the configuration provided by the hints while the operators list -is extended keeping first the `container` parser. +is extended keeping first the `container` parser. If `container` parser is explicitly set by the user the default +will be overridden. + +`include` cannot be overridden and is fixed to discovered container's log file path. #### Support multiple target containers diff --git a/receiver/receivercreator/discovery.go b/receiver/receivercreator/discovery.go index 80df7a2d8d16..752280612620 100644 --- a/receiver/receivercreator/discovery.go +++ b/receiver/receivercreator/discovery.go @@ -228,14 +228,31 @@ func createLogsConfig( logger.Debug("could not unmarshal configuration from hint", zap.Error(err)) } + containerOpFound := false for k, v := range userConf { if k == filelogOperatorsConfigKey { vlist, ok := v.([]any) if !ok { logger.Debug("could not parse operators configuration from hint", zap.Any("config", userConf)) } - vlist = append(cont, vlist...) + for _, op := range vlist { + operator, ok := op.(map[string]any) + if !ok { + logger.Debug("could not parse operator configuration from hint", zap.Any("operator", op)) + } + if operator["type"] == "container" { + containerOpFound = true + } + } + if !containerOpFound { + // if no container operator found then just extend the list + // otherwise we just use the user provided operators as-is + vlist = append(cont, vlist...) + } defaultConfMap[k] = vlist + } else if k == "include" { + // path cannot be other than the one of the target container + continue } else { defaultConfMap[k] = v } diff --git a/receiver/receivercreator/discovery_test.go b/receiver/receivercreator/discovery_test.go index bee6fd73fa7e..90a797188ec8 100644 --- a/receiver/receivercreator/discovery_test.go +++ b/receiver/receivercreator/discovery_test.go @@ -239,6 +239,15 @@ operators: - type: add field: attributes.tag value: beta` + configReplaceContainer := ` +operators: +- type: container + id: replaced +- type: regex_parser + regex: "^(?P