Skip to content

Commit e24013f

Browse files
authored
add environment variable option for language selection (#1331)
1 parent faa67c0 commit e24013f

File tree

4 files changed

+19
-4
lines changed

4 files changed

+19
-4
lines changed

internal/test/integration/docker-compose-nodeclient.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ services:
3333
environment:
3434
GOCOVERDIR: "/coverage"
3535
OTEL_EBPF_TRACE_PRINTER: "text"
36-
OTEL_EBPF_EXECUTABLE_PATH: "${OTEL_EBPF_EXECUTABLE_PATH}"
36+
OTEL_EBPF_AUTO_TARGET_LANGUAGE: "nodejs"
3737
OTEL_EBPF_SERVICE_NAMESPACE: "integration-test"
3838
OTEL_EBPF_DISCOVERY_POLL_INTERVAL: 500ms
3939
OTEL_EBPF_OTLP_TRACES_BATCH_TIMEOUT: "1ms"

pkg/appolly/discover/matcher.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,13 +368,14 @@ func FindingCriteria(cfg *obi.Config) []services.Selector {
368368

369369
if len(cfg.Discovery.Instrument) > 0 {
370370
finderCriteria := cfg.Discovery.Instrument
371-
if cfg.AutoTargetExe.IsSet() || cfg.Port.Len() > 0 {
371+
if cfg.AutoTargetExe.IsSet() || cfg.Port.Len() > 0 || cfg.AutoTargetLanguage.IsSet() {
372372
finderCriteria = slices.Clone(cfg.Discovery.Instrument)
373373
finderCriteria = append(finderCriteria, services.GlobAttributes{
374374
Name: cfg.ServiceName,
375375
Namespace: cfg.ServiceNamespace,
376376
Path: cfg.AutoTargetExe,
377377
OpenPorts: cfg.Port,
378+
Languages: cfg.AutoTargetLanguage,
378379
})
379380
}
380381
return NormalizeGlobCriteria(finderCriteria)
@@ -383,13 +384,14 @@ func FindingCriteria(cfg *obi.Config) []services.Selector {
383384
// edge use case: when neither discovery > services nor discovery > instrument sections are set
384385
// we will prioritize the newer OTEL_EBPF_AUTO_TARGET_EXE/OTEL_GO_AUTO_TARGET_EXE property
385386
// over the old, deprecated OTEL_EBPF_EXECUTABLE_PATH
386-
if cfg.AutoTargetExe.IsSet() {
387+
if cfg.AutoTargetExe.IsSet() || cfg.AutoTargetLanguage.IsSet() {
387388
return []services.Selector{
388389
&services.GlobAttributes{
389390
Name: cfg.ServiceName,
390391
Namespace: cfg.ServiceNamespace,
391392
Path: cfg.AutoTargetExe,
392393
OpenPorts: cfg.Port,
394+
Languages: cfg.AutoTargetLanguage,
393395
},
394396
}
395397
}

pkg/obi/config.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,10 @@ type Config struct {
292292
// will instrument all the service calls in all the ports, not only the port specified here.
293293
Port services.PortEnum `yaml:"open_port" env:"OTEL_EBPF_OPEN_PORT"`
294294

295+
// AutoTargetLanguage selects the executable to instrument matching a Glob of chosen languages.
296+
// To set this value via YAML, use discovery > instrument.
297+
AutoTargetLanguage services.GlobAttr `env:"OTEL_EBPF_AUTO_TARGET_LANGUAGE,expand"`
298+
295299
// ServiceName is taken from either OTEL_EBPF_SERVICE_NAME env var or OTEL_SERVICE_NAME (for OTEL spec compatibility)
296300
// Using env and envDefault is a trick to get the value either from one of either variables.
297301
// Deprecated: Service name should be set in the instrumentation target (env vars, kube metadata...)
@@ -639,7 +643,7 @@ func (c *Config) Enabled(feature Feature) bool {
639643
case FeatureNetO11y:
640644
return c.NetworkFlows.Enable || c.promNetO11yEnabled() || c.otelNetO11yEnabled()
641645
case FeatureAppO11y:
642-
return c.Port.Len() > 0 || c.AutoTargetExe.IsSet() || len(c.Discovery.Instrument) > 0 ||
646+
return c.Port.Len() > 0 || c.AutoTargetExe.IsSet() || c.AutoTargetLanguage.IsSet() || len(c.Discovery.Instrument) > 0 ||
643647
c.Exec.IsSet() || len(c.Discovery.Services) > 0
644648
}
645649
return false

pkg/obi/config_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,15 @@ func TestConfig_NetworkImplicitProm(t *testing.T) {
508508
assert.True(t, cfg.Enabled(FeatureNetO11y)) // Net o11y should be on
509509
}
510510

511+
func TestConfig_AutoLanguageEnv(t *testing.T) {
512+
// OTEL_GO_AUTO_TARGET_EXE is an alias to OTEL_EBPF_AUTO_TARGET_EXE
513+
// (Compatibility with OpenTelemetry)
514+
t.Setenv("OTEL_EBPF_AUTO_TARGET_LANGUAGE", "{go,java}")
515+
cfg, err := LoadConfig(bytes.NewReader(nil))
516+
require.NoError(t, err)
517+
assert.True(t, cfg.AutoTargetLanguage.MatchString("java"))
518+
}
519+
511520
func TestConfig_ExternalLogger(t *testing.T) {
512521
type testCase struct {
513522
name string

0 commit comments

Comments
 (0)