Skip to content

Commit

Permalink
Disable tracer by default (elastic#18339)
Browse files Browse the repository at this point in the history
  • Loading branch information
jalvz committed May 7, 2020
1 parent d152d08 commit 9564af2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
13 changes: 11 additions & 2 deletions libbeat/cmd/instance/beat.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,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 @@ -145,6 +144,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())
}

0 comments on commit 9564af2

Please sign in to comment.