Skip to content

Commit

Permalink
Minor fixes to apm fake component and integration test (#3571)
Browse files Browse the repository at this point in the history
  • Loading branch information
pchila authored Oct 11, 2023
1 parent 1c5010f commit fd06296
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions pkg/component/fake/component/comp/apm.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,11 @@ func (ats *apmTracesSender) createNewTracer(cfg *proto.APMConfig) (*apm.Tracer,
defer os.Unsetenv(envCACert)
}

if cfg.Elastic.GetGlobalLabels() != "" {
os.Setenv(envGlobalLabels, cfg.Elastic.GetGlobalLabels())
defer os.Unsetenv(envGlobalLabels)
}

ts, err := apmtransport.NewHTTPTransport()
if err != nil {
return nil, err
Expand Down Expand Up @@ -197,6 +202,10 @@ func (fai *fakeAPMInput) Update(u *client.Unit, triggers client.Trigger) error {

func newFakeAPMInput(logger zerolog.Logger, logLevel client.UnitLogLevel, unit *client.Unit) (*fakeAPMInput, error) {
logger = logger.Level(toZerologLevel(logLevel))

// close the default tracer to avoid unnecessary logs
apm.DefaultTracer.Close()

apmInput := &fakeAPMInput{
logger: logger,
unit: unit,
Expand All @@ -206,6 +215,7 @@ func newFakeAPMInput(logger zerolog.Logger, logLevel client.UnitLogLevel, unit *
if err != nil {
return apmInput, fmt.Errorf("error while setting starting state: %w", err)
}
logger.Info().Msgf("Starting fake APM traces sender with config %v", unit.Expected().APMConfig)
err = apmInput.sender.Start(context.Background(), unit.Expected().APMConfig)
if err != nil {
return apmInput, fmt.Errorf("error starting apm tracer sender: %w", err)
Expand All @@ -231,6 +241,7 @@ func senderErrorLogger(ctx context.Context, logger zerolog.Logger, errCh <-chan
if err != nil {
logger.Err(err).Msg("sender error")
_ = unit.UpdateState(client.UnitStateDegraded, fmt.Sprintf("sender error: %s", err), nil)
continue
}
_ = unit.UpdateState(client.UnitStateHealthy, fmt.Sprintf("sender error: %s", err), nil)
}
Expand Down

0 comments on commit fd06296

Please sign in to comment.