in edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.IoTHub/EdgeAgentConnection.cs [466:659]
async Task<bool> WaitForDeviceClientInitialization() =>
await Task.WhenAny(this.initTask, Task.Delay(DeviceClientInitializationWaitTime)) == this.initTask;
static class Events
{
public static readonly ILogger Log = Logger.Factory.CreateLogger<EdgeAgentConnection>();
const int IdStart = AgentEventIds.EdgeAgentConnection;
enum EventIds
{
DesiredPropertiesFailed = IdStart,
ConnectionStatusChanged,
DesiredPropertiesPatchApplied,
DesiredPropertiesUpdated,
DeploymentConfigUpdated,
ErrorUpdatingDeploymentConfig,
ErrorRefreshingTwin,
TwinRefreshSuccess,
ErrorHandlingConnectionChangeEvent,
EmptyDeploymentConfig,
RetryingGetTwin,
MismatchedSchemaVersion,
TwinRefreshInit,
TwinRefreshStart,
GotTwin,
UpdatingReportedProperties,
UpdateReportedPropertiesDeviceClientEmpty,
UpdatedReportedProperties,
ErrorUpdatingReportedProperties,
GotModuleClient,
GettingModuleClient,
SendEvent,
SendEventClientEmpty,
ErrorSendingEvent,
ErrorClosingModuleClient,
LogDesiredPropertiesAfterPatch,
LogDesiredPropertiesAfterFullTwin,
PullingTwinHasBeenTriggeredFrequently,
StartedDelayedTwinPull,
FinishedDelayedTwinPull
}
public static void DesiredPropertiesPatchFailed(Exception exception)
{
Log.LogError((int)EventIds.DesiredPropertiesFailed, exception, "Edge agent failed to process desired properties update patch");
}
public static void ConnectionStatusChanged(ConnectionStatus status, ConnectionStatusChangeReason reason)
{
Log.LogDebug((int)EventIds.ConnectionStatusChanged, $"Connection status changed to {status} with reason {reason}");
}
public static void GotTwin(Twin twin)
{
long reportedPropertiesVersion = twin?.Properties?.Reported?.Version ?? -1;
long desiredPropertiesVersion = twin?.Properties?.Desired?.Version ?? -1;
Log.LogInformation((int)EventIds.GotTwin, $"Obtained Edge agent twin from IoTHub with desired properties version {desiredPropertiesVersion} and reported properties version {reportedPropertiesVersion}.");
}
public static void UpdatingReportedProperties()
{
Log.LogDebug((int)EventIds.UpdatingReportedProperties, "Updating reported properties in IoT Hub");
}
public static void UpdateReportedPropertiesDeviceClientEmpty()
{
Log.LogDebug((int)EventIds.UpdateReportedPropertiesDeviceClientEmpty, "Updating reported properties in IoT Hub");
}
public static void UpdatedReportedProperties()
{
Log.LogDebug((int)EventIds.UpdatedReportedProperties, "Updated reported properties in IoT Hub");
}
public static void ErrorUpdatingReportedProperties(Exception ex)
{
Log.LogDebug((int)EventIds.ErrorUpdatingReportedProperties, ex, "Error updating reported properties in IoT Hub");
}
public static void GettingModuleClient(bool retrying)
{
Log.LogDebug((int)EventIds.GettingModuleClient, $"Getting module client to refresh the twin with retrying set to {retrying}");
}
public static void GotModuleClient()
{
Log.LogDebug((int)EventIds.GotModuleClient, "Got module client to refresh the twin");
}
public static void ErrorGettingTwin(Exception e)
{
Log.LogWarning((int)EventIds.RetryingGetTwin, e, "Error getting edge agent twin from IoTHub");
}
internal static void DesiredPropertiesUpdated()
{
Log.LogDebug((int)EventIds.DesiredPropertiesUpdated, "Edge agent desired properties updated callback invoked.");
}
internal static void DesiredPropertiesPatchApplied()
{
Log.LogDebug((int)EventIds.DesiredPropertiesPatchApplied, "Edge agent desired properties patch applied successfully.");
}
internal static void ConnectionStatusChangedHandlingError(Exception ex)
{
Log.LogWarning((int)EventIds.ErrorHandlingConnectionChangeEvent, ex, "Edge agent connection error handing connection change callback.");
}
internal static void TwinRefreshInit(TimeSpan interval)
{
Log.LogDebug((int)EventIds.TwinRefreshInit, "Initialize twin refresh with interval '{0:c}'", interval);
}
internal static void TwinRefreshStart()
{
Log.LogDebug((int)EventIds.TwinRefreshStart, "Begin refreshing twin from upstream...");
}
internal static void TwinRefreshSuccess()
{
Log.LogDebug((int)EventIds.TwinRefreshSuccess, "Updated edge agent configuration from upstream twin.");
}
internal static void TwinRefreshError(Exception ex)
{
Log.LogError((int)EventIds.ErrorRefreshingTwin, ex, "Error refreshing edge agent configuration from twin.");
}
internal static void ErrorUpdatingDeploymentConfig(Exception ex)
{
Log.LogError((int)EventIds.ErrorUpdatingDeploymentConfig, ex, "Error updating deployment config from edge agent desired properties.");
}
internal static void EmptyDeploymentConfig()
{
Log.LogInformation((int)EventIds.EmptyDeploymentConfig, "Deployment config in edge agent's desired properties is empty.");
}
internal static void UpdatedDeploymentConfig()
{
Log.LogDebug((int)EventIds.DeploymentConfigUpdated, "Edge agent updated deployment config from desired properties.");
}
internal static void RetryingGetTwin(RetryingEventArgs args)
{
Log.LogDebug((int)EventIds.RetryingGetTwin, $"Edge agent is retrying GetTwinAsync. Attempt #{args.CurrentRetryCount}. Last error: {args.LastException?.Message}");
}
internal static void SendEvent()
{
Log.LogDebug((int)EventIds.SendEvent, $"Edge agent is sending a diagnostic message.");
}
public static void SendEventClientEmpty()
{
Log.LogDebug((int)EventIds.SendEventClientEmpty, "Client empty.");
}
public static void ErrorSendingEvent(Exception ex)
{
Log.LogDebug((int)EventIds.ErrorSendingEvent, ex, "Error sending event");
}
public static void ErrorClosingModuleClientForRetry(Exception e)
{
Log.LogWarning((int)EventIds.ErrorClosingModuleClient, e, "Error closing module client for retry");
}
internal static void LogDesiredPropertiesAfterPatch(TwinCollection twinCollection)
{
Log.LogTrace((int)EventIds.LogDesiredPropertiesAfterPatch, $"Obtained desired properties after apply patch: {twinCollection}");
}
internal static void LogDesiredPropertiesAfterFullTwin(TwinCollection twinCollection)
{
Log.LogTrace((int)EventIds.LogDesiredPropertiesAfterFullTwin, $"Obtained desired properites after processing full twin: {twinCollection}");
}
internal static void PullingTwinHasBeenTriggeredFrequently(int count, int seconds)
{
Log.LogWarning((int)EventIds.PullingTwinHasBeenTriggeredFrequently, $"Pulling twin by 'Connected' event has been triggered frequently, {count} times in the last {seconds} seconds. This can be a sign when more edge devices use the same identity and they keep getting disconnected.");
}
internal static void StartedDelayedTwinPull()
{
Log.LogDebug((int)EventIds.StartedDelayedTwinPull, $"Started delayed twin-pull");
}
internal static void FinishedDelayedTwinPull()
{
Log.LogDebug((int)EventIds.FinishedDelayedTwinPull, $"Finished delayed twin-pull");
}
}