@@ -10,39 +10,37 @@ import (
10
10
"github.com/elastic/elastic-agent/internal/pkg/otel/manager"
11
11
)
12
12
13
- var executionMode = manager .EmbeddedExecutionMode
13
+ const defaultExecMode = manager .EmbeddedExecutionMode
14
14
15
15
type execModeConfig struct {
16
16
Agent struct {
17
17
Features struct {
18
18
Otel * struct {
19
- SubprocessExecution bool `json:"subprocess_execution" yaml:"subprocess_execution" config:"subprocess_execution"`
19
+ SubprocessExecution * bool `json:"subprocess_execution,omitempty " yaml:"subprocess_execution,omitempty " config:"subprocess_execution,omitempty "`
20
20
} `json:"otel,omitempty" yaml:"otel,omitempty" config:"otel,omitempty"`
21
21
} `json:"features" yaml:"features" config:"features"`
22
22
} `json:"agent" yaml:"agent" config:"agent"`
23
23
}
24
24
25
- // SetExecutionModeFromConfig sets the execution mode of the OTel runtime based on the config.
26
- func SetExecutionModeFromConfig (log * logp.Logger , conf * config.Config ) {
25
+ // GetExecutionModeFromConfig returns the execution mode of the OTel runtime based on the config.
26
+ func GetExecutionModeFromConfig (log * logp.Logger , conf * config.Config ) manager. ExecutionMode {
27
27
var c execModeConfig
28
28
if err := conf .UnpackTo (& c ); err != nil {
29
- log .Warnf ("failed to unpack config in otel init execution mode: %v" , err )
30
- return
29
+ log .Warnf ("failed to unpack config when getting otel runtime execution mode: %v" , err )
30
+ return defaultExecMode
31
31
}
32
32
33
- if c .Agent .Features .Otel != nil && c .Agent .Features .Otel .SubprocessExecution {
34
- executionMode = manager .SubprocessExecutionMode
35
- } else {
36
- executionMode = manager .EmbeddedExecutionMode
33
+ if c .Agent .Features .Otel == nil {
34
+ return defaultExecMode
37
35
}
38
- }
39
36
40
- // GetExecutionMode returns the execution mode of the OTel runtime.
41
- func GetExecutionMode () manager.ExecutionMode {
42
- return executionMode
43
- }
37
+ if c .Agent .Features .Otel .SubprocessExecution == nil {
38
+ return defaultExecMode
39
+ }
44
40
45
- // IsSubprocessExecution returns true if the OTel runtime is running in subprocess mode.
46
- func IsSubprocessExecution () bool {
47
- return executionMode == manager .SubprocessExecutionMode
41
+ if * c .Agent .Features .Otel .SubprocessExecution {
42
+ return manager .SubprocessExecutionMode
43
+ } else {
44
+ return manager .EmbeddedExecutionMode
45
+ }
48
46
}
0 commit comments