in src/ServiceProfiler.EventPipe.Otel/Azure.Monitor.OpenTelemetry.Profiler/ServiceProfilerAgentBootstrap.cs [39:96]
public async Task ActivateAsync(CancellationToken cancellationToken)
{
string noIKeyMessage = "No instrumentation key is set. Application Insights Profiler won't start.";
if (_serializer.TrySerialize(_userConfiguration, out string? serializedUserConfiguration))
{
_logger.LogDebug("User Settings:{eol} {details}", Environment.NewLine, serializedUserConfiguration);
}
if (_userConfiguration.IsDisabled)
{
_logger.LogInformation("Service Profiler is disabled by the configuration.");
return;
}
_logger.LogTrace("Starting service profiler from application builder.");
(bool compatible, string reason) = _userConfiguration.IsSkipCompatibilityTest ? (true, "Skipped the compatibility test by settings.") : _compatibilityUtilityFactory.Create().IsCompatible();
if (!compatible)
{
_logger.LogError("Compatibility test failed. Reason: {reason}" + Environment.NewLine +
"Bypass the compatibility test by setting environment variable of ServiceProfiler__IsSkipCompatibilityTest to true.", reason);
return;
}
if (!string.IsNullOrEmpty(reason)) { _logger.LogDebug(reason); }
try
{
if (!_serviceProfilerContext.HasAppInsightsInstrumentationKey)
{
_logger.LogError(noIKeyMessage);
return;
}
_logger.LogInformation("Starting application insights profiler with connection string: {connectionString}", _serviceProfilerContext.ConnectionString);
await _orchestrator.StartAsync(cancellationToken).ConfigureAwait(false);
}
catch (OperationCanceledException ex) when (ex.CancellationToken == cancellationToken)
{
// Terminated.
_logger.LogDebug("Profiler terminated by the user.");
}
catch (ArgumentNullException ex) when (string.Equals(ex.ParamName, "instrumentationKey", StringComparison.OrdinalIgnoreCase))
{
Debug.Fail("You hit the safety net! How could it escape the instrumentation key check?");
_logger.LogError(noIKeyMessage);
return;
}
catch (Exception ex)
{
_logger.LogError(ex, "Unexpected error.");
if (_userConfiguration.AllowsCrash)
{
throw;
}
}
}