From 1498938e22f31c8edadfaaa03ce68fc30e26942d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20=C3=81lvarez?= Date: Wed, 24 Jun 2020 14:37:40 +0200 Subject: [PATCH] fix bug when instrumentation explicitly disabled (#19355) --- libbeat/instrumentation/instrumentation.go | 2 +- libbeat/instrumentation/instrumentation_test.go | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/libbeat/instrumentation/instrumentation.go b/libbeat/instrumentation/instrumentation.go index 980d5a5531f..99454c47ffb 100644 --- a/libbeat/instrumentation/instrumentation.go +++ b/libbeat/instrumentation/instrumentation.go @@ -168,7 +168,7 @@ func initTracer(cfg Config, beatName, beatVersion string) (*instrumentation, err if !cfg.IsEnabled() { os.Setenv("ELASTIC_APM_ACTIVE", "false") logger.Infof("APM instrumentation is disabled") - return nil, nil + return &instrumentation{}, nil } else { os.Setenv("ELASTIC_APM_ACTIVE", "true") logger.Infof("APM instrumentation is enabled") diff --git a/libbeat/instrumentation/instrumentation_test.go b/libbeat/instrumentation/instrumentation_test.go index 8856f2d1fb6..f6ac0999351 100644 --- a/libbeat/instrumentation/instrumentation_test.go +++ b/libbeat/instrumentation/instrumentation_test.go @@ -80,3 +80,15 @@ func TestAPMTracerDisabledByDefault(t *testing.T) { require.NotNil(t, tracer) assert.False(t, tracer.Active()) } + +func TestInstrumentationDisabled(t *testing.T) { + cfg := common.MustNewConfigFrom(map[string]interface{}{ + "instrumentation": map[string]interface{}{ + "enabled": "false", + }, + }) + instrumentation, err := New(cfg, "filebeat", version.GetDefaultVersion()) + require.NoError(t, err) + require.NotNil(t, instrumentation) + +}