Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable tracer by default #18339

Merged
merged 2 commits into from
May 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions libbeat/cmd/instance/beat.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,7 @@ var debugf = logp.MakeDebug("beat")

func init() {
initRand()
// we need to close the default tracer to prevent the beat sending events to localhost:8200
apm.DefaultTracer.Close()
preventDefaultTracing()
}

// initRand initializes the runtime random number generator seed using
Expand All @@ -144,6 +143,16 @@ func initRand() {
rand.Seed(seed)
}

func preventDefaultTracing() {
// By default, the APM tracer is active. We switch behaviour to not require users to have
// an APM Server running, making it opt-in
if os.Getenv("ELASTIC_APM_ACTIVE") == "" {
os.Setenv("ELASTIC_APM_ACTIVE", "false")
}
// we need to close the default tracer to prevent the beat sending events to localhost:8200
apm.DefaultTracer.Close()
}

// Run initializes and runs a Beater implementation. name is the name of the
// Beat (e.g. packetbeat or metricbeat). version is version number of the Beater
// implementation. bt is the `Creator` callback for creating a new beater
Expand Down
11 changes: 11 additions & 0 deletions libbeat/cmd/instance/beat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ import (
"os"
"testing"

"github.com/stretchr/testify/require"

"go.elastic.co/apm"

"github.com/elastic/beats/v7/libbeat/cfgfile"

"github.com/gofrs/uuid"
Expand Down Expand Up @@ -115,3 +119,10 @@ func TestEmptyMetaJson(t *testing.T) {
assert.Equal(t, nil, err, "Unable to load meta file properly")
assert.NotEqual(t, uuid.Nil, b.Info.ID, "Beats UUID is not set")
}

func TestAPMTracerDisabledByDefault(t *testing.T) {
tracer, err := apm.NewTracer("", "")
require.NoError(t, err)
defer tracer.Close()
assert.False(t, tracer.Active())
}