Skip to content

Commit

Permalink
Use Logger to log exception in AgentComponents initialization
Browse files Browse the repository at this point in the history
This commit fixes a bug in logging an exception
that may occur during agent initialization; the Logger
property is used instead of the logger argument, the
former will always be initialized with a value.

Fixes elastic#1254
  • Loading branch information
russcam committed May 25, 2021
1 parent 5f7e40d commit 114e33c
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/Elastic.Apm/AgentComponents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,22 +53,21 @@ IApmServerInfo apmServerInfo

HttpTraceConfiguration = new HttpTraceConfiguration();

TracerInternal = new Tracer(Logger, Service, PayloadSender, ConfigStore,
currentExecutionSegmentsContainer ?? new CurrentExecutionSegmentsContainer(), ApmServerInfo);

if (ConfigurationReader.Enabled)
{
CentralConfigFetcher = centralConfigFetcher ?? new CentralConfigFetcher(Logger, ConfigStore, Service);
MetricsCollector = metricsCollector ?? new MetricsCollector(Logger, PayloadSender, ConfigStore);
MetricsCollector.StartCollecting();
}

TracerInternal = new Tracer(Logger, Service, PayloadSender, ConfigStore,
currentExecutionSegmentsContainer ?? new CurrentExecutionSegmentsContainer(), ApmServerInfo);

if (!ConfigurationReader.Enabled)
Logger?.Info()?.Log("The Elastic APM .NET Agent is disabled - the agent won't capture traces and metrics.");
else
Logger.Info()?.Log("The Elastic APM .NET Agent is disabled - the agent won't capture traces and metrics.");
}
catch (Exception e)
{
logger?.Error()?.LogException(e, "Failed initializing agent.");
Logger.Error()?.LogException(e, "Failed initializing agent.");
}
}

Expand Down

0 comments on commit 114e33c

Please sign in to comment.